Skip to content
Merged
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
7 changes: 5 additions & 2 deletions tests/e2e/cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ var _ = Describe("virtwork cleanup", Label("slow"), func() {
})

AfterEach(func() {
// Safety net cleanup
_, _, _, _ = testutil.RunVirtwork("cleanup",
_, stderr, exitCode, err := testutil.RunVirtwork("cleanup",
"--namespace", namespace, "--delete-namespace", "--yes")
if err != nil || exitCode != 0 {
GinkgoWriter.Printf("AfterEach cleanup failed (ns=%s exit=%d): err=%v stderr=%s\n",
namespace, exitCode, err, stderr)
}
})

It("should delete all managed resources", func() {
Expand Down
40 changes: 40 additions & 0 deletions tests/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
package e2e_test

import (
"context"
"strings"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"

"github.com/opdev/virtwork/internal/testutil"
)
Expand All @@ -26,3 +30,39 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred(), "Failed to build virtwork binary")
GinkgoWriter.Printf("Using virtwork binary: %s\n", path)
})

var _ = AfterSuite(func() {
c := testutil.MustConnect("")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

var nsList corev1.NamespaceList
if err := c.List(ctx, &nsList); err != nil {
GinkgoWriter.Printf("AfterSuite: failed to list namespaces: %v\n", err)
return
}

var stale []string
for i := range nsList.Items {
name := nsList.Items[i].Name
if strings.HasPrefix(name, "virtwork-test-") && nsList.Items[i].DeletionTimestamp == nil {
stale = append(stale, name)
}
}

if len(stale) == 0 {
GinkgoWriter.Println("AfterSuite: no stale virtwork-test-* namespaces found")
return
}

GinkgoWriter.Printf("AfterSuite: sweeping %d stale namespace(s)\n", len(stale))
for _, name := range stale {
ns := &corev1.Namespace{}
ns.Name = name
if err := c.Delete(ctx, ns); err != nil {
GinkgoWriter.Printf("AfterSuite: failed to delete namespace %s: %v\n", name, err)
} else {
GinkgoWriter.Printf("AfterSuite: deleted namespace %s\n", name)
}
}
})
6 changes: 5 additions & 1 deletion tests/e2e/fullcycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ var _ = Describe("Full deployment cycle", Label("slow"), func() {
})

AfterEach(func() {
_, _, _, _ = testutil.RunVirtwork("cleanup",
_, stderr, exitCode, err := testutil.RunVirtwork("cleanup",
"--namespace", namespace, "--delete-namespace", "--yes")
if err != nil || exitCode != 0 {
GinkgoWriter.Printf("AfterEach cleanup failed (ns=%s exit=%d): err=%v stderr=%s\n",
namespace, exitCode, err, stderr)
}
})

It("should deploy CPU workload, wait for readiness, and clean up", func() {
Expand Down
9 changes: 6 additions & 3 deletions tests/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ var _ = Describe("virtwork run", Label("slow"), func() {
})

AfterEach(func() {
// Force cleanup regardless of test outcome
_, _, _, _ = testutil.RunVirtwork("cleanup",
"--namespace", namespace, "--delete-namespace")
_, stderr, exitCode, err := testutil.RunVirtwork("cleanup",
"--namespace", namespace, "--delete-namespace", "--yes")
if err != nil || exitCode != 0 {
GinkgoWriter.Printf("AfterEach cleanup failed (ns=%s exit=%d): err=%v stderr=%s\n",
namespace, exitCode, err, stderr)
}
})

It("should deploy a single CPU workload with --no-wait", func() {
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/tps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ var _ = Describe("TPS workload", Label("slow"), func() {
})

AfterEach(func() {
_, _, _, _ = testutil.RunVirtwork("cleanup",
_, stderr, exitCode, err := testutil.RunVirtwork("cleanup",
"--namespace", namespace, "--delete-namespace", "--yes")
if err != nil || exitCode != 0 {
GinkgoWriter.Printf("AfterEach cleanup failed (ns=%s exit=%d): err=%v stderr=%s\n",
namespace, exitCode, err, stderr)
}
})

It("should deploy server and client VMs with a service", func() {
Expand Down
Loading