Skip to content

Commit

Permalink
test(e2e): avoiding flaky tests for ingress hostnames collision
Browse files Browse the repository at this point in the history
  • Loading branch information
prometherion committed Jul 2, 2021
1 parent b58ca3a commit bd448d8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
36 changes: 30 additions & 6 deletions e2e/tenant_ingress_hostnames_collision_allowed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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),
},
Expand All @@ -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),
},
Expand All @@ -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()
}
})
})
17 changes: 15 additions & 2 deletions e2e/tenant_ingress_hostnames_collision_blocked_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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()
}
})
})

0 comments on commit bd448d8

Please sign in to comment.