Skip to content

Commit dfe2dec

Browse files
committed
add test coverage for agentpooladopt controller
Signed-off-by: Troy Connor <[email protected]>
1 parent eb42392 commit dfe2dec

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package controllers
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
8+
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
9+
. "github.com/onsi/gomega"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/types"
12+
"k8s.io/utils/ptr"
13+
infrav1alpha "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha1"
14+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
15+
ctrl "sigs.k8s.io/controller-runtime"
16+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
17+
)
18+
19+
func TestAgentPoolAdoptController(t *testing.T) {
20+
g := NewWithT(t)
21+
req := ctrl.Request{NamespacedName: types.NamespacedName{Name: "fake-agent-pool", Namespace: "fake-ns"}}
22+
ctx := context.Background()
23+
scheme, err := newScheme()
24+
g.Expect(err).To(BeNil())
25+
26+
agentPool := &asocontainerservicev1.ManagedClustersAgentPool{
27+
ObjectMeta: metav1.ObjectMeta{
28+
Name: "fake-agent-pool",
29+
Namespace: "fake-ns",
30+
Annotations: map[string]string{
31+
adoptAnnotation: adoptAnnotationValue,
32+
},
33+
OwnerReferences: []metav1.OwnerReference{
34+
{
35+
Kind: infrav1alpha.AzureASOManagedMachinePoolKind,
36+
APIVersion: infrav1alpha.GroupVersion.Identifier(),
37+
},
38+
},
39+
},
40+
Spec: asocontainerservicev1.ManagedClustersAgentPool_Spec{
41+
Count: ptr.To(1),
42+
Owner: &genruntime.KnownResourceReference{
43+
Name: "fake-managed-cluster",
44+
},
45+
},
46+
}
47+
mc := &asocontainerservicev1.ManagedCluster{
48+
ObjectMeta: metav1.ObjectMeta{
49+
Name: "fake-managed-cluster",
50+
Namespace: "fake-ns",
51+
OwnerReferences: []metav1.OwnerReference{
52+
{
53+
Kind: infrav1alpha.AzureASOManagedControlPlaneKind,
54+
APIVersion: infrav1alpha.GroupVersion.Identifier(),
55+
Name: "fake-managed-cluster",
56+
},
57+
},
58+
},
59+
}
60+
asoManagedControlPlane := &infrav1alpha.AzureASOManagedControlPlane{
61+
ObjectMeta: metav1.ObjectMeta{
62+
Name: "fake-managed-cluster",
63+
Namespace: "fake-ns",
64+
Labels: map[string]string{
65+
clusterv1.ClusterNameLabel: "cluster-name",
66+
},
67+
},
68+
}
69+
70+
asocontainerservicev1.AddToScheme(scheme)
71+
infrav1alpha.AddToScheme(scheme)
72+
client := fake.NewClientBuilder().WithScheme(scheme).WithObjects(agentPool, mc, asoManagedControlPlane).WithStatusSubresource(mc, agentPool, asoManagedControlPlane).Build()
73+
aprec := &AgentPoolAdoptReconciler{
74+
Client: client,
75+
}
76+
_, err = aprec.Reconcile(ctx, req)
77+
g.Expect(err).To(BeNil())
78+
}

controllers/azurejson_machinepool_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func TestAzureJSONPoolReconcilerUserAssignedIdentities(t *testing.T) {
382382
CredentialCache: azure.NewCredentialCache(),
383383
}
384384
id := "azure:///subscriptions/123/resourceGroups/test-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/fake-provider-id"
385-
getClient = func(auth azure.Authorizer) (identities.Client, error) {
385+
getClient = func(_ azure.Authorizer) (identities.Client, error) {
386386
mockClient := mock_identities.NewMockClient(ctrlr)
387387
mockClient.EXPECT().GetClientID(gomock.Any(), gomock.Any()).Return(id, nil)
388388
return mockClient, nil

0 commit comments

Comments
 (0)