Skip to content

Commit 940498f

Browse files
committed
Test to fail reconcile if more than one RSCT CR
1 parent 09e7920 commit 940498f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

internal/controller/rsct_controller_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
var _ = Describe("RSCT Controller", func() {
3434
Context("When reconciling a resource", func() {
35-
const resourceName = "test-resource"
35+
const resourceName = "test-rsct"
3636

3737
ctx := context.Background()
3838

@@ -66,6 +66,7 @@ var _ = Describe("RSCT Controller", func() {
6666
By("Cleanup the specific resource instance RSCT")
6767
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
6868
})
69+
6970
It("should successfully reconcile the resource", func() {
7071
By("Reconciling the created resource")
7172
controllerReconciler := &RSCTReconciler{
@@ -80,5 +81,33 @@ var _ = Describe("RSCT Controller", func() {
8081
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
8182
// Example: If you expect a certain status condition after reconciliation, verify it here.
8283
})
84+
85+
It("should fail to reconcile if more than one RSCT CR exists", func() {
86+
By("Creating a second RSCT custom resource")
87+
secondRSCT := &rsctv1alpha1.RSCT{
88+
ObjectMeta: metav1.ObjectMeta{
89+
Name: "second-rsct",
90+
Namespace: "default",
91+
},
92+
}
93+
Expect(k8sClient.Create(ctx, secondRSCT)).To(Succeed())
94+
95+
controllerReconciler := &RSCTReconciler{
96+
Client: k8sClient,
97+
Scheme: k8sClient.Scheme(),
98+
}
99+
100+
_, err := controllerReconciler.Reconcile(ctx, reconcile.Request{
101+
NamespacedName: types.NamespacedName{
102+
Name: "second-rsct",
103+
Namespace: "default",
104+
},
105+
})
106+
Expect(err).To(HaveOccurred())
107+
Expect(err.Error()).To(ContainSubstring("only one RSCT custom resource is allowed"))
108+
109+
// Cleanup the second RSCT
110+
Expect(k8sClient.Delete(ctx, secondRSCT)).To(Succeed())
111+
})
83112
})
84113
})

0 commit comments

Comments
 (0)