Skip to content

Commit f78f862

Browse files
committed
e2e: allow skipping cleanup on failure
1 parent 71551ac commit f78f862

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

webhosting-operator/test/e2e/e2e_suite_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package e2e
1818

1919
import (
2020
"context"
21+
"flag"
2122
"maps"
2223
"testing"
2324
"time"
@@ -42,6 +43,14 @@ import (
4243
webhostingv1alpha1 "github.com/timebertt/kubernetes-controller-sharding/webhosting-operator/pkg/apis/webhosting/v1alpha1"
4344
)
4445

46+
var skipCleanup bool
47+
48+
func TestMain(m *testing.M) {
49+
flag.BoolVar(&skipCleanup, "skip-cleanup", false, "Skip cleanup after test failure")
50+
flag.Parse()
51+
m.Run()
52+
}
53+
4554
func TestE2E(t *testing.T) {
4655
RegisterFailHandler(Fail)
4756
RunSpecs(t, "Webhosting Operator E2E Test Suite")
@@ -112,6 +121,10 @@ var _ = BeforeEach(func(ctx SpecContext) {
112121
log.Info("Created test Namespace", "namespace", namespace.Name)
113122

114123
DeferCleanup(func(ctx SpecContext) {
124+
if ctx.SpecReport().Failed() && skipCleanup {
125+
Skip("Leaving state of test failure because --skip-cleanup is set to true")
126+
}
127+
115128
By("Delete all Websites in test Namespace")
116129
Expect(testClient.DeleteAllOf(ctx, &webhostingv1alpha1.Website{}, client.InNamespace(namespace.Name))).To(Succeed())
117130

@@ -129,6 +142,10 @@ var _ = BeforeEach(func(ctx SpecContext) {
129142
scaleController(ctx, 3)
130143

131144
DeferCleanup(func(ctx SpecContext) {
145+
if ctx.SpecReport().Failed() && skipCleanup {
146+
Skip("Leaving state of test failure because --skip-cleanup is set to true")
147+
}
148+
132149
By("Scaling webhosting-operator")
133150
scaleController(ctx, 3)
134151
}, NodeTimeout(ShortTimeout))

0 commit comments

Comments
 (0)