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 8, 2024
1 parent da07b27 commit f80c28b
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 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 Expand Up @@ -343,17 +348,10 @@ var _ = Describe("PolicyServer controller", func() {
policies, err := json.Marshal(policiesMap)
Expect(err).ToNot(HaveOccurred())

Eventually(func() error {
_, err := getTestClusterAdmissionPolicy(policyName)
return err
}, timeout, pollInterval).Should(Succeed())
Eventually(func() error {
_, err := getTestPolicyServerConfigMap(policyServerName)
return err
}, timeout, pollInterval).Should(Succeed())
configMap, err := getTestPolicyServerConfigMap(policyServerName)
Expect(err).ToNot(HaveOccurred())
Expect(configMap).To(PointTo(MatchFields(IgnoreExtras, Fields{
Eventually(func() *corev1.ConfigMap {
configMap, _ := getTestPolicyServerConfigMap(policyServerName)
return configMap
}, timeout, pollInterval).Should(PointTo(MatchFields(IgnoreExtras, Fields{
"Data": MatchAllKeys(Keys{
constants.PolicyServerConfigPoliciesEntry: MatchJSON(policies),
constants.PolicyServerConfigSourcesEntry: Equal("{}"),
Expand Down

0 comments on commit f80c28b

Please sign in to comment.