admin_runners_spec.rb 12.1 KB
Newer Older
1 2
require 'spec_helper'

3
describe "Admin Runners" do
4
  include StubENV
5
  include FilteredSearchHelpers
6
  include SortingHelper
7

8
  before do
9
    stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
10
    sign_in(create(:admin))
11 12 13
  end

  describe "Runners page" do
14 15 16
    let(:pipeline) { create(:ci_pipeline) }

    context "when there are runners" do
17
      it 'has all necessary texts' do
18 19
        runner = create(:ci_runner, contacted_at: Time.now)
        create(:ci_build, pipeline: pipeline, runner_id: runner.id)
20 21
        visit admin_runners_path

22
        expect(page).to have_text "Set up a shared Runner manually"
23
        expect(page).to have_text "Runners currently online: 1"
24
      end
25

26
      describe 'search', :js do
27
        before do
28 29
          create(:ci_runner, description: 'runner-foo')
          create(:ci_runner, description: 'runner-bar')
30 31

          visit admin_runners_path
32 33 34
        end

        it 'shows correct runner when description matches' do
35
          input_filtered_search_keys('runner-foo')
36 37 38 39 40 41

          expect(page).to have_content("runner-foo")
          expect(page).not_to have_content("runner-bar")
        end

        it 'shows no runner when description does not match' do
42
          input_filtered_search_keys('runner-baz')
43 44 45 46

          expect(page).to have_text 'No runners found'
        end
      end
47

48
      describe 'filter by status', :js do
49
        it 'shows correct runner when status matches' do
50 51
          create(:ci_runner, description: 'runner-active', active: true)
          create(:ci_runner, description: 'runner-paused', active: false)
52 53 54 55 56 57

          visit admin_runners_path

          expect(page).to have_content 'runner-active'
          expect(page).to have_content 'runner-paused'

58
          input_filtered_search_keys('status:active')
59 60 61 62 63
          expect(page).to have_content 'runner-active'
          expect(page).not_to have_content 'runner-paused'
        end

        it 'shows no runner when status does not match' do
64 65
          create(:ci_runner, :online, description: 'runner-active', active: true)
          create(:ci_runner, :online, description: 'runner-paused', active: false)
66 67 68

          visit admin_runners_path

69
          input_filtered_search_keys('status:offline')
70 71 72 73 74 75

          expect(page).not_to have_content 'runner-active'
          expect(page).not_to have_content 'runner-paused'

          expect(page).to have_text 'No runners found'
        end
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

        it 'shows correct runner when status is selected and search term is entered' do
          create(:ci_runner, description: 'runner-a-1', active: true)
          create(:ci_runner, description: 'runner-a-2', active: false)
          create(:ci_runner, description: 'runner-b-1', active: true)

          visit admin_runners_path

          input_filtered_search_keys('status:active')
          expect(page).to have_content 'runner-a-1'
          expect(page).to have_content 'runner-b-1'
          expect(page).not_to have_content 'runner-a-2'

          input_filtered_search_keys('status:active runner-a')
          expect(page).to have_content 'runner-a-1'
          expect(page).not_to have_content 'runner-b-1'
          expect(page).not_to have_content 'runner-a-2'
        end
94 95
      end

96 97 98 99
      describe 'filter by type', :js do
        it 'shows correct runner when type matches' do
          create :ci_runner, :project, description: 'runner-project'
          create :ci_runner, :group, description: 'runner-group'
100

101 102 103 104
          visit admin_runners_path

          expect(page).to have_content 'runner-project'
          expect(page).to have_content 'runner-group'
105

106 107 108 109 110 111 112 113
          input_filtered_search_keys('type:project_type')
          expect(page).to have_content 'runner-project'
          expect(page).not_to have_content 'runner-group'
        end

        it 'shows no runner when type does not match' do
          create :ci_runner, :project, description: 'runner-project'
          create :ci_runner, :group, description: 'runner-group'
