1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 01:27:01 +00:00

test: preserve SYSTEMROOT on windows (#451)

This commit is contained in:
James Hillyerd
2023-11-29 16:36:40 -08:00
committed by GitHub
parent 043551343c
commit 32b83e6345

View File

@@ -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)
}
}