@@ -25,6 +25,7 @@ import (
2525 "k8s.io/apimachinery/pkg/types"
2626 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2727
28+ appsv1 "k8s.io/api/apps/v1"
2829 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2930
3031 uiv1alpha1 "github.com/scality/ui-operator/api/v1alpha1"
@@ -33,12 +34,14 @@ import (
3334var _ = Describe ("ScalityUIComponent Controller" , func () {
3435 Context ("When reconciling a resource" , func () {
3536 const resourceName = "test-resource"
37+ const testNamespace = "default"
38+ const testImage = "scality/ui-component:latest"
3639
3740 ctx := context .Background ()
3841
3942 typeNamespacedName := types.NamespacedName {
4043 Name : resourceName ,
41- Namespace : "default" , // TODO(user):Modify as needed
44+ Namespace : testNamespace ,
4245 }
4346 scalityuicomponent := & uiv1alpha1.ScalityUIComponent {}
4447
@@ -49,23 +52,25 @@ var _ = Describe("ScalityUIComponent Controller", func() {
4952 resource := & uiv1alpha1.ScalityUIComponent {
5053 ObjectMeta : metav1.ObjectMeta {
5154 Name : resourceName ,
52- Namespace : "default" ,
55+ Namespace : testNamespace ,
56+ },
57+ Spec : uiv1alpha1.ScalityUIComponentSpec {
58+ Image : testImage ,
5359 },
54- // TODO(user): Specify other spec details if needed.
5560 }
5661 Expect (k8sClient .Create (ctx , resource )).To (Succeed ())
5762 }
5863 })
5964
6065 AfterEach (func () {
61- // TODO(user): Cleanup logic after each test, like removing the resource instance.
6266 resource := & uiv1alpha1.ScalityUIComponent {}
6367 err := k8sClient .Get (ctx , typeNamespacedName , resource )
6468 Expect (err ).NotTo (HaveOccurred ())
6569
6670 By ("Cleanup the specific resource instance ScalityUIComponent" )
6771 Expect (k8sClient .Delete (ctx , resource )).To (Succeed ())
6872 })
73+
6974 It ("should successfully reconcile the resource" , func () {
7075 By ("Reconciling the created resource" )
7176 controllerReconciler := & ScalityUIComponentReconciler {
@@ -77,8 +82,18 @@ var _ = Describe("ScalityUIComponent Controller", func() {
7782 NamespacedName : typeNamespacedName ,
7883 })
7984 Expect (err ).NotTo (HaveOccurred ())
80- // TODO(user): Add more specific assertions depending on your controller's reconciliation logic.
81- // Example: If you expect a certain status condition after reconciliation, verify it here.
85+
86+ By ("Checking if Deployment was created with correct specifications" )
87+ deployment := & appsv1.Deployment {}
88+ err = k8sClient .Get (ctx , typeNamespacedName , deployment )
89+ Expect (err ).NotTo (HaveOccurred ())
90+
91+ Expect (deployment .Spec .Template .Spec .Containers ).To (HaveLen (1 ))
92+ Expect (deployment .Spec .Template .Spec .Containers [0 ].Image ).To (Equal (testImage ))
93+ Expect (deployment .Spec .Template .Spec .Containers [0 ].Name ).To (Equal (resourceName ))
94+
95+ Expect (deployment .Spec .Template .ObjectMeta .Labels ["app" ]).To (Equal (resourceName ))
96+ Expect (deployment .Spec .Selector .MatchLabels ["app" ]).To (Equal (resourceName ))
8297 })
8398 })
8499})
0 commit comments