@@ -231,13 +231,18 @@ func TestResolveCleanupStrategy(t *testing.T) {
231
231
const (
232
232
fallbackStrategy strategyDesc = "fallback"
233
233
fullCleanupStrategy strategyDesc = "fullCleanup"
234
+ skipCleanup strategyDesc = "skipCleanup"
235
+
236
+ nodeUntouched nodeStatus = 0
237
+ nodeTouched nodeStatus = 1
234
238
)
235
239
236
240
testCases := []struct {
237
241
desc string
238
242
fallback bool
239
243
allowPartlyDone bool
240
244
clusterStatus defs.Status
245
+ nodeStatus nodeStatus
241
246
wantStrategy strategyDesc
242
247
}{
243
248
// fallback enabled
@@ -246,43 +251,49 @@ func TestResolveCleanupStrategy(t *testing.T) {
246
251
fallback : true ,
247
252
allowPartlyDone : true ,
248
253
clusterStatus : defs .StatusError ,
254
+ nodeStatus : nodeTouched ,
249
255
wantStrategy : fallbackStrategy ,
250
256
},
251
257
{
252
258
desc : "fallback: enabled, allow-partly-done: enabled, status: partly-done" ,
253
259
fallback : true ,
254
260
allowPartlyDone : true ,
255
261
clusterStatus : defs .StatusPartlyDone ,
262
+ nodeStatus : nodeTouched ,
256
263
wantStrategy : fullCleanupStrategy ,
257
264
},
258
265
{
259
266
desc : "fallback: enabled, allow-partly-done: enabled, status: done" ,
260
267
fallback : true ,
261
268
allowPartlyDone : true ,
262
269
clusterStatus : defs .StatusDone ,
263
- wantStrategy : fullCleanupStrategy ,
270
+ nodeStatus : nodeTouched ,
271
+ wantStrategy : skipCleanup ,
264
272
},
265
273
266
274
{
267
275
desc : "fallback: enabled, allow-partly-done: disabled, status: error" ,
268
276
fallback : true ,
269
277
allowPartlyDone : false ,
270
278
clusterStatus : defs .StatusError ,
279
+ nodeStatus : nodeTouched ,
271
280
wantStrategy : fallbackStrategy ,
272
281
},
273
282
{
274
283
desc : "fallback: enabled, allow-partly-done: disabled, status: partly-done" ,
275
284
fallback : true ,
276
285
allowPartlyDone : false ,
277
286
clusterStatus : defs .StatusPartlyDone ,
287
+ nodeStatus : nodeTouched ,
278
288
wantStrategy : fallbackStrategy ,
279
289
},
280
290
{
281
291
desc : "fallback: enabled, allow-partly-done: disabled, status: done" ,
282
292
fallback : true ,
283
293
allowPartlyDone : false ,
284
294
clusterStatus : defs .StatusDone ,
285
- wantStrategy : fullCleanupStrategy ,
295
+ nodeStatus : nodeTouched ,
296
+ wantStrategy : skipCleanup ,
286
297
},
287
298
288
299
// fallback disabled
@@ -291,43 +302,66 @@ func TestResolveCleanupStrategy(t *testing.T) {
291
302
fallback : false ,
292
303
allowPartlyDone : true ,
293
304
clusterStatus : defs .StatusError ,
305
+ nodeStatus : nodeTouched ,
294
306
wantStrategy : fullCleanupStrategy ,
295
307
},
296
308
{
297
309
desc : "fallback: disabled, allow-partly-done: enabled, status: partly-done" ,
298
310
fallback : false ,
299
311
allowPartlyDone : true ,
300
312
clusterStatus : defs .StatusPartlyDone ,
313
+ nodeStatus : nodeTouched ,
301
314
wantStrategy : fullCleanupStrategy ,
302
315
},
303
316
{
304
317
desc : "fallback: disabled, allow-partly-done: enabled, status: done" ,
305
318
fallback : false ,
306
319
allowPartlyDone : true ,
307
320
clusterStatus : defs .StatusDone ,
308
- wantStrategy : fullCleanupStrategy ,
321
+ nodeStatus : nodeTouched ,
322
+ wantStrategy : skipCleanup ,
309
323
},
310
-
311
324
{
312
325
desc : "fallback: disabled, allow-partly-done: disabled, status: error" ,
313
326
fallback : false ,
314
327
allowPartlyDone : false ,
315
328
clusterStatus : defs .StatusError ,
329
+ nodeStatus : nodeTouched ,
316
330
wantStrategy : fullCleanupStrategy ,
317
331
},
318
332
{
319
333
desc : "fallback: disabled, allow-partly-done: disabled, status: partly-done" ,
320
334
fallback : false ,
321
335
allowPartlyDone : false ,
322
336
clusterStatus : defs .StatusPartlyDone ,
337
+ nodeStatus : nodeTouched ,
323
338
wantStrategy : fullCleanupStrategy ,
324
339
},
325
340
{
326
341
desc : "fallback: disabled, allow-partly-done: disabled, status: done" ,
327
342
fallback : false ,
328
343
allowPartlyDone : false ,
329
344
clusterStatus : defs .StatusDone ,
330
- wantStrategy : fullCleanupStrategy ,
345
+ nodeStatus : nodeTouched ,
346
+ wantStrategy : skipCleanup ,
347
+ },
348
+
349
+ // db path is untouched
350
+ {
351
+ desc : "fallback: enabled, allow-partly-done: enabled, status: error" ,
352
+ fallback : true ,
353
+ allowPartlyDone : true ,
354
+ clusterStatus : defs .StatusError ,
355
+ nodeStatus : nodeUntouched ,
356
+ wantStrategy : skipCleanup ,
357
+ },
358
+ {
359
+ desc : "fallback: disabled, allow-partly-done: enabled, status: error" ,
360
+ fallback : false ,
361
+ allowPartlyDone : true ,
362
+ clusterStatus : defs .StatusError ,
363
+ nodeStatus : nodeUntouched ,
364
+ wantStrategy : skipCleanup ,
331
365
},
332
366
}
333
367
@@ -338,7 +372,7 @@ func TestResolveCleanupStrategy(t *testing.T) {
338
372
allowPartlyDone : tC .allowPartlyDone ,
339
373
log : log .DiscardLogger .NewDefaultEvent (),
340
374
}
341
- strategy := r .resolveCleanupStrategy (tC .clusterStatus )
375
+ strategy := r .resolveCleanupStrategy (tC .clusterStatus , tC . nodeStatus )
342
376
if tC .wantStrategy == fullCleanupStrategy {
343
377
if cmpStrategy (strategy ) != cmpStrategy (r .doFullCleanup ) {
344
378
t .Fatalf ("want=%s" , fullCleanupStrategy )
@@ -348,6 +382,10 @@ func TestResolveCleanupStrategy(t *testing.T) {
348
382
if cmpStrategy (strategy ) != cmpStrategy (r .doFallbackCleanup ) {
349
383
t .Fatalf ("want=%s" , fallbackStrategy )
350
384
}
385
+ } else if tC .wantStrategy == skipCleanup {
386
+ if cmpStrategy (strategy ) != cmpStrategy (r .skipCleanup ) {
387
+ t .Fatalf ("want=%s" , skipCleanup )
388
+ }
351
389
}
352
390
})
353
391
}
0 commit comments