diff --git a/e2e/tenant_ingress_hostnames_collision_allowed_test.go b/e2e/tenant_ingress_hostnames_collision_allowed_test.go index c5a2c826b..38206bcb5 100644 --- a/e2e/tenant_ingress_hostnames_collision_allowed_test.go +++ b/e2e/tenant_ingress_hostnames_collision_allowed_test.go @@ -14,7 +14,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" capsulev1alpha1 "github.com/clastix/capsule/api/v1alpha1" - capsulev1beta1 "github.com/clastix/capsule/api/v1beta1" ) @@ -50,8 +49,10 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr }) It("should block creation if contains collided Ingress hostnames", func() { + var cleanupFuncs []func() + for i, h := range tnt.Spec.IngressHostnames.Exact { - tnt2 := &capsulev1beta1.Tenant{ + duplicated := &capsulev1beta1.Tenant{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-%d", tnt.GetName(), i), }, @@ -65,19 +66,32 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr }, }, } + EventuallyCreation(func() error { - return k8sClient.Create(context.TODO(), tnt2) + return k8sClient.Create(context.TODO(), duplicated) }).ShouldNot(Succeed()) + + cleanupFuncs = append(cleanupFuncs, func() { + duplicatedTnt := *duplicated + + _ = k8sClient.Delete(context.TODO(), &duplicatedTnt) + }) + } + + for _, fn := range cleanupFuncs { + fn() } }) It("should not block creation if contains collided Ingress hostnames", func() { + var cleanupFuncs []func() + ModifyCapsuleConfigurationOpts(func(configuration *capsulev1alpha1.CapsuleConfiguration) { configuration.Spec.AllowTenantIngressHostnamesCollision = true }) for i, h := range tnt.Spec.IngressHostnames.Exact { - tnt2 := &capsulev1beta1.Tenant{ + duplicated := &capsulev1beta1.Tenant{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-%d", tnt.GetName(), i), }, @@ -91,10 +105,20 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr }, }, } + EventuallyCreation(func() error { - return k8sClient.Create(context.TODO(), tnt2) + return k8sClient.Create(context.TODO(), duplicated) }).Should(Succeed()) - _ = k8sClient.Delete(context.TODO(), tnt2) + + cleanupFuncs = append(cleanupFuncs, func() { + duplicatedTnt := *duplicated + + _ = k8sClient.Delete(context.TODO(), &duplicatedTnt) + }) + } + + for _, fn := range cleanupFuncs { + fn() } }) }) diff --git a/e2e/tenant_ingress_hostnames_collision_blocked_test.go b/e2e/tenant_ingress_hostnames_collision_blocked_test.go index e7a19bb98..16ad5ec15 100644 --- a/e2e/tenant_ingress_hostnames_collision_blocked_test.go +++ b/e2e/tenant_ingress_hostnames_collision_blocked_test.go @@ -43,8 +43,10 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr }) It("should block creation if contains collided Ingress hostnames", func() { + var cleanupFuncs []func() + for i, h := range tnt.Spec.IngressHostnames.Exact { - tnt2 := &capsulev1beta1.Tenant{ + duplicated := &capsulev1beta1.Tenant{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-%d", tnt.GetName(), i), }, @@ -58,9 +60,20 @@ var _ = Describe("when a second Tenant contains an already declared allowed Ingr }, }, } + EventuallyCreation(func() error { - return k8sClient.Create(context.TODO(), tnt2) + return k8sClient.Create(context.TODO(), duplicated) }).ShouldNot(Succeed()) + + cleanupFuncs = append(cleanupFuncs, func() { + duplicatedTenant := *duplicated + + k8sClient.Delete(context.TODO(), &duplicatedTenant) + }) + } + + for _, fn := range cleanupFuncs { + fn() } }) })