Skip to content

Commit

Permalink
Fix asosecret controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Nov 2, 2023
1 parent b662e1f commit c86ade4
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions controllers/asosecret_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func TestASOSecretReconcile(t *testing.T) {
defaultCluster := getASOCluster()
defaultAzureCluster := getASOAzureCluster()
defaultAzureManagedControlPlane := getASOAzureManagedControlPlane()
defaultASOSecret := getASOSecret(defaultAzureCluster)
defaultASOSecret := getASOAzureClusterIdentitySecret()
defaultAzureClusterIdentity := getASOAzureClusterIdentity()
defaultClusterIdentityType := infrav1.ServicePrincipal

cases := map[string]struct {
Expand Down Expand Up @@ -263,8 +264,11 @@ func TestASOSecretReconcile(t *testing.T) {
c.Spec.Paused = true
}),
defaultAzureCluster,
defaultAzureClusterIdentity,
defaultASOSecret,
},
event: "AzureCluster or linked Cluster is marked as paused. Won't reconcile",
asoSecret: defaultASOSecret,
event: "AzureCluster or linked Cluster is marked as paused. Won't reconcile",
},
"should return if azureCluster is not yet available": {
clusterName: defaultAzureCluster.Name,
Expand All @@ -279,6 +283,9 @@ func TestASOSecretReconcile(t *testing.T) {
t.Run(name, func(t *testing.T) {
g := NewWithT(t)
clientBuilder := fake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(tc.objects...).Build()
resultSecret := &corev1.Secret{}
key := client.ObjectKey{Name: tc.asoSecret.Name, Namespace: tc.asoSecret.Namespace}
g.Expect(clientBuilder.Get(context.Background(), key, resultSecret)).To(Succeed())

reconciler := &ASOSecretReconciler{
Client: clientBuilder,
Expand Down Expand Up @@ -306,7 +313,7 @@ func TestASOSecretReconcile(t *testing.T) {
}

if tc.event != "" {
g.Expect(reconciler.Recorder.(*record.FakeRecorder).Events).To(Receive(ContainSubstring(tc.event)))
g.Eventually(reconciler.Recorder.(*record.FakeRecorder).Events).Should(Receive(ContainSubstring(tc.event)))
}
if tc.err != "" {
g.Expect(err).To(MatchError(ContainSubstring(tc.err)))
Expand Down Expand Up @@ -356,6 +363,11 @@ func getASOAzureCluster(changes ...func(*infrav1.AzureCluster)) *infrav1.AzureCl
Spec: infrav1.AzureClusterSpec{
AzureClusterClassSpec: infrav1.AzureClusterClassSpec{
SubscriptionID: "123",
IdentityRef: &corev1.ObjectReference{
Name: "my-azure-cluster-identity",
Namespace: "default",
Kind: "AzureClusterIdentity",
},
},
},
}
Expand Down Expand Up @@ -399,8 +411,13 @@ func getASOAzureClusterIdentity(changes ...func(identity *infrav1.AzureClusterId
Namespace: "default",
},
Spec: infrav1.AzureClusterIdentitySpec{
Type: infrav1.ServicePrincipal,
ClientID: "fooClient",
TenantID: "fooTenant",
ClientSecret: corev1.SecretReference{
Name: "fooSecret",
Namespace: "default",
},
},
}

Expand Down

0 comments on commit c86ade4

Please sign in to comment.