Skip to content

Commit

Permalink
test(STONEINTG-883): add unit test coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Dheeraj<[email protected]>
  • Loading branch information
dheerajodha committed Dec 6, 2024
1 parent 8273098 commit de2793a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion internal/controller/snapshot/snapshot_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
24 changes: 24 additions & 0 deletions internal/controller/snapshot/snapshot_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit de2793a

Please sign in to comment.