From de2793a635aaad755042384a8ad5de30febf9805 Mon Sep 17 00:00:00 2001 From: Dheeraj Date: Wed, 4 Dec 2024 17:12:38 +0530 Subject: [PATCH] test(STONEINTG-883): add unit test coverage Signed-off-by: Dheeraj --- .../snapshot/snapshot_adapter_test.go | 1 - .../snapshot/snapshot_controller_test.go | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/controller/snapshot/snapshot_adapter_test.go b/internal/controller/snapshot/snapshot_adapter_test.go index d28aa5919..6c44afcef 100644 --- a/internal/controller/snapshot/snapshot_adapter_test.go +++ b/internal/controller/snapshot/snapshot_adapter_test.go @@ -1925,7 +1925,6 @@ var _ = Describe("Snapshot Adapter", Ordered, func() { result, err := adapter.EnsureOverrideSnapshotValid() Expect(result.CancelRequest).To(BeFalse()) Expect(result.RequeueRequest).To(BeFalse()) - Expect(controllerutil.HasControllerReference(hasInvalidOverrideSnapshot)).To(BeTrue()) Expect(buf.String()).Should(ContainSubstring("Snapshot has been marked as invalid")) Expect(err).ToNot(HaveOccurred()) diff --git a/internal/controller/snapshot/snapshot_controller_test.go b/internal/controller/snapshot/snapshot_controller_test.go index 7e0f257e8..de5e5a716 100644 --- a/internal/controller/snapshot/snapshot_controller_test.go +++ b/internal/controller/snapshot/snapshot_controller_test.go @@ -178,6 +178,30 @@ var _ = Describe("SnapshotController", func() { Expect(err).To(BeNil()) }) + It("can add the Application as a Controller OwnerReference on Snapshot", func() { + Expect(hasSnapshot.ObjectMeta.OwnerReferences).To(BeNil()) + + req := ctrl.Request{ + NamespacedName: types.NamespacedName{ + Name: hasSnapshot.Name, + Namespace: "default", + }, + } + result, err := snapshotReconciler.Reconcile(ctx, req) + Expect(reflect.TypeOf(result)).To(Equal(reflect.TypeOf(reconcile.Result{}))) + Expect(err).ToNot(HaveOccurred()) + + Eventually(func() bool { + err := k8sClient.Get(ctx, types.NamespacedName{ + Namespace: hasSnapshot.Namespace, + Name: hasSnapshot.Name, + }, hasSnapshot) + return err == nil + }).Should(BeTrue()) + Expect(hasSnapshot.ObjectMeta.OwnerReferences).ToNot(BeNil()) + Expect(hasSnapshot.ObjectMeta.GetOwnerReferences()[0].Name).To(Equal(hasApp.Name)) + }) + It("Does not return an error if the component cannot be found", func() { err := k8sClient.Delete(ctx, hasComp) Eventually(func() bool {