Skip to content

Commit

Permalink
tests: delete namespace until not found
Browse files Browse the repository at this point in the history
  • Loading branch information
guicassolato committed Apr 24, 2024
1 parent bed695f commit 8a3b825
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,23 @@ func CreateNamespace(namespace *string) {
}

func DeleteNamespaceCallbackWithContext(ctx context.Context, namespace *string) {
desiredTestNamespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: *namespace}}
Eventually(func(g Gomega) {
err := k8sClient.Delete(ctx, desiredTestNamespace, client.PropagationPolicy(metav1.DeletePropagationForeground))
g.Expect(err).ToNot(BeNil())
g.Expect(apierrors.IsNotFound(err)).To(BeTrue())
}).WithContext(ctx).Should(Succeed())

obj := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: *namespace}}
Eventually(func() bool {
testClient().Delete(ctx, obj, client.PropagationPolicy(metav1.DeletePropagationForeground))
existingNamespace := &v1.Namespace{}
err := testClient().Get(ctx, types.NamespacedName{Name: *namespace}, existingNamespace)
return err != nil && apierrors.IsNotFound(err)
}).WithContext(ctx).Should(BeTrue())
}

func DeleteNamespaceCallback(namespace *string) func() {
obj := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: *namespace}}
return func() {
desiredTestNamespace := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: *namespace}}
err := testClient().Delete(context.Background(), desiredTestNamespace, client.PropagationPolicy(metav1.DeletePropagationForeground))

Expect(err).ToNot(HaveOccurred())

existingNamespace := &v1.Namespace{}
Eventually(func() bool {
testClient().Delete(context.Background(), obj, client.PropagationPolicy(metav1.DeletePropagationForeground))
existingNamespace := &v1.Namespace{}
err := testClient().Get(context.Background(), types.NamespacedName{Name: *namespace}, existingNamespace)
if err != nil && apierrors.IsNotFound(err) {
return true
}
return false
return err != nil && apierrors.IsNotFound(err)
}, 3*time.Minute, 2*time.Second).Should(BeTrue())
}
}
Expand Down

0 comments on commit 8a3b825

Please sign in to comment.