@@ -340,7 +340,7 @@ func TestEnumerateWithApp(t *testing.T) {
340
340
}
341
341
342
342
// This only tests the resume info slice portion of setProgressCompleteWithRepo.
343
- func Test_setProgressCompleteWithRepo (t * testing.T ) {
343
+ func Test_setProgressCompleteWithRepo_resumeInfo (t * testing.T ) {
344
344
tests := []struct {
345
345
startingResumeInfoSlice []string
346
346
repoURL string
@@ -367,9 +367,68 @@ func Test_setProgressCompleteWithRepo(t *testing.T) {
367
367
368
368
for _ , tt := range tests {
369
369
s .resumeInfoSlice = tt .startingResumeInfoSlice
370
- s .setProgressCompleteWithRepo (0 , tt .repoURL )
370
+ s .setProgressCompleteWithRepo (0 , 0 , tt .repoURL )
371
371
if ! reflect .DeepEqual (s .resumeInfoSlice , tt .wantResumeInfoSlice ) {
372
372
t .Errorf ("s.setProgressCompleteWithRepo() got: %v, want: %v" , s .resumeInfoSlice , tt .wantResumeInfoSlice )
373
373
}
374
374
}
375
375
}
376
+
377
+ func Test_setProgressCompleteWithRepo_Progress (t * testing.T ) {
378
+ repos := []string {"a" , "b" , "c" , "d" , "e" }
379
+ tests := map [string ]struct {
380
+ repos []string
381
+ index int
382
+ offset int
383
+ wantPercentComplete int64
384
+ wantSectionsCompleted int32
385
+ wantSectionsRemaining int32
386
+ }{
387
+ "starting from the beginning, no offset" : {
388
+ repos : repos ,
389
+ index : 0 ,
390
+ offset : 0 ,
391
+ wantPercentComplete : 0 ,
392
+ wantSectionsCompleted : 0 ,
393
+ wantSectionsRemaining : 5 ,
394
+ },
395
+ "resume from the third, offset 2" : {
396
+ repos : repos [2 :],
397
+ index : 0 ,
398
+ offset : 2 ,
399
+ wantPercentComplete : 40 ,
400
+ wantSectionsCompleted : 2 ,
401
+ wantSectionsRemaining : 5 ,
402
+ },
403
+ "resume from the third, on last repo, offset 2" : {
404
+ repos : repos [2 :],
405
+ index : 2 ,
406
+ offset : 2 ,
407
+ wantPercentComplete : 80 ,
408
+ wantSectionsCompleted : 4 ,
409
+ wantSectionsRemaining : 5 ,
410
+ },
411
+ }
412
+
413
+ logger := logrus .New ()
414
+ logger .Out = io .Discard
415
+
416
+ for _ , tt := range tests {
417
+ s := & Source {
418
+ repos : tt .repos ,
419
+ log : logger .WithField ("no" , "output" ),
420
+ }
421
+
422
+ s .setProgressCompleteWithRepo (tt .index , tt .offset , "" )
423
+ gotProgress := s .GetProgress ()
424
+ if gotProgress .PercentComplete != tt .wantPercentComplete {
425
+ t .Errorf ("s.setProgressCompleteWithRepo() PercentComplete got: %v want: %v" , gotProgress .PercentComplete , tt .wantPercentComplete )
426
+ }
427
+ if gotProgress .SectionsCompleted != tt .wantSectionsCompleted {
428
+ t .Errorf ("s.setProgressCompleteWithRepo() PercentComplete got: %v want: %v" , gotProgress .SectionsCompleted , tt .wantSectionsCompleted )
429
+ }
430
+ if gotProgress .SectionsRemaining != tt .wantSectionsRemaining {
431
+ t .Errorf ("s.setProgressCompleteWithRepo() PercentComplete got: %v want: %v" , gotProgress .SectionsRemaining , tt .wantSectionsRemaining )
432
+ }
433
+ }
434
+ }
0 commit comments