From 9ed2e9d22a84053fdbb636c0842ef9b92a042c1e Mon Sep 17 00:00:00 2001 From: Tom Klingenberg Date: Sun, 1 Jul 2018 23:17:50 +0200 Subject: [PATCH] Add failing test 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). --- opts/envfile_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/opts/envfile_test.go b/opts/envfile_test.go index 630226384864..a32dbc34a08f 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)") + } +}