BigW Consortium Gitlab

runners_spec.rb 4.58 KB
Newer Older
1 2 3 4 5 6
require 'spec_helper'

describe "Runners" do
  include GitlabRoutingHelper

  let(:user) { create(:user) }
7 8

  before do
9
    gitlab_sign_in(user)
10
  end
11 12 13

  describe "specific runners" do
    before do
14 15
      @project = FactoryGirl.create :empty_project, shared_runners_enabled: false
      @project.team << [user, :master]
16

17 18
      @project2 = FactoryGirl.create :empty_project
      @project2.team << [user, :master]
19

20 21
      @project3 = FactoryGirl.create :empty_project
      @project3.team << [user, :developer]
22

23 24 25 26
      @shared_runner = FactoryGirl.create :ci_runner, :shared
      @specific_runner = FactoryGirl.create :ci_runner
      @specific_runner2 = FactoryGirl.create :ci_runner
      @specific_runner3 = FactoryGirl.create :ci_runner
27 28 29
      @project.runners << @specific_runner
      @project2.runners << @specific_runner2
      @project3.runners << @specific_runner3
30

31
      visit runners_path(@project)
32 33
    end

34
    before do
35 36
      expect(page).not_to have_content(@specific_runner3.display_name)
      expect(page).not_to have_content(@specific_runner3.display_name)
37 38
    end

39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    it "places runners in right places" do
      expect(page.find(".available-specific-runners")).to have_content(@specific_runner2.display_name)
      expect(page.find(".activated-specific-runners")).to have_content(@specific_runner.display_name)
      expect(page.find(".available-shared-runners")).to have_content(@shared_runner.display_name)
    end

    it "enables specific runner for project" do
      within ".available-specific-runners" do
        click_on "Enable for this project"
      end

      expect(page.find(".activated-specific-runners")).to have_content(@specific_runner2.display_name)
    end

    it "disables specific runner for project" do
54
      @project2.runners << @specific_runner
55
      visit runners_path(@project)
56 57 58 59 60 61 62 63 64 65

      within ".activated-specific-runners" do
        click_on "Disable for this project"
      end

      expect(page.find(".available-specific-runners")).to have_content(@specific_runner.display_name)
    end

    it "removes specific runner for project if this is last project for that runners" do
      within ".activated-specific-runners" do
66
        click_on "Remove Runner"
67 68 69 70 71 72 73 74
      end

      expect(Ci::Runner.exists?(id: @specific_runner)).to be_falsey
    end
  end

  describe "shared runners" do
    before do
75 76 77
      @project = FactoryGirl.create :empty_project, shared_runners_enabled: false
      @project.team << [user, :master]
      visit runners_path(@project)
78 79 80
    end

    it "enables shared runners" do
81
      click_on "Enable shared Runners"
82 83 84 85
      expect(@project.reload.shared_runners_enabled).to be_truthy
    end
  end

86
  describe "shared runners description" do
87 88
    let(:shared_runners_text) { 'custom **shared** runners description' }
    let(:shared_runners_html) { 'custom shared runners description' }
89 90

    before do
91 92 93 94
      stub_application_setting(shared_runners_text: shared_runners_text)
      project = FactoryGirl.create :empty_project, shared_runners_enabled: false
      project.team << [user, :master]
      visit runners_path(project)
95 96 97
    end

    it "sees shared runners description" do
98
      expect(page.find(".shared-runners-description")).to have_content(shared_runners_html)
99 100 101
    end
  end

102 103
  describe "show page" do
    before do
104 105
      @project = FactoryGirl.create :empty_project
      @project.team << [user, :master]
106
      @specific_runner = FactoryGirl.create :ci_runner
107
      @project.runners << @specific_runner
108 109 110
    end

    it "shows runner information" do
111
      visit runners_path(@project)
112 113 114 115
      click_on @specific_runner.short_sha
      expect(page).to have_content(@specific_runner.platform)
    end
  end
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

  feature 'configuring runners ability to picking untagged jobs' do
    given(:project) { create(:empty_project) }
    given(:runner) { create(:ci_runner) }

    background do
      project.team << [user, :master]
      project.runners << runner
    end

    scenario 'user checks default configuration' do
      visit namespace_project_runner_path(project.namespace, project, runner)

      expect(page).to have_content 'Can run untagged jobs Yes'
    end

132
    context 'when runner has tags' do
133 134 135
      before do
        runner.update_attribute(:tag_list, ['tag'])
      end
136

137
      scenario 'user wants to prevent runner from running untagged job' do
138 139 140 141
        visit runners_path(project)
        page.within('.activated-specific-runners') do
          first('small > a').click
        end
142

143 144 145 146 147 148
        uncheck 'runner_run_untagged'
        click_button 'Save changes'

        expect(page).to have_content 'Can run untagged jobs No'
        expect(runner.reload.run_untagged?).to eq false
      end
149 150
    end
  end
151
end