mirror of https://github.com/joho/godotenv.git
Make sure we don't overwrite existing ENV vars.
parent
3f6d91c4c0
commit
9ec71cc6c8
|
@ -34,7 +34,7 @@ func loadFile(filename string) (err error) {
|
||||||
if !isIgnoredLine(fullLine) {
|
if !isIgnoredLine(fullLine) {
|
||||||
key, value, err := parseLine(fullLine)
|
key, value, err := parseLine(fullLine)
|
||||||
|
|
||||||
if err == nil {
|
if err == nil && os.Getenv(key) == "" {
|
||||||
os.Setenv(key, value)
|
os.Setenv(key, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,16 @@ func TestLoadQuotedEnv(t *testing.T) {
|
||||||
loadEnvAndCompareValues(t, envFileName, expectedValues)
|
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) {
|
func TestParsing(t *testing.T) {
|
||||||
// unquoted values
|
// unquoted values
|
||||||
parseAndCompare(t, "FOO=bar", "FOO", "bar")
|
parseAndCompare(t, "FOO=bar", "FOO", "bar")
|
||||||
|
|
Loading…
Reference in New Issue