Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include unset variables when parsing env_file #2259

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions opts/envfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ another invalid line`
// ParseEnvFile with environment variable import definitions
func TestParseEnvVariableDefinitionsFile(t *testing.T) {
content := `# comment=
UNDEFINED_VAR
HOME
UNDEFINED_VAR
`
tmpFile := tmpFileWithContent(content, t)
defer os.Remove(tmpFile)
Expand All @@ -154,12 +154,16 @@ HOME
t.Fatal("There must not be any error")
}

if 2 != len(variables) {
t.Fatal("exactly two variable are imported")
}

if "HOME="+os.Getenv("HOME") != variables[0] {
t.Fatal("the HOME variable is not properly imported as the first variable (but it is the only one to import)")
t.Fatal("the HOME variable is not properly imported as the first variable")
}

if 1 != len(variables) {
t.Fatal("exactly one variable is imported (as the other one is not set at all)")
if "UNDEFINED_VAR" != variables[1] {
t.Fatal("the UNDEFINED_VAR variable is not properly imported as the second variable")
}
}

Expand Down
2 changes: 2 additions & 0 deletions opts/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]
if present {
// if only a pass-through variable is given, clean it up.
lines = append(lines, fmt.Sprintf("%s=%s", strings.TrimSpace(line), value))
} else {
lines = append(lines, strings.TrimSpace(line))
}
}
}
Expand Down