diff --git a/pkg/test/integration_test.go b/pkg/test/integration_test.go index c65bddc..de56deb 100644 --- a/pkg/test/integration_test.go +++ b/pkg/test/integration_test.go @@ -8,6 +8,7 @@ import ( smtpclient "net/smtp" "os" "path/filepath" + "runtime" "testing" "time" @@ -222,7 +223,7 @@ func startServer() (func(), error) { // Storage setup. storage.Constructors["memory"] = mem.New - os.Clearenv() + clearEnv() conf, err := config.Process() if err != nil { return nil, err @@ -272,3 +273,23 @@ func readTestData(path ...string) []byte { } return data } + +// clearEnv clears environment variables, preserving any that are critical for this OS. +func clearEnv() { + preserve := make(map[string]string) + backup := func(k string) { + preserve[k] = os.Getenv(k) + } + + // Backup ciritcal env variables. + switch runtime.GOOS { + case "windows": + backup("SYSTEMROOT") + } + + os.Clearenv() + + for k, v := range preserve { + os.Setenv(k, v) + } +}