Skip to content

Commit

Permalink
Merge pull request #657 from johnbieren/fixtest
Browse files Browse the repository at this point in the history
test: fix owner reference test in releasePlan adapter
  • Loading branch information
johnbieren authored Jan 24, 2025
2 parents c49d620 + 8e6c6ce commit 66dc68b
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions controllers/releaseplan/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,38 +98,17 @@ var _ = Describe("ReleasePlan adapter", Ordered, func() {
result, err := adapter.EnsureOwnerReferenceIsSet()
Expect(!result.RequeueRequest && !result.CancelRequest).To(BeTrue())
Expect(err).NotTo(HaveOccurred())
Expect(adapter.releasePlan.OwnerReferences).To(HaveLen(1))
})

It("should delete the releasePlan if the owner is deleted", func() {
newApplication := &applicationapiv1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "application-",
Namespace: "default",
},
boolTrue := true
expectedOwnerReference := metav1.OwnerReference{
Kind: "Application",
APIVersion: "appstudio.redhat.com/v1alpha1",
UID: application.UID,
Name: application.Name,
Controller: &boolTrue,
BlockOwnerDeletion: &boolTrue,
}
Expect(k8sClient.Create(ctx, newApplication)).To(Succeed())

adapter.ctx = toolkit.GetMockedContext(ctx, []toolkit.MockData{
{
ContextKey: loader.ApplicationContextKey,
Resource: newApplication,
},
})

Expect(adapter.releasePlan.OwnerReferences).To(HaveLen(0))
result, err := adapter.EnsureOwnerReferenceIsSet()
Expect(!result.RequeueRequest && !result.CancelRequest).To(BeTrue())
Expect(err).NotTo(HaveOccurred())
Expect(adapter.releasePlan.OwnerReferences).To(HaveLen(1))

Expect(k8sClient.Delete(ctx, newApplication)).To(Succeed())
_, err = adapter.loader.GetReleasePlan(ctx, k8sClient, &v1alpha1.Release{
Spec: v1alpha1.ReleaseSpec{
ReleasePlan: adapter.releasePlan.Name,
},
})
Expect(err).To(HaveOccurred())
Expect(adapter.releasePlan.ObjectMeta.OwnerReferences).To(ContainElement(expectedOwnerReference))
})
})

Expand Down

0 comments on commit 66dc68b

Please sign in to comment.