@@ -530,7 +530,11 @@ func TestRun_SingleCheckerSingleCheck(t *testing.T) {
530
530
},
531
531
},
532
532
}
533
- results := run (ctx , nil , nil , []Checker {checker })
533
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {checker })
534
+ if len (resultsOrderedByCheckerAndCheck ) != 1 {
535
+ t .Fatalf ("expected results for 1 checker, got %d" , len (resultsOrderedByCheckerAndCheck ))
536
+ }
537
+ results := resultsOrderedByCheckerAndCheck [0 ]
534
538
if len (results ) != 1 {
535
539
t .Fatalf ("expected 1 result, got %d" , len (results ))
536
540
}
@@ -560,15 +564,19 @@ func TestRun_MultipleCheckersMultipleChecks(t *testing.T) {
560
564
},
561
565
},
562
566
}
563
- results := run (ctx , nil , nil , []Checker {checker1 , checker2 })
564
- if len (results ) != 3 {
565
- t .Fatalf ("expected 3 results, got %d" , len (results ))
567
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {checker1 , checker2 })
568
+ if len (resultsOrderedByCheckerAndCheck ) != 2 {
569
+ t .Fatalf ("expected results for 2 checkers , got %d" , len (resultsOrderedByCheckerAndCheck ))
566
570
}
567
- names := [] string { results [ 0 ]. Name , results [ 1 ]. Name , results [ 2 ]. Name }
571
+
568
572
expected := []string {"c1-check1" , "c1-check2" , "c2-check1" }
569
- for i , name := range expected {
570
- if names [i ] != name {
571
- t .Errorf ("expected result %d to have name %q, got %q" , i , name , names [i ])
573
+ expectedIdx := 0
574
+ for _ , results := range resultsOrderedByCheckerAndCheck {
575
+ for _ , result := range results {
576
+ if result .Name != expected [expectedIdx ] {
577
+ t .Errorf ("expected result %d to be %q, got %q" , expectedIdx , expected [expectedIdx ], result .Name )
578
+ }
579
+ expectedIdx ++
572
580
}
573
581
}
574
582
}
@@ -595,7 +603,9 @@ func TestRun_ChecksRunInParallel(t *testing.T) {
595
603
},
596
604
},
597
605
}
598
- results := run (ctx , nil , nil , []Checker {checker })
606
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {checker })
607
+
608
+ results := resultsOrderedByCheckerAndCheck [0 ]
599
609
if len (results ) != 2 {
600
610
t .Fatalf ("expected 2 results, got %d" , len (results ))
601
611
}
@@ -670,7 +680,10 @@ func TestRun_ContextCancellation(t *testing.T) {
670
680
cancel ()
671
681
}()
672
682
673
- results := run (ctx , nil , nil , []Checker {checker })
683
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {checker })
684
+ if len (resultsOrderedByCheckerAndCheck ) != 1 {
685
+ t .Fatalf ("expected results for 1 checker, got %d" , len (resultsOrderedByCheckerAndCheck ))
686
+ }
674
687
675
688
select {
676
689
case <- completed :
@@ -679,6 +692,7 @@ func TestRun_ContextCancellation(t *testing.T) {
679
692
// This is expected - the check was cancelled
680
693
}
681
694
695
+ results := resultsOrderedByCheckerAndCheck [0 ]
682
696
if len (results ) != 1 {
683
697
t .Fatalf ("expected 1 result, got %d" , len (results ))
684
698
}
@@ -717,18 +731,21 @@ func TestRun_OrderOfResults(t *testing.T) {
717
731
},
718
732
}
719
733
720
- results := run (ctx , nil , nil , []Checker {checker1 , checker2 })
721
-
722
- if len (results ) != 4 {
723
- t .Fatalf ("expected 4 results, got %d" , len (results ))
734
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {checker1 , checker2 })
735
+ if len (resultsOrderedByCheckerAndCheck ) != 2 {
736
+ t .Fatalf ("expected results for 2 checkers, got %d" , len (resultsOrderedByCheckerAndCheck ))
724
737
}
725
738
726
739
// The order should be all checks from checker1 followed by all checks from checker2,
727
740
// regardless of their completion time
728
741
expected := []string {"c1-check1" , "c1-check2" , "c2-check1" , "c2-check2" }
729
- for i , name := range expected {
730
- if results [i ].Name != name {
731
- t .Errorf ("result[%d]: expected %q, got %q" , i , name , results [i ].Name )
742
+ expectedIdx := 0
743
+ for _ , results := range resultsOrderedByCheckerAndCheck {
744
+ for _ , result := range results {
745
+ if result .Name != expected [expectedIdx ] {
746
+ t .Errorf ("expected result %d to be %q, got %q" , expectedIdx , expected [expectedIdx ], result .Name )
747
+ }
748
+ expectedIdx ++
732
749
}
733
750
}
734
751
}
@@ -761,11 +778,16 @@ func TestRun_LargeNumberOfCheckersAndChecks(t *testing.T) {
761
778
}
762
779
763
780
start := time .Now ()
764
- results := run (ctx , nil , nil , checkers )
781
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , checkers )
765
782
duration := time .Since (start )
766
783
767
- if len (results ) != expectedTotal {
768
- t .Errorf ("expected %d results, got %d" , expectedTotal , len (results ))
784
+ resultTotal := 0
785
+ for _ , results := range resultsOrderedByCheckerAndCheck {
786
+ resultTotal += len (results )
787
+ }
788
+
789
+ if resultTotal != expectedTotal {
790
+ t .Errorf ("expected %d results, got %d" , expectedTotal , resultTotal )
769
791
}
770
792
771
793
t .Logf ("Completed %d checks in %v" , expectedTotal , duration )
@@ -799,8 +821,13 @@ func TestRun_ErrorHandlingInChecks(t *testing.T) {
799
821
},
800
822
}
801
823
802
- results := run (ctx , nil , nil , []Checker {checker })
824
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {checker })
825
+
826
+ if len (resultsOrderedByCheckerAndCheck ) != 1 {
827
+ t .Fatalf ("expected results for 1 checker, got %d" , len (resultsOrderedByCheckerAndCheck ))
828
+ }
803
829
830
+ results := resultsOrderedByCheckerAndCheck [0 ]
804
831
if len (results ) != 2 {
805
832
t .Fatalf ("expected 2 results, got %d" , len (results ))
806
833
}
@@ -840,13 +867,23 @@ func TestRun_ZeroChecksFromChecker(t *testing.T) {
840
867
},
841
868
}
842
869
843
- results := run (ctx , nil , nil , []Checker {emptyChecker , normalChecker })
870
+ resultsOrderedByCheckerAndCheck := run (ctx , nil , nil , []Checker {emptyChecker , normalChecker })
844
871
845
- if len (results ) != 1 {
846
- t .Fatalf ("expected 1 result, got %d" , len (results ))
872
+ if len (resultsOrderedByCheckerAndCheck ) != 2 {
873
+ t .Fatalf ("expected results for 2 checkers, got %d" , len (resultsOrderedByCheckerAndCheck ))
874
+ }
875
+
876
+ emptyResults := resultsOrderedByCheckerAndCheck [0 ] // We expect no results from the empty checker
877
+ if len (emptyResults ) != 0 {
878
+ t .Fatalf ("expected 0 results from empty checker, got %d" , len (emptyResults ))
879
+ }
880
+
881
+ normalResults := resultsOrderedByCheckerAndCheck [1 ] // We expect results from the normal checker
882
+ if len (normalResults ) != 1 {
883
+ t .Fatalf ("expected 1 result, got %d" , len (normalResults ))
847
884
}
848
885
849
- if results [0 ].Name != "check1" {
850
- t .Errorf ("expected result from normal checker, got %s" , results [0 ].Name )
886
+ if normalResults [0 ].Name != "check1" {
887
+ t .Errorf ("expected result from normal checker, got %s" , normalResults [0 ].Name )
851
888
}
852
889
}
0 commit comments