From 7054bb0ca5ab0e804e94115762e8ba10ec3fa862 Mon Sep 17 00:00:00 2001 From: Alan Amoyel Date: Mon, 3 Jun 2024 11:16:18 +0200 Subject: [PATCH] fix: avoid random failures on tests --- internal/controllers/ipcidr_controller_test.go | 2 ++ internal/controllers/ipclaim_controller_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/controllers/ipcidr_controller_test.go b/internal/controllers/ipcidr_controller_test.go index 027858e..426f842 100644 --- a/internal/controllers/ipcidr_controller_test.go +++ b/internal/controllers/ipcidr_controller_test.go @@ -61,6 +61,8 @@ var _ = Describe("IPCidr controller", func() { } return createdIpCidr.Status.Registered, nil }, timeout, interval).Should(Equal(false)) + By("Deleting the bad cidr") + Expect(k8sClient.Delete(ctx, createdIpCidr)).Should(Succeed()) By("Creating a new IPCidr that overlap a created one") ipCidrName = "overlap-cidr" diff --git a/internal/controllers/ipclaim_controller_test.go b/internal/controllers/ipclaim_controller_test.go index ad5292e..3efb85e 100644 --- a/internal/controllers/ipclaim_controller_test.go +++ b/internal/controllers/ipclaim_controller_test.go @@ -21,20 +21,20 @@ var _ = Describe("IPClaim controller", func() { ipcidr := getIpCidr(ipClaimCidr, "172.16.0.0/16") Expect(k8sClient.Create(ctx, ipcidr)).Should(Succeed()) - By("Creating a new IPClaim with bad prefix") + By("Creating a new IPClaim to claim an IP addr") ipClaimName := "test-ip" ipclaim := getIPClaim("IP", false, ipClaimName, ipClaimCidr) Expect(k8sClient.Create(ctx, ipclaim)).Should(Succeed()) By("Checking if the 'registered' status field is set to 'true'") ipClaimLookupKey := types.NamespacedName{Name: ipClaimName} - claimedIP := &ipamv1alpha1.IPClaim{} + ipClaimCR := &ipamv1alpha1.IPClaim{} Eventually(func() (bool, error) { - err := k8sClient.Get(ctx, ipClaimLookupKey, claimedIP) + err := k8sClient.Get(ctx, ipClaimLookupKey, ipClaimCR) if err != nil { return false, err } - return claimedIP.Status.Registered, nil + return ipClaimCR.Status.Registered, nil }, timeout, interval).Should(Equal(true)) }) })