@@ -165,11 +165,14 @@ func TestConditionsEqual(t *testing.T) {
165165 }
166166
167167 for _ , tc := range testCases {
168- actual := conditionEqual (tc .a , tc .b )
169- if actual != tc .expected {
170- t .Fatalf ("%q: expected %v, got %v" , tc .description ,
171- tc .expected , actual )
172- }
168+ t .Run (tc .description , func (t * testing.T ) {
169+
170+ actual := conditionEqual (tc .a , tc .b )
171+ if actual != tc .expected {
172+ t .Fatalf ("%q: expected %v, got %v" , tc .description ,
173+ tc .expected , actual )
174+ }
175+ })
173176 }
174177}
175178
@@ -293,43 +296,45 @@ func TestConditions(t *testing.T) {
293296 }
294297
295298 for _ , test := range tests {
299+ t .Run (test .name , func (t * testing.T ) {
300+
301+ basicClusterOperator := testBasicClusterOperator ()
302+ // Make sure we have a clean ClusterOperator and CCO config for each test run
303+ objects := []runtime.Object {
304+ basicClusterOperator ,
305+ testOperatorConfig ("" ),
306+ }
307+
308+ fakeClient := fake .NewClientBuilder ().
309+ WithStatusSubresource (basicClusterOperator ).
310+ WithRuntimeObjects (objects ... ).Build ()
311+
312+ r := & ReconcileStatus {
313+ Client : fakeClient ,
314+ Logger : log .WithField ("controller" , controllerName ),
315+ platform : configv1 .AWSPlatformType ,
316+ }
296317
297- basicClusterOperator := testBasicClusterOperator ()
298- // Make sure we have a clean ClusterOperator and CCO config for each test run
299- objects := []runtime.Object {
300- basicClusterOperator ,
301- testOperatorConfig ("" ),
302- }
303-
304- fakeClient := fake .NewClientBuilder ().
305- WithStatusSubresource (basicClusterOperator ).
306- WithRuntimeObjects (objects ... ).Build ()
307-
308- r := & ReconcileStatus {
309- Client : fakeClient ,
310- Logger : log .WithField ("controller" , controllerName ),
311- platform : configv1 .AWSPlatformType ,
312- }
313-
314- for _ , handler := range test .statusHandlers {
315- AddHandler (handler .Name (), handler )
316- }
317- defer clearHandlers ()
318-
319- _ , err := r .Reconcile (context .TODO (), reconcile.Request {})
320-
321- require .NoError (t , err , "unexpected error" )
322-
323- for _ , condition := range test .expectedConditions {
324- co := getClusterOperator (fakeClient )
325- assert .NotNil (t , co )
326- foundCondition , _ := findClusterOperatorCondition (co .Status .Conditions , condition .conditionType )
327- require .NotNil (t , foundCondition )
328- assert .Equal (t , string (condition .status ), string (foundCondition .Status ), "condition %s had unexpected status" , condition .conditionType )
329- if condition .reason != "" {
330- assert .Exactly (t , condition .reason , foundCondition .Reason )
318+ for _ , handler := range test .statusHandlers {
319+ AddHandler (handler .Name (), handler )
331320 }
332- }
321+ defer clearHandlers ()
322+
323+ _ , err := r .Reconcile (context .TODO (), reconcile.Request {})
324+
325+ require .NoError (t , err , "unexpected error" )
326+
327+ for _ , condition := range test .expectedConditions {
328+ co := getClusterOperator (fakeClient )
329+ assert .NotNil (t , co )
330+ foundCondition , _ := findClusterOperatorCondition (co .Status .Conditions , condition .conditionType )
331+ require .NotNil (t , foundCondition )
332+ assert .Equal (t , string (condition .status ), string (foundCondition .Status ), "condition %s had unexpected status" , condition .conditionType )
333+ if condition .reason != "" {
334+ assert .Exactly (t , condition .reason , foundCondition .Reason )
335+ }
336+ }
337+ })
333338 }
334339}
335340
@@ -438,21 +443,23 @@ func TestSortedStatus(t *testing.T) {
438443 }
439444
440445 for _ , test := range tests {
441- sortStatusArrays (& test .status )
442- assert .ElementsMatchf (t , test .status .Conditions , test .expected .Conditions , "conditions = %v, want %v" , test .status .Conditions , test .expected .Conditions )
443- assert .ElementsMatchf (t , test .status .RelatedObjects , test .expected .RelatedObjects , "conditions = %v, want %v" , test .status .RelatedObjects , test .expected .RelatedObjects )
446+ t .Run (test .name , func (t * testing.T ) {
447+ sortStatusArrays (& test .status )
448+ assert .ElementsMatchf (t , test .status .Conditions , test .expected .Conditions , "conditions = %v, want %v" , test .status .Conditions , test .expected .Conditions )
449+ assert .ElementsMatchf (t , test .status .RelatedObjects , test .expected .RelatedObjects , "conditions = %v, want %v" , test .status .RelatedObjects , test .expected .RelatedObjects )
444450
445- for i , expected := range test .expected .Conditions {
446- assert .Equal (t , expected , test .status .Conditions [i ])
447- }
451+ for i , expected := range test .expected .Conditions {
452+ assert .Equal (t , expected , test .status .Conditions [i ])
453+ }
448454
449- for i , expected := range test .expected .RelatedObjects {
450- assert .Equal (t , expected , test .expected .RelatedObjects [i ])
451- }
455+ for i , expected := range test .expected .RelatedObjects {
456+ assert .Equal (t , expected , test .expected .RelatedObjects [i ])
457+ }
452458
453- if ! reflect .DeepEqual (test .status , test .expected ) {
454- t .Error ("status' are not equal" )
455- }
459+ if ! reflect .DeepEqual (test .status , test .expected ) {
460+ t .Error ("status' are not equal" )
461+ }
462+ })
456463 }
457464}
458465
@@ -534,7 +541,7 @@ func newHandler(name string, conditions []configv1.ClusterOperatorStatusConditio
534541 }
535542}
536543
537- func (h * miniHandler ) GetConditions (log.FieldLogger ) ([]configv1.ClusterOperatorStatusCondition , error ) {
544+ func (h * miniHandler ) GetConditions (context. Context , log.FieldLogger ) ([]configv1.ClusterOperatorStatusCondition , error ) {
538545 return h .conditions , nil
539546}
540547
0 commit comments