diff options
Diffstat (limited to 'tests/e2e/test_helpers.go')
| -rw-r--r-- | tests/e2e/test_helpers.go | 27 |
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 +} |
