@@ -30,6 +30,8 @@ import (
3030 "os"
3131 "testing"
3232
33+ "github.com/pdok/smooth-operator/model"
34+
3335 "github.com/google/go-cmp/cmp"
3436 "github.com/pdok/atom-generator/feeds"
3537 apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -42,6 +44,7 @@ import (
4244 . "github.com/onsi/ginkgo/v2" //nolint:revive // ginkgo bdd
4345 . "github.com/onsi/gomega" //nolint:revive // ginkgo bdd
4446 smoothoperatorv1 "github.com/pdok/smooth-operator/api/v1"
47+ smoothoperatorutils "github.com/pdok/smooth-operator/pkg/util"
4548 smoothoperatorvalidation "github.com/pdok/smooth-operator/pkg/validation"
4649 "github.com/pkg/errors"
4750 "github.com/stretchr/testify/require"
@@ -201,6 +204,40 @@ var _ = Describe("Testing Atom Controller", func() {
201204 }, "10s" , "1s" ).Should (BeTrue ())
202205 })
203206
207+ It ("Respects the TTL of the WMS" , func () {
208+ By ("Creating a new resource for the Kind WMS" )
209+ controllerReconciler := & AtomReconciler {
210+ Client : k8sClient ,
211+ Scheme : k8sClient .Scheme (),
212+ AtomGeneratorImage : testImageName1 ,
213+ LighttpdImage : testImageName2 ,
214+ }
215+
216+ ttlName := testAtom .GetName () + "-ttl"
217+ ttlAtom := testAtom .DeepCopy ()
218+ ttlAtom .Name = ttlName
219+ ttlAtom .Spec .Lifecycle = & model.Lifecycle {TTLInDays : smoothoperatorutils .Pointer (int32 (0 ))}
220+ objectKeyTTLAtom := client .ObjectKeyFromObject (ttlAtom )
221+
222+ err := k8sClient .Get (ctx , objectKeyTTLAtom , ttlAtom )
223+ Expect (client .IgnoreNotFound (err )).To (Not (HaveOccurred ()))
224+ if err != nil && apierrors .IsNotFound (err ) {
225+ Expect (k8sClient .Create (ctx , ttlAtom )).To (Succeed ())
226+ }
227+
228+ // Reconcile
229+ _ , err = controllerReconciler .Reconcile (ctx , reconcile.Request {NamespacedName : objectKeyTTLAtom })
230+ Expect (err ).To (Not (HaveOccurred ()))
231+
232+ // Check the WMS cannot be found anymore
233+ Eventually (func () bool {
234+ err = k8sClient .Get (ctx , objectKeyTTLAtom , ttlAtom )
235+ return apierrors .IsNotFound (err )
236+ }, "10s" , "1s" ).Should (BeTrue ())
237+
238+ // Not checking owned resources because the test env does not do garbage collection
239+ })
240+
204241 It ("Should cleanup the cluster" , func () {
205242 err := k8sClient .Get (ctx , objectKeyAtom , clusterAtom )
206243 Expect (client .IgnoreNotFound (err )).NotTo (HaveOccurred ())
0 commit comments