@@ -32,7 +32,7 @@ import (
32
32
33
33
var _ = Describe ("RSCT Controller" , func () {
34
34
Context ("When reconciling a resource" , func () {
35
- const resourceName = "test-resource "
35
+ const resourceName = "test-rsct "
36
36
37
37
ctx := context .Background ()
38
38
@@ -66,6 +66,7 @@ var _ = Describe("RSCT Controller", func() {
66
66
By ("Cleanup the specific resource instance RSCT" )
67
67
Expect (k8sClient .Delete (ctx , resource )).To (Succeed ())
68
68
})
69
+
69
70
It ("should successfully reconcile the resource" , func () {
70
71
By ("Reconciling the created resource" )
71
72
controllerReconciler := & RSCTReconciler {
@@ -80,5 +81,33 @@ var _ = Describe("RSCT Controller", func() {
80
81
// TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
81
82
// Example: If you expect a certain status condition after reconciliation, verify it here.
82
83
})
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
+ })
83
112
})
84
113
})
0 commit comments