From 1e8974570434ae0069596ac08aea0e5d6fe69920 Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Mon, 2 Jul 2018 07:33:44 +0200 Subject: [PATCH] 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 --- opts/envfile_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/opts/envfile_test.go b/opts/envfile_test.go index 6302263848..dd79f60925 100644 --- a/opts/envfile_test.go +++ b/opts/envfile_test.go @@ -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)") + } +}