summaryrefslogtreecommitdiff
path: root/tests/e2e/test_helpers.go
diff options
context:
space:
mode:
authorJames O'Doherty <james@theodohertyfamily.com>2026-06-03 23:45:45 -0400
committerJames O'Doherty <james@theodohertyfamily.com>2026-06-03 23:45:45 -0400
commit51a0845adba702ac02437405988b24b3b2c9fb45 (patch)
tree62174471b2bf2240f5cbe8532c991e33afce9e18 /tests/e2e/test_helpers.go
parentda70b10fbd056f19d892acad542ce96c40c58389 (diff)
fix: resolve resource leaks and improve namespace lifecycle management
- Fix DNS resolver leaks by creating temporary resolv.conf files within the profile's runtime directory and ensuring robust cleanup. - Fix isolation block directory leaks by explicitly removing the block directory during namespace unpinning. - Improve namespace lifecycle management: - Register processes before joining an active namespace to prevent race conditions in reference counting. - Update `IsLastProcess` and corresponding tests to reflect the unregister-then-check cleanup flow. - Improve test reliability and correctness: - Convert `TestAppRun_ProfileDirInjection` to use separate binary execution, preventing process replacement and ensuring `t.TempDir()` cleanup. - Replace hardcoded test configuration paths with `t.TempDir()` in `mount_leak_test.go`. - Implement `SetEnvOverrides` helper for cleaner environment variable management in E2E tests. - Improve E2E lifecycle tests with better environment handling and output redirection.
Diffstat (limited to 'tests/e2e/test_helpers.go')
-rw-r--r--tests/e2e/test_helpers.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/e2e/test_helpers.go b/tests/e2e/test_helpers.go
index 0ae83aa..6d65011 100644
--- a/tests/e2e/test_helpers.go
+++ b/tests/e2e/test_helpers.go
@@ -3,6 +3,7 @@ package e2e
import (
"fmt"
"os"
+ "strings"
)
// GetBinaryPath resolves the path to the wg-wrap binary.
@@ -19,3 +20,29 @@ func GetBinaryPath() (string, error) {
return path, nil
}
+
+// SetEnvOverrides returns a new slice of environment variables with the provided overrides applied.
+// It ensures that overriding an existing variable replaces it rather than appending it.
+func SetEnvOverrides(overrides map[string]string) []string {
+ env := os.Environ()
+ newEnv := make([]string, 0, len(env)+len(overrides))
+
+ for _, e := range env {
+ matched := false
+ for k := range overrides {
+ if strings.HasPrefix(e, k+"=") {
+ matched = true
+ break
+ }
+ }
+ if !matched {
+ newEnv = append(newEnv, e)
+ }
+ }
+
+ for k, v := range overrides {
+ newEnv = append(newEnv, fmt.Sprintf("%s=%s", k, v))
+ }
+
+ return newEnv
+}