114

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
          visit admin_runners_path

          input_filtered_search_keys('type:instance_type')

          expect(page).not_to have_content 'runner-project'
          expect(page).not_to have_content 'runner-group'

          expect(page).to have_text 'No runners found'
        end

        it 'shows correct runner when type is selected and search term is entered' do
          create :ci_runner, :project, description: 'runner-a-1'
          create :ci_runner, :instance, description: 'runner-a-2'
          create :ci_runner, :project, description: 'runner-b-1'

          visit admin_runners_path

          input_filtered_search_keys('type:project_type')
          expect(page).to have_content 'runner-a-1'
          expect(page).to have_content 'runner-b-1'
          expect(page).not_to have_content 'runner-a-2'

          input_filtered_search_keys('type:project_type runner-a')
          expect(page).to have_content 'runner-a-1'
          expect(page).not_to have_content 'runner-b-1'
          expect(page).not_to have_content 'runner-a-2'
        end
142
      end
143

144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
      describe 'filter by tag', :js do
        it 'shows correct runner when tag matches' do
          create :ci_runner, description: 'runner-blue', tag_list: ['blue']
          create :ci_runner, description: 'runner-red', tag_list: ['red']

          visit admin_runners_path

          expect(page).to have_content 'runner-blue'
          expect(page).to have_content 'runner-red'

          input_filtered_search_keys('tag:blue')

          expect(page).to have_content 'runner-blue'
          expect(page).not_to have_content 'runner-red'
        end

        it 'shows no runner when tag does not match' do
          create :ci_runner, description: 'runner-blue', tag_list: ['blue']
          create :ci_runner, description: 'runner-red', tag_list: ['blue']

          visit admin_runners_path

          input_filtered_search_keys('tag:red')

          expect(page).not_to have_content 'runner-blue'
          expect(page).not_to have_content 'runner-blue'
          expect(page).to have_text 'No runners found'
        end

        it 'shows correct runner when tag is selected and search term is entered' do
          create :ci_runner, description: 'runner-a-1', tag_list: ['blue']
          create :ci_runner, description: 'runner-a-2', tag_list: ['red']
          create :ci_runner, description: 'runner-b-1', tag_list: ['blue']

          visit admin_runners_path

          input_filtered_search_keys('tag:blue')

          expect(page).to have_content 'runner-a-1'
          expect(page).to have_content 'runner-b-1'
          expect(page).not_to have_content 'runner-a-2'

          input_filtered_search_keys('tag:blue runner-a')

          expect(page).to have_content 'runner-a-1'
          expect(page).not_to have_content 'runner-b-1'
          expect(page).not_to have_content 'runner-a-2'
        end
      end

194
      it 'sorts by last contact date', :js do
195 196
        create(:ci_runner, description: 'runner-1', created_at: '2018-07-12 15:37', contacted_at: '2018-07-12 15:37')
        create(:ci_runner, description: 'runner-2', created_at: '2018-07-12 16:37', contacted_at: '2018-07-12 16:37')
197 198 199

        visit admin_runners_path

200 201 202 203 204 205
        within '.runners-content .gl-responsive-table-row:nth-child(2)' do
          expect(page).to have_content 'runner-2'
        end

        within '.runners-content .gl-responsive-table-row:nth-child(3)' do
          expect(page).to have_content 'runner-1'
206 207 208 209
        end

        sorting_by 'Last Contact'

210 211 212
        within '.runners-content .gl-responsive-table-row:nth-child(2)' do
          expect(page).to have_content 'runner-1'
        end
213

214 215
        within '.runners-content .gl-responsive-table-row:nth-child(3)' do
          expect(page).to have_content 'runner-2'
216 217
        end
      end
Valery Sizov's avatar
Valery Sizov committed
218
    end
219

220
    context "when there are no runners" do
221
      before do
222
        visit admin_runners_path
223 224
      end

225
      it 'has all necessary texts including no runner message' do
226
        expect(page).to have_text "Set up a shared Runner manually"
227
        expect(page).to have_text "Runners currently online: 0"
228
        expect(page).to have_text 'No runners found'
Valery Sizov's avatar
Valery Sizov committed
229
      end
230
    end
231 232

    context 'group runner' do
233
      let(:group) { create(:group) }
234
      let!(:runner) { create(:ci_runner, :group, groups: [group]) }
235

236
      it 'shows the label and does not show the project count' do
237 238 239
        visit admin_runners_path

        within "#runner_#{runner.id}" do
Clement Ho's avatar
Clement Ho committed
240
          expect(page).to have_selector '.badge', text: 'group'
241 242 243 244 245 246 247
          expect(page).to have_text 'n/a'
        end
      end
    end

    context 'shared runner' do
      it 'shows the label and does not show the project count' do
