Skip to content

Commit 5fd05b1

Browse files
committed
test for managedclusteradopt controller
Signed-off-by: Troy Connor <[email protected]>
1 parent b32f0c6 commit 5fd05b1

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

Diff for: controllers/managedclusteradopt_controller_test.go

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
asocontainerservicev1 "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20231001"
24+
asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
25+
"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
26+
. "github.com/onsi/gomega"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
"k8s.io/apimachinery/pkg/runtime"
29+
"k8s.io/apimachinery/pkg/types"
30+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
31+
ctrl "sigs.k8s.io/controller-runtime"
32+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
33+
34+
"sigs.k8s.io/cluster-api-provider-azure/api/v1alpha1"
35+
)
36+
37+
func TestManagedClusterAdoptReconcile(t *testing.T) {
38+
ctx := context.Background()
39+
g := NewWithT(t)
40+
req := ctrl.Request{
41+
NamespacedName: types.NamespacedName{
42+
Name: "fake-mc",
43+
Namespace: "fake-ns",
44+
},
45+
}
46+
managedCluster := &asocontainerservicev1.ManagedCluster{
47+
ObjectMeta: metav1.ObjectMeta{
48+
Name: "fake-mc",
49+
Namespace: "fake-ns",
50+
Annotations: map[string]string{
51+
adoptAnnotation: adoptAnnotationValue,
52+
},
53+
},
54+
Spec: asocontainerservicev1.ManagedCluster_Spec{
55+
Owner: &genruntime.KnownResourceReference{
56+
Name: "fake-mc",
57+
},
58+
},
59+
}
60+
61+
rg := &asoresourcesv1.ResourceGroup{
62+
ObjectMeta: metav1.ObjectMeta{
63+
Name: "fake-mc",
64+
Namespace: "fake-ns",
65+
},
66+
}
67+
68+
s := runtime.NewScheme()
69+
err := asocontainerservicev1.AddToScheme(s)
70+
g.Expect(err).ToNot(HaveOccurred())
71+
err = clusterv1.AddToScheme(s)
72+
g.Expect(err).ToNot(HaveOccurred())
73+
err = asoresourcesv1.AddToScheme(s)
74+
g.Expect(err).ToNot(HaveOccurred())
75+
err = v1alpha1.AddToScheme(s)
76+
g.Expect(err).ToNot(HaveOccurred())
77+
client := fake.NewClientBuilder().WithScheme(s).WithObjects(managedCluster, rg).Build()
78+
rec := ManagedClusterAdoptReconciler{
79+
Client: client,
80+
}
81+
_, err = rec.Reconcile(ctx, req)
82+
g.Expect(err).ToNot(HaveOccurred())
83+
mcp := &v1alpha1.AzureASOManagedControlPlane{}
84+
err = rec.Get(ctx, types.NamespacedName{Name: managedCluster.Name, Namespace: managedCluster.Namespace}, mcp)
85+
g.Expect(err).ToNot(HaveOccurred())
86+
asomc := &v1alpha1.AzureASOManagedCluster{}
87+
err = rec.Get(ctx, types.NamespacedName{Name: managedCluster.Name, Namespace: managedCluster.Namespace}, asomc)
88+
g.Expect(err).ToNot(HaveOccurred())
89+
}

0 commit comments

Comments
 (0)