Fix test cleanup to handle missing resources gracefully
Make AfterEach cleanup blocks more robust by only attempting to delete resources if they exist. This prevents test failures when resources have already been deleted or don't exist. Changes: - Check if resource exists before attempting deletion - Only call Delete if Get succeeds (err == nil) - Applied to all 5 controller test files This fixes intermittent test failures in GitHub Actions where AfterEach was failing with resource not found errors.
This commit is contained in:
@@ -61,10 +61,10 @@ var _ = Describe("FirewallGroup Controller", func() {
|
|||||||
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
||||||
resource := &unifiv1beta1.FirewallGroup{}
|
resource := &unifiv1beta1.FirewallGroup{}
|
||||||
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
if err == nil {
|
||||||
|
By("Cleanup the specific resource instance FirewallGroup")
|
||||||
By("Cleanup the specific resource instance FirewallGroup")
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
}
|
||||||
})
|
})
|
||||||
It("should successfully reconcile the resource", func() {
|
It("should successfully reconcile the resource", func() {
|
||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ var _ = Describe("FirewallPolicy Controller", func() {
|
|||||||
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
||||||
resource := &unifiv1beta1.FirewallPolicy{}
|
resource := &unifiv1beta1.FirewallPolicy{}
|
||||||
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
if err == nil {
|
||||||
|
By("Cleanup the specific resource instance FirewallPolicy")
|
||||||
By("Cleanup the specific resource instance FirewallPolicy")
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
}
|
||||||
})
|
})
|
||||||
It("should successfully reconcile the resource", func() {
|
It("should successfully reconcile the resource", func() {
|
||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ var _ = Describe("FirewallZone Controller", func() {
|
|||||||
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
||||||
resource := &unifiv1beta1.FirewallZone{}
|
resource := &unifiv1beta1.FirewallZone{}
|
||||||
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
if err == nil {
|
||||||
|
By("Cleanup the specific resource instance FirewallZone")
|
||||||
By("Cleanup the specific resource instance FirewallZone")
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
}
|
||||||
})
|
})
|
||||||
It("should successfully reconcile the resource", func() {
|
It("should successfully reconcile the resource", func() {
|
||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ var _ = Describe("Networkconfiguration Controller", func() {
|
|||||||
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
||||||
resource := &unifiv1beta1.Networkconfiguration{}
|
resource := &unifiv1beta1.Networkconfiguration{}
|
||||||
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
if err == nil {
|
||||||
|
By("Cleanup the specific resource instance Networkconfiguration")
|
||||||
By("Cleanup the specific resource instance Networkconfiguration")
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
}
|
||||||
})
|
})
|
||||||
It("should successfully reconcile the resource", func() {
|
It("should successfully reconcile the resource", func() {
|
||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ var _ = Describe("PortForward Controller", func() {
|
|||||||
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
// TODO(user): Cleanup logic after each test, like removing the resource instance.
|
||||||
resource := &unifiv1beta1.PortForward{}
|
resource := &unifiv1beta1.PortForward{}
|
||||||
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
err := k8sClient.Get(ctx, typeNamespacedName, resource)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
if err == nil {
|
||||||
|
By("Cleanup the specific resource instance PortForward")
|
||||||
By("Cleanup the specific resource instance PortForward")
|
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
||||||
Expect(k8sClient.Delete(ctx, resource)).To(Succeed())
|
}
|
||||||
})
|
})
|
||||||
It("should successfully reconcile the resource", func() {
|
It("should successfully reconcile the resource", func() {
|
||||||
By("Reconciling the created resource")
|
By("Reconciling the created resource")
|
||||||
|
|||||||
Reference in New Issue
Block a user