@@ -83,8 +83,8 @@ func TestReconcileServiceBindingNonExistingServiceInstance(t *testing.T) {
83
83
assertNumEvents (t , events , 1 )
84
84
85
85
expectedEvent := corev1 .EventTypeWarning + " " + errorNonexistentServiceInstanceReason + " " + "References a non-existent ServiceInstance \" /nothere\" "
86
- if e , a := expectedEvent , events [ 0 ]; e != a {
87
- t .Fatalf ( "Received unexpected event: %v" , a )
86
+ if err := checkEvents ( events , [] string { expectedEvent }); err != nil {
87
+ t .Fatal ( err )
88
88
}
89
89
}
90
90
@@ -125,7 +125,7 @@ func TestReconcileServiceBindingUnresolvedClusterServiceClassReference(t *testin
125
125
t .Fatal ("serviceclassref was nil and reconcile should return an error" )
126
126
}
127
127
if ! strings .Contains (err .Error (), "not been resolved yet" ) {
128
- t .Fatalf ("Did not get the expected error %q : got %q " , "not been resolved yet" , err )
128
+ t .Fatalf ("Did not get the expected error: %s " , expectedGot ( "not been resolved yet" , err ) )
129
129
}
130
130
131
131
brokerActions := fakeClusterServiceBrokerClient .Actions ()
@@ -174,8 +174,8 @@ func TestReconcileServiceBindingUnresolvedClusterServicePlanReference(t *testing
174
174
t .Fatal ("serviceclass nothere was found and it should not be found" )
175
175
}
176
176
177
- if ! strings . Contains (err .Error (), "not been resolved yet" ) {
178
- t .Fatalf ( "Did not get the expected error %q : got %q" , "not been resolved yet" , err )
177
+ if err := checkEventContains (err .Error (), "not been resolved yet" ); err != nil {
178
+ t .Fatal ( err )
179
179
}
180
180
181
181
brokerActions := fakeClusterServiceBrokerClient .Actions ()
@@ -242,8 +242,8 @@ func TestReconcileServiceBindingNonExistingClusterServiceClass(t *testing.T) {
242
242
assertNumEvents (t , events , 1 )
243
243
244
244
expectedEvent := corev1 .EventTypeWarning + " " + errorNonexistentClusterServiceClassMessage + " " + "References a non-existent ClusterServiceClass (K8S: \" nosuchclassid\" ExternalName: \" " + testNonExistentClusterServiceClassName + "\" )"
245
- if e , a := expectedEvent , events [ 0 ]; e != a {
246
- t .Fatalf ( "Received unexpected event expected: %v got: %v" , e , a )
245
+ if err := checkEvents ( events , [] string { expectedEvent }); err != nil {
246
+ t .Fatal ( err )
247
247
}
248
248
}
249
249
@@ -327,18 +327,19 @@ func TestReconcileServiceBindingWithSecretConflict(t *testing.T) {
327
327
// second action is a get on the secret
328
328
action := kubeActions [1 ].(clientgotesting.GetAction )
329
329
if e , a := "get" , action .GetVerb (); e != a {
330
- t .Fatalf ("Unexpected verb on action; expected %v, got %v " , e , a )
330
+ t .Fatalf ("Unexpected verb on action; %s " , expectedGot ( e , a ) )
331
331
}
332
332
if e , a := "secrets" , action .GetResource ().Resource ; e != a {
333
- t .Fatalf ("Unexpected resource on action; expected %v, got %v " , e , a )
333
+ t .Fatalf ("Unexpected resource on action; %s " , expectedGot ( e , a ) )
334
334
}
335
335
336
336
events := getRecordedEvents (testController )
337
337
assertNumEvents (t , events , 1 )
338
338
339
339
expectedEvent := corev1 .EventTypeWarning + " " + errorInjectingBindResultReason
340
- if e , a := expectedEvent , events [0 ]; ! strings .HasPrefix (a , e ) {
341
- t .Fatalf ("Received unexpected event: %v" , a )
340
+
341
+ if err := checkEventPrefixes (events , []string {expectedEvent }); err != nil {
342
+ t .Fatal (err )
342
343
}
343
344
}
344
345
@@ -441,10 +442,10 @@ func TestReconcileServiceBindingWithParameters(t *testing.T) {
441
442
// second action is a get on the secret
442
443
action := kubeActions [2 ].(clientgotesting.CreateAction )
443
444
if e , a := "create" , action .GetVerb (); e != a {
444
- t .Fatalf ("Unexpected verb on action; expected %v, got %v " , e , a )
445
+ t .Fatalf ("Unexpected verb on action; %s " , expectedGot ( e , a ) )
445
446
}
446
447
if e , a := "secrets" , action .GetResource ().Resource ; e != a {
447
- t .Fatalf ("Unexpected resource on action; expected %v, got %v " , e , a )
448
+ t .Fatalf ("Unexpected resource on action; %s " , expectedGot ( e , a ) )
448
449
}
449
450
actionSecret , ok := action .GetObject ().(* corev1.Secret )
450
451
if ! ok {
@@ -458,29 +459,29 @@ func TestReconcileServiceBindingWithParameters(t *testing.T) {
458
459
t .Fatal ("Secret is not owned by the ServiceBinding" )
459
460
}
460
461
if e , a := testServiceBindingSecretName , actionSecret .Name ; e != a {
461
- t .Fatalf ("Unexpected name of secret; expected %v, got %v " , e , a )
462
+ t .Fatalf ("Unexpected name of secret; %s " , expectedGot ( e , a ) )
462
463
}
463
464
value , ok := actionSecret .Data ["a" ]
464
465
if ! ok {
465
466
t .Fatal ("Didn't find secret key 'a' in created secret" )
466
467
}
467
468
if e , a := "b" , string (value ); e != a {
468
- t .Fatalf ("Unexpected value of key 'a' in created secret; expected %v got %v " , e , a )
469
+ t .Fatalf ("Unexpected value of key 'a' in created secret; %s " , expectedGot ( e , a ) )
469
470
}
470
471
value , ok = actionSecret .Data ["c" ]
471
472
if ! ok {
472
473
t .Fatal ("Didn't find secret key 'a' in created secret" )
473
474
}
474
475
if e , a := "d" , string (value ); e != a {
475
- t .Fatalf ("Unexpected value of key 'c' in created secret; expected %v got %v " , e , a )
476
+ t .Fatalf ("Unexpected value of key 'c' in created secret; %s " , expectedGot ( e , a ) )
476
477
}
477
478
478
479
events := getRecordedEvents (testController )
479
480
assertNumEvents (t , events , 1 )
480
481
481
482
expectedEvent := corev1 .EventTypeNormal + " " + successInjectedBindResultReason + " " + successInjectedBindResultMessage
482
- if e , a := expectedEvent , events [ 0 ]; e != a {
483
- t .Fatalf ( "Received unexpected event: %v" , a )
483
+ if err := checkEvents ( events , [] string { expectedEvent }); err != nil {
484
+ t .Fatal ( err )
484
485
}
485
486
}
486
487
@@ -527,8 +528,8 @@ func TestReconcileServiceBindingNonbindableClusterServiceClass(t *testing.T) {
527
528
assertNumEvents (t , events , 1 )
528
529
529
530
expectedEvent := corev1 .EventTypeWarning + " " + errorNonbindableClusterServiceClassReason + ` References a non-bindable ClusterServiceClass (K8S: "UNBINDABLE-SERVICE" ExternalName: "test-unbindable-serviceclass") and Plan ("test-unbindable-plan") combination`
530
- if e , a := expectedEvent , events [ 0 ]; e != a {
531
- t .Fatalf ( "Received unexpected event: %v" , a )
531
+ if err := checkEvents ( events , [] string { expectedEvent }); err != nil {
532
+ t .Fatal ( err )
532
533
}
533
534
}
534
535
@@ -615,31 +616,31 @@ func TestReconcileServiceBindingNonbindableClusterServiceClassBindablePlan(t *te
615
616
// second action is a get on the secret
616
617
action := kubeActions [2 ].(clientgotesting.CreateAction )
617
618
if e , a := "create" , action .GetVerb (); e != a {
618
- t .Fatalf ("Unexpected verb on action; expected %v, got %v " , e , a )
619
+ t .Fatalf ("Unexpected verb on action; %s " , expectedGot ( e , a ) )
619
620
}
620
621
if e , a := "secrets" , action .GetResource ().Resource ; e != a {
621
- t .Fatalf ("Unexpected resource on action; expected %v, got %v " , e , a )
622
+ t .Fatalf ("Unexpected resource on action; %s " , expectedGot ( e , a ) )
622
623
}
623
624
actionSecret , ok := action .GetObject ().(* corev1.Secret )
624
625
if ! ok {
625
626
t .Fatal ("couldn't convert secret into a corev1.Secret" )
626
627
}
627
628
if e , a := testServiceBindingSecretName , actionSecret .Name ; e != a {
628
- t .Fatalf ("Unexpected name of secret; expected %v, got %v " , e , a )
629
+ t .Fatalf ("Unexpected name of secret; %s " , expectedGot ( e , a ) )
629
630
}
630
631
value , ok := actionSecret .Data ["a" ]
631
632
if ! ok {
632
633
t .Fatal ("Didn't find secret key 'a' in created secret" )
633
634
}
634
635
if e , a := "b" , string (value ); e != a {
635
- t .Fatalf ("Unexpected value of key 'a' in created secret; expected %v got %v " , e , a )
636
+ t .Fatalf ("Unexpected value of key 'a' in created secret; %s " , expectedGot ( e , a ) )
636
637
}
637
638
value , ok = actionSecret .Data ["c" ]
638
639
if ! ok {
639
640
t .Fatal ("Didn't find secret key 'a' in created secret" )
640
641
}
641
642
if e , a := "d" , string (value ); e != a {
642
- t .Fatalf ("Unexpected value of key 'c' in created secret; expected %v got %v " , e , a )
643
+ t .Fatalf ("Unexpected value of key 'c' in created secret; %s " , expectedGot ( e , a ) )
643
644
}
644
645
645
646
events := getRecordedEvents (testController )
@@ -689,8 +690,8 @@ func TestReconcileServiceBindingBindableClusterServiceClassNonbindablePlan(t *te
689
690
assertNumEvents (t , events , 1 )
690
691
691
692
expectedEvent := corev1 .EventTypeWarning + " " + errorNonbindableClusterServiceClassReason + ` References a non-bindable ClusterServiceClass (K8S: "SCGUID" ExternalName: "test-serviceclass") and Plan ("test-unbindable-plan") combination`
692
- if e , a := expectedEvent , events [ 0 ]; e != a {
693
- t .Fatalf ( "Received unexpected event: %v" , a )
693
+ if err := checkEvents ( events , [] string { expectedEvent }); err != nil {
694
+ t .Fatal ( err )
694
695
}
695
696
}
696
697
@@ -722,8 +723,8 @@ func TestReconcileServiceBindingFailsWithServiceInstanceAsyncOngoing(t *testing.
722
723
t .Fatalf ("reconcileServiceBinding did not fail with async operation ongoing" )
723
724
}
724
725
725
- if ! strings . Contains (err .Error (), "Ongoing Asynchronous" ) {
726
- t .Fatalf ( "Did not get the expected error %q : got %q" , "Ongoing Asynchronous" , err )
726
+ if err := checkEventContains (err .Error (), "Ongoing Asynchronous" ); err != nil {
727
+ t .Fatal ( err )
727
728
}
728
729
729
730
brokerActions := fakeClusterServiceBrokerClient .Actions ()
0 commit comments