Merge pull request #29 from joho/respect_empty_external_env_vars

Respect preset empty external env vars
pull/7/merge
John Barton 2017-03-29 07:01:54 +11:00 committed by GitHub
commit 325433c502
2 changed files with 10 additions and 1 deletions

View File

@ -119,8 +119,15 @@ func loadFile(filename string, overload bool) error {
return err
}
currentEnv := map[string]bool{}
rawEnv := os.Environ()
for _, rawEnvLine := range rawEnv {
key := strings.Split(rawEnvLine, "=")[0]
currentEnv[key] = true
}
for key, value := range envMap {
if os.Getenv(key) == "" || overload {
if !currentEnv[key] || overload {
os.Setenv(key, value)
}
}

View File

@ -100,10 +100,12 @@ func TestLoadDoesNotOverride(t *testing.T) {
// ensure NO overload
presets := map[string]string{
"OPTION_A": "do_not_override",
"OPTION_B": "",
}
expectedValues := map[string]string{
"OPTION_A": "do_not_override",
"OPTION_B": "",
}
loadEnvAndCompareValues(t, Load, envFileName, expectedValues, presets)
}