Created
November 20, 2018 23:08
-
-
Save mszostok/c0d18319b08acf444b116fdd187f9afe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fixBrokerBearerAuthInfo() *v1beta1.ClusterServiceBrokerAuthInfo { | |
return &v1beta1.ClusterServiceBrokerAuthInfo{ | |
Bearer: &v1beta1.ClusterBearerTokenAuthConfig{ | |
SecretRef: &v1beta1.ObjectReference{Namespace: "test-ns", Name: "auth-secret"}, | |
}, | |
} | |
} | |
func fixBrokerBasicAuthSecret() *corev1.Secret { | |
return &corev1.Secret{ | |
Data: map[string][]byte{ | |
v1beta1.BasicAuthUsernameKey: []byte("foo"), | |
v1beta1.BasicAuthPasswordKey: []byte("bar"), | |
}, | |
} | |
} | |
func fixBrokerBearerAuthSecret() *corev1.Secret { | |
return &corev1.Secret{ | |
Data: map[string][]byte{ | |
v1beta1.BearerTokenKey: []byte("token"), | |
}, | |
} | |
} | |
func TestReconcileClusterServiceBrokerDeletionShouldNotUpdateClient(t *testing.T) { | |
cases := []struct { | |
name string | |
authInfo *v1beta1.ClusterServiceBrokerAuthInfo | |
secret *corev1.Secret | |
}{ | |
{ | |
name: "no auth", | |
authInfo: nil, | |
secret: nil, | |
}, | |
{ | |
name: "basic auth", | |
authInfo: fixBrokerBasicAuthInfo(), | |
secret: fixBrokerBasicAuthSecret(), | |
}, | |
{ | |
name: "bearer auth", | |
authInfo: fixBrokerBearerAuthInfo(), | |
secret: fixBrokerBearerAuthSecret(), | |
}, | |
} | |
for _, tc := range cases { | |
t.Run(tc.name, func(t *testing.T) { | |
// given | |
fakeKubeClient, _, fakeClusterServiceBrokerClient, testController, _ := newTestController(t, getTestCatalogConfig()) | |
addGetSecretReaction(fakeKubeClient, tc.secret) | |
broker := getTestClusterServiceBrokerWithAuth(tc.authInfo) | |
broker.DeletionTimestamp = &metav1.Time{} | |
broker.Finalizers = []string{v1beta1.FinalizerServiceCatalog} | |
updateBrokerClientCalled := false | |
testController.brokerClientManager = NewBrokerClientManager(func(_ *osb.ClientConfiguration) (osb.Client, error) { | |
updateBrokerClientCalled = true | |
return nil, nil | |
}) | |
// when | |
err := reconcileClusterServiceBroker(t, testController, broker) | |
if err != nil { | |
t.Fatalf("This should not fail : %v", err) | |
} | |
// then | |
if updateBrokerClientCalled { | |
t.Errorf("Unexpected broker client update action") | |
} | |
brokerActions := fakeClusterServiceBrokerClient.Actions() | |
assertNumberOfBrokerActions(t, brokerActions, 0) | |
kubeActions := fakeKubeClient.Actions() | |
assertNumberOfActions(t, kubeActions, 0) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment