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 23, 2024
1 parent bed695f commit 3521192
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions controllers/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,24 @@ 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))
testClient().Delete(ctx, desiredTestNamespace, client.PropagationPolicy(metav1.DeletePropagationForeground))
existingNamespace := &v1.Namespace{}
err := testClient().Get(ctx, types.NamespacedName{Name: *namespace}, existingNamespace)
g.Expect(err).ToNot(BeNil())
g.Expect(apierrors.IsNotFound(err)).To(BeTrue())
}).WithContext(ctx).Should(Succeed())

}

func DeleteNamespaceCallback(namespace *string) func() {
desiredTestNamespace := &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 {
Eventually(func(g Gomega) {
testClient().Delete(context.Background(), desiredTestNamespace, 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
g.Expect(err).ToNot(BeNil())
g.Expect(apierrors.IsNotFound(err)).To(BeTrue())
}, 3*time.Minute, 2*time.Second).Should(BeTrue())
}
}
Expand Down

0 comments on commit 3521192

Please sign in to comment.