forked from coop-cloud-mirrors/godotenv
Make sure we don't overwrite existing ENV vars.
This commit is contained in:
parent
3f6d91c4c0
commit
9ec71cc6c8
@ -34,7 +34,7 @@ func loadFile(filename string) (err error) {
|
||||
if !isIgnoredLine(fullLine) {
|
||||
key, value, err := parseLine(fullLine)
|
||||
|
||||
if err == nil {
|
||||
if err == nil && os.Getenv(key) == "" {
|
||||
os.Setenv(key, value)
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,16 @@ func TestLoadQuotedEnv(t *testing.T) {
|
||||
loadEnvAndCompareValues(t, envFileName, expectedValues)
|
||||
}
|
||||
|
||||
func TestActualEnvVarsAreLeftAlone(t *testing.T) {
|
||||
os.Clearenv()
|
||||
os.Setenv("OPTION_A", "actualenv")
|
||||
_ = Load("fixtures/plain.env")
|
||||
|
||||
if os.Getenv("OPTION_A") != "actualenv" {
|
||||
t.Error("An ENV var set earlier was overwritten")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsing(t *testing.T) {
|
||||
// unquoted values
|
||||
parseAndCompare(t, "FOO=bar", "FOO", "bar")
|
||||
|
Loading…
Reference in New Issue
Block a user