knapsack_pro 8.3.2 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -1
- data/.github/pull_request_template.md +5 -17
- data/.gitignore +0 -1
- data/CHANGELOG.md +16 -0
- data/README.md +1 -1
- data/lib/knapsack_pro/client/api/v1/queues.rb +1 -0
- data/lib/knapsack_pro/formatters/time_tracker.rb +4 -4
- data/lib/knapsack_pro/queue_allocator.rb +13 -12
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/client/api/v1/queues_spec.rb +3 -1
- data/spec/knapsack_pro/config/env_spec.rb +330 -352
- data/spec/knapsack_pro/formatters/time_tracker_spec.rb +448 -0
- data/spec_time_tracker/spec_helper.rb +29 -0
- metadata +4 -4
- data/bin/test +0 -15
- data/spec/knapsack_pro/formatters/time_tracker_specs.rb +0 -545
@@ -9,48 +9,46 @@ describe KnapsackPro::Config::Env do
|
|
9
9
|
describe '.ci_node_total' do
|
10
10
|
subject { described_class.ci_node_total }
|
11
11
|
|
12
|
-
context 'when
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
context 'when KNAPSACK_PRO_CI_NODE_TOTAL has value' do
|
13
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_TOTAL' => '5' }) }
|
14
|
+
it { should eq 5 }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when CI environment has value' do
|
18
|
+
before do
|
19
|
+
expect(described_class).to receive(:ci_env_for).with(:node_total).and_return(4)
|
16
20
|
end
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
expect(described_class).to receive(:ci_env_for).with(:node_total).and_return(4)
|
21
|
-
end
|
22
|
+
it { should eq 4 }
|
23
|
+
end
|
22
24
|
|
23
|
-
|
25
|
+
context 'when both KNAPSACK_PRO_CI_NODE_TOTAL and CI environment have value' do
|
26
|
+
before do
|
27
|
+
stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_TOTAL' => env_value })
|
28
|
+
expect(described_class).to receive(:ci_env_for).with(:node_total).and_return(ci_value)
|
24
29
|
end
|
25
30
|
|
26
|
-
context 'when
|
27
|
-
|
28
|
-
|
29
|
-
expect(described_class).to receive(:ci_env_for).with(:node_total).and_return(ci_value)
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'when values are different' do
|
33
|
-
let(:env_value) { '5' }
|
34
|
-
let(:ci_value) { 4 }
|
31
|
+
context 'when values are different' do
|
32
|
+
let(:env_value) { '5' }
|
33
|
+
let(:ci_value) { 4 }
|
35
34
|
|
36
|
-
|
35
|
+
it { should eq 5 }
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
37
|
+
it 'logs a warning' do
|
38
|
+
expect(described_class).to receive(:warn).with(
|
39
|
+
'You have set the environment variable KNAPSACK_PRO_CI_NODE_TOTAL to 5 which could be automatically determined from the CI environment as 4.'
|
40
|
+
)
|
41
|
+
subject
|
44
42
|
end
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
context 'when values are the same' do
|
46
|
+
let(:env_value) { '5' }
|
47
|
+
let(:ci_value) { 5 }
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
49
|
+
it 'does not log a warning' do
|
50
|
+
expect(described_class).not_to receive(:warn)
|
51
|
+
subject
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
@@ -63,56 +61,54 @@ describe KnapsackPro::Config::Env do
|
|
63
61
|
describe '.ci_node_index' do
|
64
62
|
subject { described_class.ci_node_index }
|
65
63
|
|
66
|
-
context 'when
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
context 'when KNAPSACK_PRO_CI_NODE_INDEX has value' do
|
65
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_INDEX' => '3' }) }
|
66
|
+
it { should eq 3 }
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'when CI environment has value' do
|
70
|
+
before do
|
71
|
+
expect(described_class).to receive(:ci_env_for).with(:node_index).and_return(2)
|
70
72
|
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
-
expect(described_class).to receive(:ci_env_for).with(:node_index).and_return(2)
|
75
|
-
end
|
74
|
+
it { should eq 2 }
|
75
|
+
end
|
76
76
|
|
77
|
-
|
77
|
+
context 'when both KNAPSACK_PRO_CI_NODE_INDEX and CI environment have value' do
|
78
|
+
before do
|
79
|
+
stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_INDEX' => env_value })
|
80
|
+
expect(described_class).to receive(:ci_env_for).with(:node_index).and_return(ci_value)
|
78
81
|
end
|
79
82
|
|
80
|
-
context 'when
|
81
|
-
|
82
|
-
|
83
|
-
expect(described_class).to receive(:ci_env_for).with(:node_index).and_return(ci_value)
|
84
|
-
end
|
85
|
-
|
86
|
-
context 'when values are different' do
|
87
|
-
let(:env_value) { '3' }
|
88
|
-
let(:ci_value) { 2 }
|
83
|
+
context 'when values are different' do
|
84
|
+
let(:env_value) { '3' }
|
85
|
+
let(:ci_value) { 2 }
|
89
86
|
|
90
|
-
|
87
|
+
it { should eq 3 }
|
91
88
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
89
|
+
it 'logs a warning' do
|
90
|
+
expect(described_class).to receive(:warn).with(
|
91
|
+
'You have set the environment variable KNAPSACK_PRO_CI_NODE_INDEX to 3 which could be automatically determined from the CI environment as 2.'
|
92
|
+
)
|
93
|
+
subject
|
98
94
|
end
|
95
|
+
end
|
99
96
|
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
context 'when values are the same' do
|
98
|
+
let(:env_value) { '3' }
|
99
|
+
let(:ci_value) { 3 }
|
103
100
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
101
|
+
it 'does not log a warning' do
|
102
|
+
expect(described_class).not_to receive(:warn)
|
103
|
+
subject
|
108
104
|
end
|
109
105
|
end
|
106
|
+
end
|
110
107
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
108
|
+
context 'when order of loading envs does matter' do
|
109
|
+
context 'when GitLab CI' do
|
110
|
+
before { stub_const("ENV", { 'CI_NODE_INDEX' => '2', 'GITLAB_CI' => 'true' }) }
|
111
|
+
it { should eq 1 }
|
116
112
|
end
|
117
113
|
end
|
118
114
|
|
@@ -124,48 +120,46 @@ describe KnapsackPro::Config::Env do
|
|
124
120
|
describe '.ci_node_build_id' do
|
125
121
|
subject { described_class.ci_node_build_id }
|
126
122
|
|
127
|
-
context 'when
|
128
|
-
|
129
|
-
|
130
|
-
|
123
|
+
context 'when KNAPSACK_PRO_CI_NODE_BUILD_ID has value' do
|
124
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_BUILD_ID' => '7' }) }
|
125
|
+
it { should eq '7' }
|
126
|
+
end
|
127
|
+
|
128
|
+
context 'when CI environment has value' do
|
129
|
+
before do
|
130
|
+
expect(described_class).to receive(:ci_env_for).with(:node_build_id).and_return('8')
|
131
131
|
end
|
132
132
|
|
133
|
-
|
134
|
-
|
135
|
-
expect(described_class).to receive(:ci_env_for).with(:node_build_id).and_return('8')
|
136
|
-
end
|
133
|
+
it { should eq '8' }
|
134
|
+
end
|
137
135
|
|
138
|
-
|
136
|
+
context 'when both KNAPSACK_PRO_CI_NODE_BUILD_ID and CI environment have value' do
|
137
|
+
before do
|
138
|
+
stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_BUILD_ID' => env_value })
|
139
|
+
expect(described_class).to receive(:ci_env_for).with(:node_build_id).and_return(ci_value)
|
139
140
|
end
|
140
141
|
|
141
|
-
context 'when
|
142
|
-
|
143
|
-
|
144
|
-
expect(described_class).to receive(:ci_env_for).with(:node_build_id).and_return(ci_value)
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'when values are different' do
|
148
|
-
let(:env_value) { '7' }
|
149
|
-
let(:ci_value) { '8' }
|
142
|
+
context 'when values are different' do
|
143
|
+
let(:env_value) { '7' }
|
144
|
+
let(:ci_value) { '8' }
|
150
145
|
|
151
|
-
|
146
|
+
it { should eq '7' }
|
152
147
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
148
|
+
it 'logs a warning' do
|
149
|
+
expect(described_class).to receive(:warn).with(
|
150
|
+
'You have set the environment variable KNAPSACK_PRO_CI_NODE_BUILD_ID to 7 which could be automatically determined from the CI environment as 8.'
|
151
|
+
)
|
152
|
+
subject
|
159
153
|
end
|
154
|
+
end
|
160
155
|
|
161
|
-
|
162
|
-
|
163
|
-
|
156
|
+
context 'when values are the same' do
|
157
|
+
let(:env_value) { '7' }
|
158
|
+
let(:ci_value) { '7' }
|
164
159
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
160
|
+
it 'does not log a warning' do
|
161
|
+
expect(described_class).not_to receive(:warn)
|
162
|
+
subject
|
169
163
|
end
|
170
164
|
end
|
171
165
|
end
|
@@ -180,48 +174,46 @@ describe KnapsackPro::Config::Env do
|
|
180
174
|
describe '.ci_node_retry_count' do
|
181
175
|
subject { described_class.ci_node_retry_count }
|
182
176
|
|
183
|
-
context 'when
|
184
|
-
|
185
|
-
|
186
|
-
|
177
|
+
context 'when KNAPSACK_PRO_CI_NODE_RETRY_COUNT has value' do
|
178
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_RETRY_COUNT' => '1' }) }
|
179
|
+
it { should eq 1 }
|
180
|
+
end
|
181
|
+
|
182
|
+
context 'when CI environment has value' do
|
183
|
+
before do
|
184
|
+
expect(described_class).to receive(:ci_env_for).with(:node_retry_count).and_return('2')
|
187
185
|
end
|
188
186
|
|
189
|
-
|
190
|
-
|
191
|
-
expect(described_class).to receive(:ci_env_for).with(:node_retry_count).and_return('2')
|
192
|
-
end
|
187
|
+
it { should eq 2 }
|
188
|
+
end
|
193
189
|
|
194
|
-
|
190
|
+
context 'when both KNAPSACK_PRO_CI_NODE_RETRY_COUNT and CI environment have value' do
|
191
|
+
before do
|
192
|
+
stub_const("ENV", { 'KNAPSACK_PRO_CI_NODE_RETRY_COUNT' => env_value })
|
193
|
+
expect(described_class).to receive(:ci_env_for).with(:node_retry_count).and_return(ci_value)
|
195
194
|
end
|
196
195
|
|
197
|
-
context 'when
|
198
|
-
|
199
|
-
|
200
|
-
expect(described_class).to receive(:ci_env_for).with(:node_retry_count).and_return(ci_value)
|
201
|
-
end
|
202
|
-
|
203
|
-
context 'when values are different' do
|
204
|
-
let(:env_value) { '1' }
|
205
|
-
let(:ci_value) { 2 }
|
196
|
+
context 'when values are different' do
|
197
|
+
let(:env_value) { '1' }
|
198
|
+
let(:ci_value) { 2 }
|
206
199
|
|
207
|
-
|
200
|
+
it { should eq 1 }
|
208
201
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
end
|
202
|
+
it 'logs a warning' do
|
203
|
+
expect(described_class).to receive(:warn).with(
|
204
|
+
'You have set the environment variable KNAPSACK_PRO_CI_NODE_RETRY_COUNT to 1 which could be automatically determined from the CI environment as 2.'
|
205
|
+
)
|
206
|
+
subject
|
215
207
|
end
|
208
|
+
end
|
216
209
|
|
217
|
-
|
218
|
-
|
219
|
-
|
210
|
+
context 'when values are the same' do
|
211
|
+
let(:env_value) { '7' }
|
212
|
+
let(:ci_value) { '7' }
|
220
213
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
214
|
+
it 'does not log a warning' do
|
215
|
+
expect(described_class).not_to receive(:warn)
|
216
|
+
subject
|
225
217
|
end
|
226
218
|
end
|
227
219
|
end
|
@@ -247,48 +239,46 @@ describe KnapsackPro::Config::Env do
|
|
247
239
|
describe '.commit_hash' do
|
248
240
|
subject { described_class.commit_hash }
|
249
241
|
|
250
|
-
context 'when
|
251
|
-
|
252
|
-
|
253
|
-
|
242
|
+
context 'when KNAPSACK_PRO_COMMIT_HASH has value' do
|
243
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_COMMIT_HASH' => '3fa64859337f6e56409d49f865d13fd7' }) }
|
244
|
+
it { should eq '3fa64859337f6e56409d49f865d13fd7' }
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when CI environment has value' do
|
248
|
+
before do
|
249
|
+
expect(described_class).to receive(:ci_env_for).with(:commit_hash).and_return('fe61a08118d0d52e97c38666eba1eaf3')
|
254
250
|
end
|
255
251
|
|
256
|
-
|
257
|
-
|
258
|
-
expect(described_class).to receive(:ci_env_for).with(:commit_hash).and_return('fe61a08118d0d52e97c38666eba1eaf3')
|
259
|
-
end
|
252
|
+
it { should eq 'fe61a08118d0d52e97c38666eba1eaf3' }
|
253
|
+
end
|
260
254
|
|
261
|
-
|
255
|
+
context 'when both KNAPSACK_PRO_COMMIT_HASH and CI environment have value' do
|
256
|
+
before do
|
257
|
+
stub_const("ENV", { 'KNAPSACK_PRO_COMMIT_HASH' => env_value })
|
258
|
+
expect(described_class).to receive(:ci_env_for).with(:commit_hash).and_return(ci_value)
|
262
259
|
end
|
263
260
|
|
264
|
-
context 'when
|
265
|
-
|
266
|
-
|
267
|
-
expect(described_class).to receive(:ci_env_for).with(:commit_hash).and_return(ci_value)
|
268
|
-
end
|
269
|
-
|
270
|
-
context 'when values are different' do
|
271
|
-
let(:env_value) { '3fa64859337f6e56409d49f865d13fd7' }
|
272
|
-
let(:ci_value) { 'fe61a08118d0d52e97c38666eba1eaf3' }
|
261
|
+
context 'when values are different' do
|
262
|
+
let(:env_value) { '3fa64859337f6e56409d49f865d13fd7' }
|
263
|
+
let(:ci_value) { 'fe61a08118d0d52e97c38666eba1eaf3' }
|
273
264
|
|
274
|
-
|
265
|
+
it { should eq '3fa64859337f6e56409d49f865d13fd7' }
|
275
266
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
end
|
267
|
+
it 'logs a warning' do
|
268
|
+
expect(described_class).to receive(:warn).with(
|
269
|
+
'You have set the environment variable KNAPSACK_PRO_COMMIT_HASH to 3fa64859337f6e56409d49f865d13fd7 which could be automatically determined from the CI environment as fe61a08118d0d52e97c38666eba1eaf3.'
|
270
|
+
)
|
271
|
+
subject
|
282
272
|
end
|
273
|
+
end
|
283
274
|
|
284
|
-
|
285
|
-
|
286
|
-
|
275
|
+
context 'when values are the same' do
|
276
|
+
let(:env_value) { '3fa64859337f6e56409d49f865d13fd7' }
|
277
|
+
let(:ci_value) { '3fa64859337f6e56409d49f865d13fd7' }
|
287
278
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
end
|
279
|
+
it 'does not log a warning' do
|
280
|
+
expect(described_class).not_to receive(:warn)
|
281
|
+
subject
|
292
282
|
end
|
293
283
|
end
|
294
284
|
end
|
@@ -301,48 +291,46 @@ describe KnapsackPro::Config::Env do
|
|
301
291
|
describe '.branch' do
|
302
292
|
subject { described_class.branch }
|
303
293
|
|
304
|
-
context 'when
|
305
|
-
|
306
|
-
|
307
|
-
|
294
|
+
context 'when KNAPSACK_PRO_BRANCH has value' do
|
295
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_BRANCH' => 'main' }) }
|
296
|
+
it { should eq 'main' }
|
297
|
+
end
|
298
|
+
|
299
|
+
context 'when CI environment has value' do
|
300
|
+
before do
|
301
|
+
expect(described_class).to receive(:ci_env_for).with(:branch).and_return('feature-branch')
|
308
302
|
end
|
309
303
|
|
310
|
-
|
311
|
-
|
312
|
-
expect(described_class).to receive(:ci_env_for).with(:branch).and_return('feature-branch')
|
313
|
-
end
|
304
|
+
it { should eq 'feature-branch' }
|
305
|
+
end
|
314
306
|
|
315
|
-
|
307
|
+
context 'when both KNAPSACK_PRO_BRANCH and CI environment have value' do
|
308
|
+
before do
|
309
|
+
stub_const("ENV", { 'KNAPSACK_PRO_BRANCH' => env_value })
|
310
|
+
expect(described_class).to receive(:ci_env_for).with(:branch).and_return(ci_value)
|
316
311
|
end
|
317
312
|
|
318
|
-
context 'when
|
319
|
-
|
320
|
-
|
321
|
-
expect(described_class).to receive(:ci_env_for).with(:branch).and_return(ci_value)
|
322
|
-
end
|
323
|
-
|
324
|
-
context 'when values are different' do
|
325
|
-
let(:env_value) { 'main' }
|
326
|
-
let(:ci_value) { 'feature-branch' }
|
313
|
+
context 'when values are different' do
|
314
|
+
let(:env_value) { 'main' }
|
315
|
+
let(:ci_value) { 'feature-branch' }
|
327
316
|
|
328
|
-
|
317
|
+
it { should eq 'main' }
|
329
318
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
end
|
319
|
+
it 'logs a warning' do
|
320
|
+
expect(described_class).to receive(:warn).with(
|
321
|
+
'You have set the environment variable KNAPSACK_PRO_BRANCH to main which could be automatically determined from the CI environment as feature-branch.'
|
322
|
+
)
|
323
|
+
subject
|
336
324
|
end
|
325
|
+
end
|
337
326
|
|
338
|
-
|
339
|
-
|
340
|
-
|
327
|
+
context 'when values are the same' do
|
328
|
+
let(:env_value) { 'main' }
|
329
|
+
let(:ci_value) { 'main' }
|
341
330
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
end
|
331
|
+
it 'does not log a warning' do
|
332
|
+
expect(described_class).not_to receive(:warn)
|
333
|
+
subject
|
346
334
|
end
|
347
335
|
end
|
348
336
|
end
|
@@ -355,48 +343,46 @@ describe KnapsackPro::Config::Env do
|
|
355
343
|
describe '.project_dir' do
|
356
344
|
subject { described_class.project_dir }
|
357
345
|
|
358
|
-
context 'when
|
359
|
-
|
360
|
-
|
361
|
-
|
346
|
+
context 'when KNAPSACK_PRO_PROJECT_DIR has value' do
|
347
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_PROJECT_DIR' => '/home/user/myapp' }) }
|
348
|
+
it { should eq '/home/user/myapp' }
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'when CI environment has value' do
|
352
|
+
before do
|
353
|
+
expect(described_class).to receive(:ci_env_for).with(:project_dir).and_return('/home/runner/myapp')
|
362
354
|
end
|
363
355
|
|
364
|
-
|
365
|
-
|
366
|
-
expect(described_class).to receive(:ci_env_for).with(:project_dir).and_return('/home/runner/myapp')
|
367
|
-
end
|
356
|
+
it { should eq '/home/runner/myapp' }
|
357
|
+
end
|
368
358
|
|
369
|
-
|
359
|
+
context 'when both KNAPSACK_PRO_PROJECT_DIR and CI environment have value' do
|
360
|
+
before do
|
361
|
+
stub_const("ENV", { 'KNAPSACK_PRO_PROJECT_DIR' => env_value })
|
362
|
+
expect(described_class).to receive(:ci_env_for).with(:project_dir).and_return(ci_value)
|
370
363
|
end
|
371
364
|
|
372
|
-
context 'when
|
373
|
-
|
374
|
-
|
375
|
-
expect(described_class).to receive(:ci_env_for).with(:project_dir).and_return(ci_value)
|
376
|
-
end
|
377
|
-
|
378
|
-
context 'when values are different' do
|
379
|
-
let(:env_value) { '/home/user/myapp' }
|
380
|
-
let(:ci_value) { '/home/runner/myapp' }
|
365
|
+
context 'when values are different' do
|
366
|
+
let(:env_value) { '/home/user/myapp' }
|
367
|
+
let(:ci_value) { '/home/runner/myapp' }
|
381
368
|
|
382
|
-
|
369
|
+
it { should eq '/home/user/myapp' }
|
383
370
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
end
|
371
|
+
it 'logs a warning' do
|
372
|
+
expect(described_class).to receive(:warn).with(
|
373
|
+
'You have set the environment variable KNAPSACK_PRO_PROJECT_DIR to /home/user/myapp which could be automatically determined from the CI environment as /home/runner/myapp.'
|
374
|
+
)
|
375
|
+
subject
|
390
376
|
end
|
377
|
+
end
|
391
378
|
|
392
|
-
|
393
|
-
|
394
|
-
|
379
|
+
context 'when values are the same' do
|
380
|
+
let(:env_value) { '/home/user/myapp' }
|
381
|
+
let(:ci_value) { '/home/user/myapp' }
|
395
382
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
end
|
383
|
+
it 'does not log a warning' do
|
384
|
+
expect(described_class).not_to receive(:warn)
|
385
|
+
subject
|
400
386
|
end
|
401
387
|
end
|
402
388
|
end
|
@@ -409,48 +395,46 @@ describe KnapsackPro::Config::Env do
|
|
409
395
|
describe '.user_seat' do
|
410
396
|
subject { described_class.user_seat }
|
411
397
|
|
412
|
-
context 'when
|
413
|
-
|
414
|
-
|
415
|
-
|
398
|
+
context 'when KNAPSACK_PRO_USER_SEAT has value' do
|
399
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_USER_SEAT' => 'John Doe' }) }
|
400
|
+
it { should eq 'John Doe' }
|
401
|
+
end
|
402
|
+
|
403
|
+
context 'when CI environment has value' do
|
404
|
+
before do
|
405
|
+
expect(described_class).to receive(:ci_env_for).with(:user_seat).and_return('Jane Doe')
|
416
406
|
end
|
417
407
|
|
418
|
-
|
419
|
-
|
420
|
-
expect(described_class).to receive(:ci_env_for).with(:user_seat).and_return('Jane Doe')
|
421
|
-
end
|
408
|
+
it { should eq 'Jane Doe' }
|
409
|
+
end
|
422
410
|
|
423
|
-
|
411
|
+
context 'when both KNAPSACK_PRO_USER_SEAT and CI environment have value' do
|
412
|
+
before do
|
413
|
+
stub_const("ENV", { 'KNAPSACK_PRO_USER_SEAT' => env_value })
|
414
|
+
expect(described_class).to receive(:ci_env_for).with(:user_seat).and_return(ci_value)
|
424
415
|
end
|
425
416
|
|
426
|
-
context 'when
|
427
|
-
|
428
|
-
|
429
|
-
expect(described_class).to receive(:ci_env_for).with(:user_seat).and_return(ci_value)
|
430
|
-
end
|
417
|
+
context 'when values are different' do
|
418
|
+
let(:env_value) { 'John Doe' }
|
419
|
+
let(:ci_value) { 'Jane Doe' }
|
431
420
|
|
432
|
-
|
433
|
-
let(:env_value) { 'John Doe' }
|
434
|
-
let(:ci_value) { 'Jane Doe' }
|
435
|
-
|
436
|
-
it { should eq 'John Doe' }
|
421
|
+
it { should eq 'John Doe' }
|
437
422
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
end
|
423
|
+
it 'logs a warning' do
|
424
|
+
expect(described_class).to receive(:warn).with(
|
425
|
+
'You have set the environment variable KNAPSACK_PRO_USER_SEAT to John Doe which could be automatically determined from the CI environment as Jane Doe.'
|
426
|
+
)
|
427
|
+
subject
|
444
428
|
end
|
429
|
+
end
|
445
430
|
|
446
|
-
|
447
|
-
|
448
|
-
|
431
|
+
context 'when values are the same' do
|
432
|
+
let(:env_value) { 'John Doe' }
|
433
|
+
let(:ci_value) { 'John Doe' }
|
449
434
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
end
|
435
|
+
it 'does not log a warning' do
|
436
|
+
expect(described_class).not_to receive(:warn)
|
437
|
+
subject
|
454
438
|
end
|
455
439
|
end
|
456
440
|
end
|
@@ -811,16 +795,14 @@ describe KnapsackPro::Config::Env do
|
|
811
795
|
describe '.fixed_test_suite_split?' do
|
812
796
|
subject { described_class.fixed_test_suite_split? }
|
813
797
|
|
814
|
-
context 'when
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
end
|
798
|
+
context 'when KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=true' do
|
799
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT' => 'true' }) }
|
800
|
+
it { should be true }
|
801
|
+
end
|
819
802
|
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
end
|
803
|
+
context 'when KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT=false' do
|
804
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_FIXED_TEST_SUITE_SPLIT' => 'false' }) }
|
805
|
+
it { should be false }
|
824
806
|
end
|
825
807
|
|
826
808
|
context "when ENV doesn't exist" do
|
@@ -833,70 +815,68 @@ describe KnapsackPro::Config::Env do
|
|
833
815
|
subject { described_class.fixed_queue_split? }
|
834
816
|
after(:each) { described_class.remove_instance_variable(:@fixed_queue_split) }
|
835
817
|
|
836
|
-
context 'when
|
837
|
-
|
838
|
-
[
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
)
|
863
|
-
end
|
864
|
-
|
865
|
-
expect(subject).to eq(false)
|
818
|
+
context 'when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=false' do
|
819
|
+
[
|
820
|
+
['AppVeyor', { 'APPVEYOR' => '123' }],
|
821
|
+
['Buildkite', { 'BUILDKITE' => 'true' }],
|
822
|
+
['CircleCI', { 'CIRCLECI' => 'true' }],
|
823
|
+
['Cirrus CI', { 'CIRRUS_CI' => 'true' }],
|
824
|
+
['Codefresh', { 'CF_BUILD_ID' => '123' }],
|
825
|
+
['Codeship', { 'CI_NAME' => 'codeship' }],
|
826
|
+
['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }],
|
827
|
+
['GitLab CI', { 'GITLAB_CI' => 'true' }],
|
828
|
+
['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }],
|
829
|
+
['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
|
830
|
+
['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
|
831
|
+
['Travis CI', { 'TRAVIS' => 'true' }],
|
832
|
+
['Unsupported CI', {}],
|
833
|
+
].each do |ci, env|
|
834
|
+
it "on #{ci} it is false" do
|
835
|
+
stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'false' }))
|
836
|
+
|
837
|
+
ci_env = described_class.detected_ci.new.fixed_queue_split
|
838
|
+
if ci_env == false
|
839
|
+
expect(described_class).not_to receive(:warn)
|
840
|
+
else
|
841
|
+
expect(described_class).to receive(:warn).with(
|
842
|
+
'You have set the environment variable KNAPSACK_PRO_FIXED_QUEUE_SPLIT to false which could be automatically determined from the CI environment as true.'
|
843
|
+
)
|
866
844
|
end
|
845
|
+
|
846
|
+
expect(subject).to eq(false)
|
867
847
|
end
|
868
848
|
end
|
849
|
+
end
|
869
850
|
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
end
|
897
|
-
|
898
|
-
expect(subject).to eq(true)
|
851
|
+
context 'when KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true' do
|
852
|
+
[
|
853
|
+
['AppVeyor', { 'APPVEYOR' => '123' }],
|
854
|
+
['Buildkite', { 'BUILDKITE' => 'true' }],
|
855
|
+
['CircleCI', { 'CIRCLECI' => 'true' }],
|
856
|
+
['Cirrus CI', { 'CIRRUS_CI' => 'true' }],
|
857
|
+
['Codefresh', { 'CF_BUILD_ID' => '123' }],
|
858
|
+
['Codeship', { 'CI_NAME' => 'codeship' }],
|
859
|
+
['GitHub Actions', { 'GITHUB_ACTIONS' => 'true' }],
|
860
|
+
['GitLab CI', { 'GITLAB_CI' => 'true' }],
|
861
|
+
['Heroku CI', { 'HEROKU_TEST_RUN_ID' => '123' }],
|
862
|
+
['Semaphore CI 1.0', { 'SEMAPHORE_BUILD_NUMBER' => '123' }],
|
863
|
+
['Semaphore CI 2.0', { 'SEMAPHORE' => 'true', 'SEMAPHORE_WORKFLOW_ID' => '123' }],
|
864
|
+
['Travis CI', { 'TRAVIS' => 'true' }],
|
865
|
+
['Unsupported CI', {}],
|
866
|
+
].each do |ci, env|
|
867
|
+
it "on #{ci} it is true" do
|
868
|
+
stub_const("ENV", env.merge({ 'KNAPSACK_PRO_FIXED_QUEUE_SPLIT' => 'true' }))
|
869
|
+
|
870
|
+
ci_env = described_class.detected_ci.new.fixed_queue_split
|
871
|
+
if ci_env == true
|
872
|
+
expect(described_class).not_to receive(:warn)
|
873
|
+
else
|
874
|
+
expect(described_class).to receive(:warn).with(
|
875
|
+
'You have set the environment variable KNAPSACK_PRO_FIXED_QUEUE_SPLIT to true which could be automatically determined from the CI environment as false.'
|
876
|
+
)
|
899
877
|
end
|
878
|
+
|
879
|
+
expect(subject).to eq(true)
|
900
880
|
end
|
901
881
|
end
|
902
882
|
end
|
@@ -1121,39 +1101,37 @@ describe KnapsackPro::Config::Env do
|
|
1121
1101
|
describe '.mode' do
|
1122
1102
|
subject { described_class.mode }
|
1123
1103
|
|
1124
|
-
context 'when
|
1125
|
-
|
1126
|
-
before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'development' }) }
|
1104
|
+
context 'when development mode' do
|
1105
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'development' }) }
|
1127
1106
|
|
1128
|
-
|
1129
|
-
|
1107
|
+
it { should eq :development }
|
1108
|
+
end
|
1130
1109
|
|
1131
|
-
|
1132
|
-
|
1110
|
+
context 'when test mode' do
|
1111
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'test' }) }
|
1133
1112
|
|
1134
|
-
|
1135
|
-
|
1113
|
+
it { should eq :test }
|
1114
|
+
end
|
1136
1115
|
|
1137
|
-
|
1138
|
-
|
1116
|
+
context 'when production mode' do
|
1117
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'production' }) }
|
1139
1118
|
|
1140
|
-
|
1141
|
-
|
1119
|
+
it { should eq :production }
|
1120
|
+
end
|
1142
1121
|
|
1143
|
-
|
1144
|
-
|
1122
|
+
context 'when fake mode' do
|
1123
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => 'fake' }) }
|
1145
1124
|
|
1146
|
-
|
1147
|
-
|
1148
|
-
end
|
1125
|
+
it do
|
1126
|
+
expect { subject }.to raise_error(ArgumentError)
|
1149
1127
|
end
|
1128
|
+
end
|
1150
1129
|
|
1151
|
-
|
1152
|
-
|
1130
|
+
context 'when blank mode' do
|
1131
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_MODE' => '' }) }
|
1153
1132
|
|
1154
|
-
|
1155
|
-
|
1156
|
-
end
|
1133
|
+
it do
|
1134
|
+
expect { subject }.to raise_error(ArgumentError)
|
1157
1135
|
end
|
1158
1136
|
end
|
1159
1137
|
|