248
        runner = create(:ci_runner, :instance)
249 250 251 252

        visit admin_runners_path

        within "#runner_#{runner.id}" do
Clement Ho's avatar
Clement Ho committed
253
          expect(page).to have_selector '.badge', text: 'shared'
254 255 256 257 258 259 260
          expect(page).to have_text 'n/a'
        end
      end
    end

    context 'specific runner' do
      it 'shows the label and the project count' do
261 262
        project = create(:project)
        runner = create(:ci_runner, :project, projects: [project])
263 264 265 266

        visit admin_runners_path

        within "#runner_#{runner.id}" do
Clement Ho's avatar
Clement Ho committed
267
          expect(page).to have_selector '.badge', text: 'specific'
268 269 270 271
          expect(page).to have_text '1'
        end
      end
    end
272 273 274
  end

  describe "Runner show page" do
275
    let(:runner) { create(:ci_runner) }
276 277

    before do
278 279
      @project1 = create(:project)
      @project2 = create(:project)
280
      visit admin_runner_path(runner)
281 282 283
    end

    describe 'runner info' do
284
      it { expect(find_field('runner_token').value).to eq runner.token }
285 286 287
    end

    describe 'projects' do
Valery Sizov's avatar
Valery Sizov committed
288
      it 'contains project names' do
289 290
        expect(page).to have_content(@project1.full_name)
        expect(page).to have_content(@project2.full_name)
Valery Sizov's avatar
Valery Sizov committed
291
      end
292 293 294 295
    end

    describe 'search' do
      before do
296
        search_form = find('#runner-projects-search')
297
        search_form.fill_in 'search', with: @project1.name
298
        search_form.click_button 'Search'
299 300
      end

Valery Sizov's avatar
Valery Sizov committed
301
      it 'contains name of correct project' do
302 303
        expect(page).to have_content(@project1.full_name)
        expect(page).not_to have_content(@project2.full_name)
Valery Sizov's avatar
Valery Sizov committed
304
      end
305
    end
306 307

    describe 'enable/create' do
308
      shared_examples 'assignable runner' do
309 310 311 312 313 314 315 316 317
        it 'enables a runner for a project' do
          within '.unassigned-projects' do
            click_on 'Enable'
          end

          assigned_project = page.find('.assigned-projects')

          expect(assigned_project).to have_content(@project2.path)
        end
318 319
      end

320
      context 'with specific runner' do
321 322
        let(:runner) { create(:ci_runner, :project, projects: [@project1]) }

323 324
        before do
          visit admin_runner_path(runner)
325 326
        end

327
        it_behaves_like 'assignable runner'
328 329
      end

330
      context 'with locked runner' do
331 332
        let(:runner) { create(:ci_runner, :project, projects: [@project1], locked: true) }

333 334 335 336 337 338 339
        before do
          visit admin_runner_path(runner)
        end

        it_behaves_like 'assignable runner'
      end

340
      context 'with shared runner' do
341 342
        let(:runner) { create(:ci_runner, :instance) }

343 344 345 346
        before do
          @project1.destroy
          visit admin_runner_path(runner)
        end
347

348
        it_behaves_like 'assignable runner'
349 350 351 352
      end
    end

    describe 'disable/destroy' do
353 354
      let(:runner) { create(:ci_runner, :project, projects: [@project1]) }

355 356 357 358 359 360 361 362 363 364 365 366 367 368
      before do
        visit admin_runner_path(runner)
      end

      it 'enables specific runner for project' do
        within '.assigned-projects' do
          click_on 'Disable'
        end

        new_runner_project = page.find('.unassigned-projects')

        expect(new_runner_project).to have_content(@project1.path)
      end
    end
369
  end
370 371

  describe 'runners registration token' do
372
    let!(:token) { Gitlab::CurrentSettings.runners_registration_token }
373 374 375 376

    before do
      visit admin_runners_path
    end
377 378

    it 'has a registration token' do
379
      expect(page.find('#registration_token')).to have_content(token)
380 381 382
    end

    describe 'reload registration token' do
383
      let(:page_token) { find('#registration_token').text }
384 385 386 387 388 389

      before do
        click_button 'Reset runners registration token'
      end

      it 'changes registration token' do
390
        expect(page_token).not_to eq token
391 392 393
      end
    end
  end
394
end