Skip to content

Commit

Permalink
fix(test): fix some update calls.
Browse files Browse the repository at this point in the history
Some tests needs to update resources in order to properly test resource
deletion. However, this needs to happen inside an Eventually call to
ensure that the test will update the latest version of the resource.
Otherwise, it will fail.

Signed-off-by: José Guilherme Vanz <jguilhermevanz@suse.com>
  • Loading branch information
jvanz committed May 7, 2024
1 parent c97fc60 commit 5563f3d
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions controllers/policyserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ var _ = Describe("PolicyServer controller", func() {
It("policy server resources should be gone after it being deleted", func() {
// It's necessary remove the test finalizer to make the
// Kubernetes garbage collector to remove the resources
policyServer, err := getTestPolicyServer(policyServerName)
Expect(err).Should(Succeed())
controllerutil.RemoveFinalizer(policyServer, IntegrationTestsFinalizer)
err = reconciler.Client.Update(ctx, policyServer)
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
policyServer, err := getTestPolicyServer(policyServerName)
if err != nil {
return err
}
controllerutil.RemoveFinalizer(policyServer, IntegrationTestsFinalizer)
return reconciler.Client.Update(ctx, policyServer)
}).Should(Succeed())

Expect(
k8sClient.Delete(ctx, policyServerFactory(policyServerName)),
Expand Down Expand Up @@ -154,12 +157,14 @@ var _ = Describe("PolicyServer controller", func() {
})

It(fmt.Sprintf("should get its %q finalizer removed", constants.KubewardenFinalizer), func() {
policy, err := getTestClusterAdmissionPolicy(policyName)
Expect(err).ToNot(HaveOccurred())

controllerutil.RemoveFinalizer(policy, IntegrationTestsFinalizer)
err = reconciler.Client.Update(ctx, policy)
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
policy, err := getTestClusterAdmissionPolicy(policyName)
if err != nil {
return err
}
controllerutil.RemoveFinalizer(policy, IntegrationTestsFinalizer)
return reconciler.Client.Update(ctx, policy)
}).Should(Succeed())

Expect(
k8sClient.Delete(ctx, policyServerFactory(policyServerName)),
Expand Down

0 comments on commit 5563f3d

Please sign in to comment.