@@ -28,7 +28,6 @@ package controller
2828import (
2929 "context"
3030 _ "embed"
31- "errors"
3231 "fmt"
3332 "slices"
3433
@@ -73,6 +72,7 @@ var _ = Describe("WMS Controller", func() {
7372 Name : ownerInfoResourceName ,
7473 }
7574 ownerInfo := & smoothoperatorv1.OwnerInfo {}
75+ initScripts , mapfileGenerator := true , true
7676
7777 BeforeEach (func () {
7878 pdoknlv3 .SetHost ("localhost" )
@@ -118,6 +118,20 @@ var _ = Describe("WMS Controller", func() {
118118
119119 By ("Cleanup the specific resource instance OwnerInfo" )
120120 Expect (k8sClient .Delete (ctx , ownerInfoResource )).To (Succeed ())
121+
122+ // the testEnv does not do garbage collection (https://book.kubebuilder.io/reference/envtest#testing-considerations)
123+ By ("Cleaning Owned Resources" )
124+ objects , err := getExpectedObjects (ctx , wms , initScripts , mapfileGenerator )
125+ Expect (err ).NotTo (HaveOccurred ())
126+ for _ , o := range objects {
127+ objectKey := client.ObjectKey {
128+ Namespace : o .GetNamespace (),
129+ Name : o .GetName (),
130+ }
131+ err := k8sClient .Get (ctx , objectKey , o )
132+ Expect (err ).NotTo (HaveOccurred ())
133+ Expect (k8sClient .Delete (ctx , o )).To (Succeed ())
134+ }
121135 })
122136
123137 It ("Should successfully reconcile the resource" , func () {
@@ -127,7 +141,8 @@ var _ = Describe("WMS Controller", func() {
127141 reconcileWMS (controllerReconciler , wms , typeNamespacedNameWms )
128142
129143 By ("Waiting for the owned resources to be created" )
130- expectedBareObjects , err := getExpectedObjects (ctx , wms , false )
144+ initScripts = false
145+ expectedBareObjects , err := getExpectedObjects (ctx , wms , initScripts , mapfileGenerator )
131146 Expect (err ).NotTo (HaveOccurred ())
132147
133148 Eventually (func () error {
@@ -146,32 +161,6 @@ var _ = Describe("WMS Controller", func() {
146161
147162 Expect (len (wms .Status .Conditions )).To (BeEquivalentTo (1 ))
148163 Expect (wms .Status .Conditions [0 ].Status ).To (BeEquivalentTo (metav1 .ConditionTrue ))
149-
150- By ("Deleting the WMS" )
151- Expect (k8sClient .Delete (ctx , wms )).To (Succeed ())
152-
153- By ("Reconciling the WMS again" )
154- _ , err = controllerReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : typeNamespacedNameWms })
155- Expect (err ).NotTo (HaveOccurred ())
156-
157- By ("Waiting for the owned resources to be deleted" )
158- Eventually (func () error {
159- for _ , o := range expectedBareObjects {
160- // TODO make finalizers work in the test environment
161- if len (o .GetFinalizers ()) > 0 {
162- continue
163- }
164-
165- err := k8sClient .Get (ctx , types.NamespacedName {Namespace : namespace , Name : o .GetName ()}, o )
166- if err == nil {
167- return errors .New ("expected " + smoothoperatorutils .GetObjectFullName (k8sClient , o ) + " to not be found" )
168- }
169- if ! k8serrors .IsNotFound (err ) {
170- return err
171- }
172- }
173- return nil
174- }, "10s" , "1s" ).Should (Not (HaveOccurred ()))
175164 })
176165
177166 It ("Should successfully reconcile after a change in an owned resource" , func () {
@@ -930,7 +919,7 @@ var _ = Describe("WMS Controller", func() {
930919 Expect (k8sClient .Get (ctx , typeNamespacedNameWms , wms )).To (Succeed ())
931920
932921 controllerReconciler := getWMSReconciler ()
933-
922+ mapfileGenerator = false
934923 By ("Reconciling the WMS and checking the configMap" )
935924 reconcileWMS (controllerReconciler , wms , typeNamespacedNameWms )
936925 deployment := & appsv1.Deployment {}
@@ -986,14 +975,6 @@ func reconcileWMS(r *WMSReconciler, wms *pdoknlv3.WMS, typeNamespacedNameWms typ
986975 // Check it's there
987976 err = k8sClient .Get (ctx , typeNamespacedNameWms , wms )
988977 Expect (err ).NotTo (HaveOccurred ())
989-
990- // Check finalizers
991- finalizerName := getFinalizerName (wms )
992- Expect (wms .Finalizers ).To (ContainElement (finalizerName ))
993-
994- // Reconcile again
995- _ , err = r .Reconcile (ctx , reconcile.Request {NamespacedName : typeNamespacedNameWms })
996- Expect (err ).NotTo (HaveOccurred ())
997978}
998979
999980//go:embed test_manifests/v3_wms.yaml
0 commit comments