Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
test to show current behaviour is wrong at parsing a environment file
defining an undefined variable - it must not be defined!

NOTE: this test assume the $HOME variable is always set (see Posix, this
       normally is the case, e.g. the testsuite remains stable).

Signed-off-by: Tom Klingenberg <[email protected]>
  • Loading branch information
ktomk committed Jul 1, 2018
1 parent 34ba66b commit 8d01c2b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions opts/envfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,26 @@ another invalid line`
t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error())
}
}

// ParseEnvFile with environment variable import definitions
func TestParseEnvVariableDefinitionsFile(t *testing.T) {
content := `# comment=
UNDEFINED_VAR
HOME
`
tmpFile := tmpFileWithContent(content, t)
defer os.Remove(tmpFile)

variables, err := ParseEnvFile(tmpFile)
if nil != err {
t.Fatal("There must not be any error")
}

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

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

0 comments on commit 8d01c2b

Please sign in to comment.