add test for undefined variable environment file import

test to show current behavior is wrong at parsing an 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 test suite remains stable).

Signed-off-by: Tom Klingenberg <tklingenberg@lastflood.net>
This commit is contained in:
Tom Klingenberg 2018-07-02 07:33:44 +02:00
parent 34ba66b0c5
commit 1e89745704
1 changed files with 23 additions and 0 deletions

View File

@ -139,3 +139,26 @@ another invalid line`
t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error()) 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)")
}
}