@@ -31,25 +31,25 @@ import (
31
31
"k8s.io/apimachinery/pkg/runtime"
32
32
"k8s.io/apimachinery/pkg/util/diff"
33
33
34
+ "strings"
35
+
34
36
"k8s.io/client-go/pkg/api"
35
37
"k8s.io/client-go/pkg/api/v1"
36
38
clientgotesting "k8s.io/client-go/testing"
37
- "strings"
38
39
)
39
40
41
+ // TestShouldReconcileBroker ensures that with the expected conditions the
42
+ // reconciler is reported as needing to run.
43
+ //
44
+ // The test cases are proving:
45
+ // - broker without ready condition will reconcile
46
+ // - broker with deletion timestamp set will reconcile
47
+ // - broker without ready condition, with status will reconcile
48
+ // - broker without ready condition, without status will reconcile
49
+ // - broker with status/ready, past relist interval will reconcile
50
+ // - broker with status/ready, within relist interval will NOT reconcile
51
+ // - broker with status/ready/checksum, will reconcile
40
52
func TestShouldReconcileBroker (t * testing.T ) {
41
- // The test cases here are testing shouldReconcileBroker to ensure that
42
- // with the expected conditions the reconciler is reported as needing
43
- // to run.
44
- // The test cases are proving:
45
- // - broker without ready condition will reconcile
46
- // - broker with deletion timestamp set will reconcile
47
- // - broker without ready condition, with status will reconcile
48
- // - broker without ready condition, without status will reconcile
49
- // - broker with status/ready, past relist interval will reconcile
50
- // - broker with status/ready, within relist interval will NOT reconcile
51
- // - broker with status/ready/checksum, will reconcile
52
- //
53
53
// Anonymous struct fields:
54
54
// name: short description of the test
55
55
// broker: broker object to test
@@ -156,6 +156,11 @@ func TestShouldReconcileBroker(t *testing.T) {
156
156
}
157
157
}
158
158
159
+ // TestReconcileBrokerExistingServiceClass verifies a simple, successful run
160
+ // of reconcileBroker(). This test will cause reconcileBroker() to fetch the
161
+ // catalog from the Broker, create a Service Class for the single service that
162
+ // it lists and reconcile the service class ensuring the name and id of the
163
+ // relisted service matches the existing entry and updates the service catalog.
159
164
func TestReconcileBrokerExistingServiceClass (t * testing.T ) {
160
165
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t , getTestCatalogConfig ())
161
166
@@ -185,6 +190,9 @@ func TestReconcileBrokerExistingServiceClass(t *testing.T) {
185
190
assertNumberOfActions (t , kubeActions , 0 )
186
191
}
187
192
193
+ // TestReconcileBrokerExistingServiceClassDifferentExternalID simulates catalog
194
+ // refresh where broker lists an existing service but there is a mismatch on the
195
+ // service class ID which should result in an error
188
196
func TestReconcileBrokerExistingServiceClassDifferentExternalID (t * testing.T ) {
189
197
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t , getTestCatalogConfig ())
190
198
@@ -219,6 +227,9 @@ func TestReconcileBrokerExistingServiceClassDifferentExternalID(t *testing.T) {
219
227
}
220
228
}
221
229
230
+ // TestReconcileBrokerExistingServiceClassDifferentBroker simulates catalog
231
+ // refresh where broker lists a service which matches an existing, already
232
+ // cataloged service but the service points to a different Broker. Results in an error.
222
233
func TestReconcileBrokerExistingServiceClassDifferentBroker (t * testing.T ) {
223
234
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t , getTestCatalogConfig ())
224
235
@@ -253,6 +264,8 @@ func TestReconcileBrokerExistingServiceClassDifferentBroker(t *testing.T) {
253
264
}
254
265
}
255
266
267
+ // TestReconcileBrokerDelete simulates a broker reconciliation where broker was marked for deletion.
268
+ // Results in service class and broker both being deleted.
256
269
func TestReconcileBrokerDelete (t * testing.T ) {
257
270
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , sharedInformers := newTestController (t , getTestCatalogConfig ())
258
271
@@ -279,7 +292,7 @@ func TestReconcileBrokerDelete(t *testing.T) {
279
292
assertNumberOfActions (t , kubeActions , 0 )
280
293
281
294
actions := fakeCatalogClient .Actions ()
282
- // The three actions should be:
295
+ // The four actions should be:
283
296
// 0. Deleting the associated ServiceClass
284
297
// 1. Updating the ready condition
285
298
// 2. Getting the broker
@@ -305,6 +318,9 @@ func TestReconcileBrokerDelete(t *testing.T) {
305
318
}
306
319
}
307
320
321
+ // TestReconcileBrokerErrorFetchingCatalog simulates broker reconciliation where
322
+ // OSB client responds with an error for getting the catalog which in turn causes
323
+ // reconcileBroker() to return an error.
308
324
func TestReconcileBrokerErrorFetchingCatalog (t * testing.T ) {
309
325
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , _ := newTestController (t , fakeosb.FakeClientConfiguration {
310
326
CatalogReaction : & fakeosb.CatalogReaction {
@@ -339,6 +355,9 @@ func TestReconcileBrokerErrorFetchingCatalog(t *testing.T) {
339
355
}
340
356
}
341
357
358
+ // TestReconcileBrokerZeroServices simulates broker reconciliation where
359
+ // OSB client responds with zero services which causes reconcileBroker()
360
+ // to return an error
342
361
func TestReconcileBrokerZeroServices (t * testing.T ) {
343
362
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , _ := newTestController (t , fakeosb.FakeClientConfiguration {
344
363
CatalogReaction : & fakeosb.CatalogReaction {
@@ -534,6 +553,9 @@ func testReconcileBrokerWithAuth(t *testing.T, authInfo *v1alpha1.BrokerAuthInfo
534
553
}
535
554
}
536
555
556
+ // TestReconcileBrokerWithReconcileError simulates broker reconciliation where
557
+ // creation of a service class causes an error which causes ReconcileBroker to
558
+ // return an error
537
559
func TestReconcileBrokerWithReconcileError (t * testing.T ) {
538
560
fakeKubeClient , fakeCatalogClient , fakeBrokerClient , testController , _ := newTestController (t , getTestCatalogConfig ())
539
561
@@ -577,7 +599,25 @@ func TestReconcileBrokerWithReconcileError(t *testing.T) {
577
599
}
578
600
}
579
601
602
+ // TestUpdateBrokerCondition ensures that with specific conditions
603
+ // the broker correctly reflects the changes during updateBrokerCondition().
604
+ //
605
+ // The test cases are proving:
606
+ // - broker transitions from unset status to not ready results in status change and new time
607
+ // - broker transitions from not ready to not ready results in no changes
608
+ // - broker transitions from not ready to not ready and with reason & msg updates results in no time change, but reflects new reason & msg
609
+ // - broker transitions from not ready to ready results in status change & new time
610
+ // - broker transitions from ready to ready results in no status change
611
+ // - broker transitions from ready to not ready results in status change & new time
612
+ // - condition reason & message should always be updated
580
613
func TestUpdateBrokerCondition (t * testing.T ) {
614
+ // Anonymous struct fields:
615
+ // name: short description of the test
616
+ // input: broker object to test
617
+ // status: new condition status
618
+ // reason: condition reason
619
+ // message: condition message
620
+ // transitionTimeChanged: true if the test conditions should result in transition time change
581
621
cases := []struct {
582
622
name string
583
623
input * v1alpha1.Broker
@@ -689,7 +729,7 @@ func TestUpdateBrokerCondition(t *testing.T) {
689
729
continue
690
730
}
691
731
if e , a := tc .message , outputCondition .Message ; e != "" && e != a {
692
- t .Errorf ("%v: condition reasons didn't match; expected %v, got %v" , tc .name , e , a )
732
+ t .Errorf ("%v: condition message didn't match; expected %v, got %v" , tc .name , e , a )
693
733
}
694
734
}
695
735
}
0 commit comments