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
22 changes: 22 additions & 0 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ const (
unstructuredSecretName = "unstructured-secret"
)

// ensurePortForward ensures a fresh port-forward connection to localstack
// Kills any existing port-forward and starts a new one
func ensurePortForward(namespace string) error {
// Kill any existing port-forward
exec.Command("pkill", "-f", "port-forward.*localstack").Run()
time.Sleep(1 * time.Second)

// Start new port-forward
log.Println("Starting fresh port-forward for localstack...")
pf := exec.Command("kubectl", "port-forward", "-n", namespace, "services/localstack", "4566:4566")
pf.Stdout = os.Stdout
pf.Stderr = os.Stderr
if err := pf.Start(); err != nil {
return fmt.Errorf("failed to start port-forward: %w", err)
}
Comment on lines +65 to +70

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The port-forward process started here is not tracked for cleanup. If the test suite finishes or crashes, this process might continue running in the background. Consider returning the exec.Cmd object or adding it to a global registry so it can be killed in the TestMain cleanup phase, similar to how it is handled in testSetup.


// Give it time to establish
time.Sleep(3 * time.Second)
log.Println("Port-forward established")
return nil
}

Comment on lines +56 to +77

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I dont think so it is required because user will make sure that while doing port forwarding it should not have any process running , this is making code unnecessarily complex

func TestMain(m *testing.M) {
testenv = env.New()
runningProcesses := []exec.Cmd{}
Expand Down
Loading
Loading