mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-05-06 01:16:44 +00:00
test(e2e): avoiding flaky tests for ingress hostnames collision
This commit is contained in:
@@ -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()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user