@@ -82,7 +82,10 @@ func TestNoPrebuilds(t *testing.T) {
82
82
require .NoError (t , err )
83
83
84
84
validateState (t , prebuilds.ReconciliationState { /*all zero values*/ }, * state )
85
- validateActions (t , prebuilds.ReconciliationActions { /*all zero values*/ }, * actions )
85
+ validateActions (t , prebuilds.ReconciliationActions {
86
+ ActionType : prebuilds .ActionTypeCreate ,
87
+ Create : 0 ,
88
+ }, * actions )
86
89
}
87
90
88
91
// A new template version with a preset with prebuilds configured should result in a new prebuild being created.
@@ -107,7 +110,8 @@ func TestNetNew(t *testing.T) {
107
110
Desired : 1 ,
108
111
}, * state )
109
112
validateActions (t , prebuilds.ReconciliationActions {
110
- Create : 1 ,
113
+ ActionType : prebuilds .ActionTypeCreate ,
114
+ Create : 1 ,
111
115
}, * actions )
112
116
}
113
117
@@ -143,7 +147,9 @@ func TestOutdatedPrebuilds(t *testing.T) {
143
147
actions , err := ps .CalculateActions (clock , backoffInterval )
144
148
require .NoError (t , err )
145
149
validateState (t , prebuilds.ReconciliationState {}, * state )
146
- validateActions (t , prebuilds.ReconciliationActions {DeleteIDs : []uuid.UUID {outdated .prebuildID }}, * actions )
150
+ validateActions (t , prebuilds.ReconciliationActions {
151
+ ActionType : prebuilds .ActionTypeDelete ,
152
+ DeleteIDs : []uuid.UUID {outdated .prebuildID }}, * actions )
147
153
148
154
// WHEN: calculating the current preset's state.
149
155
ps , err = snapshot .FilterByPreset (current .presetID )
@@ -154,7 +160,10 @@ func TestOutdatedPrebuilds(t *testing.T) {
154
160
actions , err = ps .CalculateActions (clock , backoffInterval )
155
161
require .NoError (t , err )
156
162
validateState (t , prebuilds.ReconciliationState {Desired : 1 }, * state )
157
- validateActions (t , prebuilds.ReconciliationActions {Create : 1 }, * actions )
163
+ validateActions (t , prebuilds.ReconciliationActions {
164
+ ActionType : prebuilds .ActionTypeCreate ,
165
+ Create : 1 ,
166
+ }, * actions )
158
167
}
159
168
160
169
// A new template version is created with a preset with prebuilds configured; while a prebuild is provisioning up or down,
@@ -181,7 +190,9 @@ func TestInProgressActions(t *testing.T) {
181
190
inProgress : 1 ,
182
191
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
183
192
return validateState (t , prebuilds.ReconciliationState {Desired : 1 , Starting : 1 }, state ) &&
184
- validateActions (t , prebuilds.ReconciliationActions {}, actions )
193
+ validateActions (t , prebuilds.ReconciliationActions {
194
+ ActionType : prebuilds .ActionTypeCreate ,
195
+ }, actions )
185
196
},
186
197
},
187
198
// With one running prebuild and one starting, no creations/deletions should occur since we're approaching the correct state.
@@ -193,7 +204,9 @@ func TestInProgressActions(t *testing.T) {
193
204
inProgress : 1 ,
194
205
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
195
206
return validateState (t , prebuilds.ReconciliationState {Actual : 1 , Desired : 2 , Starting : 1 }, state ) &&
196
- validateActions (t , prebuilds.ReconciliationActions {}, actions )
207
+ validateActions (t , prebuilds.ReconciliationActions {
208
+ ActionType : prebuilds .ActionTypeCreate ,
209
+ }, actions )
197
210
},
198
211
},
199
212
// With one running prebuild and one starting, no creations/deletions should occur
@@ -206,7 +219,9 @@ func TestInProgressActions(t *testing.T) {
206
219
inProgress : 1 ,
207
220
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
208
221
return validateState (t , prebuilds.ReconciliationState {Actual : 2 , Desired : 2 , Starting : 1 }, state ) &&
209
- validateActions (t , prebuilds.ReconciliationActions {}, actions )
222
+ validateActions (t , prebuilds.ReconciliationActions {
223
+ ActionType : prebuilds .ActionTypeCreate ,
224
+ }, actions )
210
225
},
211
226
},
212
227
// With one prebuild desired and one stopping, a new prebuild will be created.
@@ -218,7 +233,10 @@ func TestInProgressActions(t *testing.T) {
218
233
inProgress : 1 ,
219
234
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
220
235
return validateState (t , prebuilds.ReconciliationState {Desired : 1 , Stopping : 1 }, state ) &&
221
- validateActions (t , prebuilds.ReconciliationActions {Create : 1 }, actions )
236
+ validateActions (t , prebuilds.ReconciliationActions {
237
+ ActionType : prebuilds .ActionTypeCreate ,
238
+ Create : 1 ,
239
+ }, actions )
222
240
},
223
241
},
224
242
// With 3 prebuilds desired, 2 running, and 1 stopping, a new prebuild will be created.
@@ -230,7 +248,10 @@ func TestInProgressActions(t *testing.T) {
230
248
inProgress : 1 ,
231
249
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
232
250
return validateState (t , prebuilds.ReconciliationState {Actual : 2 , Desired : 3 , Stopping : 1 }, state ) &&
233
- validateActions (t , prebuilds.ReconciliationActions {Create : 1 }, actions )
251
+ validateActions (t , prebuilds.ReconciliationActions {
252
+ ActionType : prebuilds .ActionTypeCreate ,
253
+ Create : 1 ,
254
+ }, actions )
234
255
},
235
256
},
236
257
// With 3 prebuilds desired, 3 running, and 1 stopping, no creations/deletions should occur since the desired state is already achieved.
@@ -242,7 +263,9 @@ func TestInProgressActions(t *testing.T) {
242
263
inProgress : 1 ,
243
264
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
244
265
return validateState (t , prebuilds.ReconciliationState {Actual : 3 , Desired : 3 , Stopping : 1 }, state ) &&
245
- validateActions (t , prebuilds.ReconciliationActions {}, actions )
266
+ validateActions (t , prebuilds.ReconciliationActions {
267
+ ActionType : prebuilds .ActionTypeCreate ,
268
+ }, actions )
246
269
},
247
270
},
248
271
// With one prebuild desired and one deleting, a new prebuild will be created.
@@ -254,7 +277,10 @@ func TestInProgressActions(t *testing.T) {
254
277
inProgress : 1 ,
255
278
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
256
279
return validateState (t , prebuilds.ReconciliationState {Desired : 1 , Deleting : 1 }, state ) &&
257
- validateActions (t , prebuilds.ReconciliationActions {Create : 1 }, actions )
280
+ validateActions (t , prebuilds.ReconciliationActions {
281
+ ActionType : prebuilds .ActionTypeCreate ,
282
+ Create : 1 ,
283
+ }, actions )
258
284
},
259
285
},
260
286
// With 2 prebuilds desired, 1 running, and 1 deleting, a new prebuild will be created.
@@ -266,7 +292,10 @@ func TestInProgressActions(t *testing.T) {
266
292
inProgress : 1 ,
267
293
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
268
294
return validateState (t , prebuilds.ReconciliationState {Actual : 1 , Desired : 2 , Deleting : 1 }, state ) &&
269
- validateActions (t , prebuilds.ReconciliationActions {Create : 1 }, actions )
295
+ validateActions (t , prebuilds.ReconciliationActions {
296
+ ActionType : prebuilds .ActionTypeCreate ,
297
+ Create : 1 ,
298
+ }, actions )
270
299
},
271
300
},
272
301
// With 2 prebuilds desired, 2 running, and 1 deleting, no creations/deletions should occur since the desired state is already achieved.
@@ -278,7 +307,9 @@ func TestInProgressActions(t *testing.T) {
278
307
inProgress : 1 ,
279
308
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
280
309
return validateState (t , prebuilds.ReconciliationState {Actual : 2 , Desired : 2 , Deleting : 1 }, state ) &&
281
- validateActions (t , prebuilds.ReconciliationActions {}, actions )
310
+ validateActions (t , prebuilds.ReconciliationActions {
311
+ ActionType : prebuilds .ActionTypeCreate ,
312
+ }, actions )
282
313
},
283
314
},
284
315
// With 3 prebuilds desired, 1 running, and 2 starting, no creations should occur since the builds are in progress.
@@ -290,7 +321,7 @@ func TestInProgressActions(t *testing.T) {
290
321
inProgress : 2 ,
291
322
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
292
323
return validateState (t , prebuilds.ReconciliationState {Actual : 1 , Desired : 3 , Starting : 2 }, state ) &&
293
- validateActions (t , prebuilds.ReconciliationActions {Create : 0 }, actions )
324
+ validateActions (t , prebuilds.ReconciliationActions {ActionType : prebuilds . ActionTypeCreate , Create : 0 }, actions )
294
325
},
295
326
},
296
327
// With 3 prebuilds desired, 5 running, and 2 deleting, no deletions should occur since the builds are in progress.
@@ -302,8 +333,11 @@ func TestInProgressActions(t *testing.T) {
302
333
inProgress : 2 ,
303
334
checkFn : func (state prebuilds.ReconciliationState , actions prebuilds.ReconciliationActions ) bool {
304
335
expectedState := prebuilds.ReconciliationState {Actual : 5 , Desired : 3 , Deleting : 2 , Extraneous : 2 }
305
- expectedActions := prebuilds.ReconciliationActions {}
306
- return assert .Len (t , actions .DeleteIDs , 2 , "'deleteIDs' did not match expectation" ) &&
336
+ expectedActions := prebuilds.ReconciliationActions {
337
+ ActionType : prebuilds .ActionTypeDelete ,
338
+ }
339
+ return assert .EqualValuesf (t , expectedActions .ActionType , actions .ActionType , "'ActionType' did not match expectation" ) &&
340
+ assert .Len (t , actions .DeleteIDs , 2 , "'deleteIDs' did not match expectation" ) &&
307
341
assert .EqualValuesf (t , expectedActions .Create , actions .Create , "'create' did not match expectation" ) &&
308
342
assert .EqualValuesf (t , expectedState .Desired , state .Desired , "'desired' did not match expectation" ) &&
309
343
assert .EqualValuesf (t , expectedState .Actual , state .Actual , "'actual' did not match expectation" ) &&
@@ -408,7 +442,8 @@ func TestExtraneous(t *testing.T) {
408
442
Actual : 2 , Desired : 1 , Extraneous : 1 , Eligible : 2 ,
409
443
}, * state )
410
444
validateActions (t , prebuilds.ReconciliationActions {
411
- DeleteIDs : []uuid.UUID {older },
445
+ ActionType : prebuilds .ActionTypeDelete ,
446
+ DeleteIDs : []uuid.UUID {older },
412
447
}, * actions )
413
448
}
414
449
@@ -445,7 +480,8 @@ func TestDeprecated(t *testing.T) {
445
480
require .NoError (t , err )
446
481
validateState (t , prebuilds.ReconciliationState {}, * state )
447
482
validateActions (t , prebuilds.ReconciliationActions {
448
- DeleteIDs : []uuid.UUID {current .prebuildID },
483
+ ActionType : prebuilds .ActionTypeDelete ,
484
+ DeleteIDs : []uuid.UUID {current .prebuildID },
449
485
}, * actions )
450
486
}
451
487
@@ -495,6 +531,7 @@ func TestLatestBuildFailed(t *testing.T) {
495
531
Actual : 0 , Desired : 1 ,
496
532
}, * state )
497
533
validateActions (t , prebuilds.ReconciliationActions {
534
+ ActionType : prebuilds .ActionTypeBackoff ,
498
535
BackoffUntil : lastBuildTime .Add (time .Duration (numFailed ) * backoffInterval ),
499
536
}, * actions )
500
537
@@ -510,6 +547,7 @@ func TestLatestBuildFailed(t *testing.T) {
510
547
Actual : 1 , Desired : 1 , Eligible : 1 ,
511
548
}, * state )
512
549
validateActions (t , prebuilds.ReconciliationActions {
550
+ ActionType : prebuilds .ActionTypeCreate ,
513
551
BackoffUntil : time.Time {},
514
552
}, * actions )
515
553
@@ -526,6 +564,7 @@ func TestLatestBuildFailed(t *testing.T) {
526
564
Actual : 0 , Desired : 1 ,
527
565
}, * state )
528
566
validateActions (t , prebuilds.ReconciliationActions {
567
+ ActionType : prebuilds .ActionTypeCreate ,
529
568
Create : 1 , // <--- NOTE: we're now able to create a new prebuild because the interval has elapsed.
530
569
BackoffUntil : lastBuildTime .Add (time .Duration (numFailed ) * backoffInterval ),
531
570
}, * actions )
@@ -582,6 +621,7 @@ func validateState(t *testing.T, expected, actual prebuilds.ReconciliationState)
582
621
// validateActions is a convenience func to make tests more readable; it exploits the fact that the default states for
583
622
// prebuilds align with zero values.
584
623
func validateActions (t * testing.T , expected , actual prebuilds.ReconciliationActions ) bool {
585
- return assert .EqualValuesf (t , expected .DeleteIDs , actual .DeleteIDs , "'deleteIDs' did not match expectation" ) &&
624
+ return assert .EqualValuesf (t , expected .ActionType , actual .ActionType , "'ActionType' did not match expectation" ) &&
625
+ assert .EqualValuesf (t , expected .DeleteIDs , actual .DeleteIDs , "'deleteIDs' did not match expectation" ) &&
586
626
assert .EqualValuesf (t , expected .Create , actual .Create , "'create' did not match expectation" )
587
627
}
0 commit comments