1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
142
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Runners' do
let(:user) { create(:user) }
before do
sign_in(user)
end
context 'when user opens runners page' do
let(:project) { create(:project) }
before do
project.add_maintainer(user)
end
it 'user can see a button to install runners on kubernetes clusters' do
visit project_runners_path(project)
expect(page).to have_link('Install Runner on Kubernetes', href: project_clusters_path(project))
end
end
context 'when a project has enabled shared_runners' do
let(:project) { create(:project) }
before do
project.add_maintainer(user)
end
context 'when a project_type runner is activated on the project' do
let!(:specific_runner) { create(:ci_runner, :project, projects: [project]) }
it 'user sees the specific runner' do
visit project_runners_path(project)
within '.activated-specific-runners' do
expect(page).to have_content(specific_runner.display_name)
end
click_on specific_runner.short_sha
expect(page).to have_content(specific_runner.platform)
end
it 'user can pause and resume the specific runner' do
visit project_runners_path(project)
within '.activated-specific-runners' do
expect(page).to have_content('Pause')
end
click_on 'Pause'
within '.activated-specific-runners' do
expect(page).to have_content('Resume')
end
click_on 'Resume'
within '.activated-specific-runners' do
expect(page).to have_content('Pause')
end
end
it 'user removes an activated specific runner if this is last project for that runners' do
visit project_runners_path(project)
within '.activated-specific-runners' do
click_on 'Remove Runner'
end
expect(page).not_to have_content(specific_runner.display_name)
end
it 'user edits the runner to be protected' do
visit project_runners_path(project)
within '.activated-specific-runners' do
first('.edit-runner > a').click
end
expect(page.find_field('runner[access_level]')).not_to be_checked
check 'runner_access_level'
click_button 'Save changes'
expect(page).to have_content 'Protected Yes'
end
context 'when a runner has a tag' do
before do
specific_runner.update(tag_list: ['tag'])
end
it 'user edits runner not to run untagged jobs' do
visit project_runners_path(project)
within '.activated-specific-runners' do
first('.edit-runner > a').click
end
expect(page.find_field('runner[run_untagged]')).to be_checked
uncheck 'runner_run_untagged'
click_button 'Save changes'
expect(page).to have_content 'Can run untagged jobs No'
end
end
context 'when a shared runner is activated on the project' do
let!(:shared_runner) { create(:ci_runner, :instance) }
it 'user sees CI/CD setting page' do
visit project_runners_path(project)
expect(page.find('.available-shared-runners')).to have_content(shared_runner.display_name)
end
end
end
context 'when a specific runner exists in another project' do
let(:another_project) { create(:project) }
let!(:specific_runner) { create(:ci_runner, :project, projects: [another_project]) }
before do
another_project.add_maintainer(user)
end
it 'user enables and disables a specific runner' do
visit project_runners_path(project)
within '.available-specific-runners' do
click_on 'Enable for this project'
end
expect(page.find('.activated-specific-runners')).to have_content(specific_runner.display_name)
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
end
context 'when application settings have shared_runners_text' do
let(:shared_runners_text) { 'custom **shared** runners description' }
let(:shared_runners_html) { 'custom shared runners description' }
before do
stub_application_setting(shared_runners_text: shared_runners_text)
end
it 'user sees shared runners description' do
visit project_runners_path(project)
expect(page.find('.shared-runners-description')).to have_content(shared_runners_html)
end
end
end
context 'when a project has disabled shared_runners' do
let(:project) { create(:project, shared_runners_enabled: false) }
before do
project.add_maintainer(user)
end
it 'user enables shared runners' do
visit project_runners_path(project)
click_on 'Enable shared Runners'
expect(page.find('.shared-runners-description')).to have_content('Disable shared Runners')
end
end
context 'group runners in project settings' do
before do
project.add_maintainer(user)
end
let(:group) { create :group }
context 'as project and group maintainer' do
before do
group.add_maintainer(user)
end
context 'project with a group but no group runner' do
let(:project) { create :project, group: group }
it 'group runners are not available' do
visit project_runners_path(project)
expect(page).to have_content 'This group does not provide any group Runners yet'
expect(page).to have_content 'Group maintainers can register group runners in the Group CI/CD settings'
expect(page).not_to have_content 'Ask your group maintainer to set up a group Runner'
end
end
end
context 'as project maintainer' do
context 'project without a group' do
let(:project) { create :project }
it 'group runners are not available' do
visit project_runners_path(project)
expect(page).to have_content 'This project does not belong to a group and can therefore not make use of group Runners.'
end
end
context 'project with a group but no group runner' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
it 'group runners are not available' do
visit project_runners_path(project)
expect(page).to have_content 'This group does not provide any group Runners yet.'
expect(page).not_to have_content 'Group maintainers can register group runners in the Group CI/CD settings'
expect(page).to have_content 'Ask your group maintainer to set up a group Runner.'
end
end
context 'project with a group and a group runner' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let!(:ci_runner) { create(:ci_runner, :group, groups: [group], description: 'group-runner') }
it 'group runners are available' do
visit project_runners_path(project)
expect(page).to have_content 'Available group Runners: 1'
expect(page).to have_content 'group-runner'
end
it 'group runners may be disabled for a project' do
visit project_runners_path(project)
click_on 'Disable group Runners'
expect(page).to have_content 'Enable group Runners'
expect(project.reload.group_runners_enabled).to be false
click_on 'Enable group Runners'
expect(page).to have_content 'Disable group Runners'
expect(project.reload.group_runners_enabled).to be true
end
end
end
end
context 'group runners in group settings' do
let(:group) { create(:group) }
before do
group.add_owner(user)
end
context 'group with no runners' do
it 'there are no runners displayed' do
visit group_settings_ci_cd_path(group)
expect(page).to have_content 'No runners found'
end
it 'user can see a link to install runners on kubernetes clusters' do
visit group_settings_ci_cd_path(group)
expect(page).to have_link('Install Runner on Kubernetes', href: group_clusters_path(group))
end
end
context 'group with a runner' do
let!(:runner) { create(:ci_runner, :group, groups: [group], description: 'group-runner') }
it 'the runner is visible' do
visit group_settings_ci_cd_path(group)
expect(page).not_to have_content 'No runners found'
expect(page).to have_content 'Available Runners: 1'
expect(page).to have_content 'group-runner'
end
it 'user can pause and resume the group runner' do
visit group_settings_ci_cd_path(group)
expect(page).to have_link href: pause_group_runner_path(group, runner)
expect(page).not_to have_link href: resume_group_runner_path(group, runner)
click_link href: pause_group_runner_path(group, runner)
expect(page).not_to have_link href: pause_group_runner_path(group, runner)
expect(page).to have_link href: resume_group_runner_path(group, runner)
click_link href: resume_group_runner_path(group, runner)
expect(page).to have_link href: pause_group_runner_path(group, runner)
expect(page).not_to have_link href: resume_group_runner_path(group, runner)
end
it 'user can view runner details' do
visit group_settings_ci_cd_path(group)
expect(page).to have_content(runner.display_name)
click_on runner.short_sha
expect(page).to have_content(runner.platform)
end
it 'user can remove a group runner' do
visit group_settings_ci_cd_path(group)
all(:link, href: group_runner_path(group, runner))[1].click
expect(page).not_to have_content(runner.display_name)
end
it 'user edits the runner to be protected' do
visit group_settings_ci_cd_path(group)
click_link href: edit_group_runner_path(group, runner)
expect(page.find_field('runner[access_level]')).not_to be_checked
check 'runner_access_level'
click_button 'Save changes'
expect(page).to have_content 'Protected Yes'
end
context 'when a runner has a tag' do
before do
runner.update(tag_list: ['tag'])
end
it 'user edits runner not to run untagged jobs' do
visit group_settings_ci_cd_path(group)
click_link href: edit_group_runner_path(group, runner)
expect(page.find_field('runner[run_untagged]')).to be_checked
uncheck 'runner_run_untagged'
click_button 'Save changes'
expect(page).to have_content 'Can run untagged jobs No'
end
end
end
context 'group with a project runner' do
let(:project) { create(:project, group: group) }
let!(:runner) { create(:ci_runner, :project, projects: [project], description: 'project-runner') }
it 'the runner is visible' do
visit group_settings_ci_cd_path(group)
expect(page).not_to have_content 'No runners found'
expect(page).to have_content 'Available Runners: 1'
expect(page).to have_content 'project-runner'
end
it 'user can pause and resume the project runner' do
visit group_settings_ci_cd_path(group)
expect(page).to have_link href: pause_group_runner_path(group, runner)
expect(page).not_to have_link href: resume_group_runner_path(group, runner)
click_link href: pause_group_runner_path(group, runner)
expect(page).not_to have_link href: pause_group_runner_path(group, runner)
expect(page).to have_link href: resume_group_runner_path(group, runner)
click_link href: resume_group_runner_path(group, runner)
expect(page).to have_link href: pause_group_runner_path(group, runner)
expect(page).not_to have_link href: resume_group_runner_path(group, runner)
end
it 'user can view runner details' do
visit group_settings_ci_cd_path(group)
expect(page).to have_content(runner.display_name)
click_on runner.short_sha
expect(page).to have_content(runner.platform)
end
it 'user can remove a project runner' do
visit group_settings_ci_cd_path(group)
all(:link, href: group_runner_path(group, runner))[1].click
expect(page).not_to have_content(runner.display_name)
end
it 'user edits the runner to be protected' do
visit group_settings_ci_cd_path(group)
click_link href: edit_group_runner_path(group, runner)
expect(page.find_field('runner[access_level]')).not_to be_checked
check 'runner_access_level'
click_button 'Save changes'
expect(page).to have_content 'Protected Yes'
end
context 'when a runner has a tag' do
before do
runner.update(tag_list: ['tag'])
end
it 'user edits runner not to run untagged jobs' do
visit group_settings_ci_cd_path(group)
click_link href: edit_group_runner_path(group, runner)
expect(page.find_field('runner[run_untagged]')).to be_checked
uncheck 'runner_run_untagged'
click_button 'Save changes'
expect(page).to have_content 'Can run untagged jobs No'
end
end
end
context 'group with a multi-project runner' do
let(:project) { create(:project, group: group) }
let(:project_2) { create(:project, group: group) }
let!(:runner) { create(:ci_runner, :project, projects: [project, project_2], description: 'group-runner') }
it 'user cannot remove the project runner' do
visit group_settings_ci_cd_path(group)
expect(all(:link, href: group_runner_path(group, runner)).length).to eq(1)
end
end
end
end
|