Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 185 additions & 224 deletions pkg/rhai/e2e/progression_e2e_test.go

Large diffs are not rendered by default.

33 changes: 22 additions & 11 deletions pkg/rhai/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,37 @@ import (
)

var (
k8sClient client.Client
ctx context.Context
testNs *corev1.Namespace
k8sClient client.Client
ctx context.Context
testNs *corev1.Namespace
suiteHasFailed bool
)

func TestRHAIE2E(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)

ginkgo.ReportAfterEach(func(report ginkgo.SpecReport) {
if report.Failed() {
suiteHasFailed = true
}
})

ginkgo.RunSpecs(t, "RHAI Progression Tracking E2E Suite")
}

var _ = ginkgo.BeforeSuite(func() {
ctx = context.Background()

// Get Kubernetes config
cfg := config.GetConfigOrDie()
gomega.ExpectWithOffset(1, cfg).NotTo(gomega.BeNil())

// Add Trainer APIs to scheme
err := trainer.AddToScheme(scheme.Scheme)
gomega.ExpectWithOffset(1, err).NotTo(gomega.HaveOccurred())

// Configure k8s client
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(k8sClient).NotTo(gomega.BeNil())

// Create shared test namespace for all tests
testNs = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "rhai-e2e-progression-",
Expand All @@ -69,9 +73,16 @@ var _ = ginkgo.BeforeSuite(func() {
})

var _ = ginkgo.AfterSuite(func() {
// Cleanup shared test namespace
if testNs != nil {
ginkgo.GinkgoWriter.Printf("Cleaning up test namespace: %s\n", testNs.Name)
gomega.Expect(k8sClient.Delete(ctx, testNs)).To(gomega.Succeed())
// Cleanup namespace only on success; keep for debugging on failure
if testNs != nil && k8sClient != nil {
if !suiteHasFailed {
ginkgo.GinkgoWriter.Printf("✓ All tests passed - cleaning up: %s\n", testNs.Name)
if err := k8sClient.Delete(ctx, testNs); err != nil {
ginkgo.GinkgoWriter.Printf("Warning: Failed to delete namespace %s: %v\n", testNs.Name, err)
}
} else {
ginkgo.GinkgoWriter.Printf("✗ Tests failed - keeping namespace for debugging: %s\n", testNs.Name)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this going to leave a bunch of namespaces in the cluster? How do we clean them up?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also move theese changes to a separate PR so we can easily revert it if necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, it will run all tests serially in the single test namespace

ginkgo.GinkgoWriter.Printf(" To cleanup: oc delete namespace %s\n", testNs.Name)
}
}
})
Loading
Loading