add more test for var files

This commit is contained in:
Adrien Delorme 2020-03-12 17:08:53 +01:00
parent 6b48feb817
commit 710ebdcef5
4 changed files with 37 additions and 0 deletions

View File

@ -91,6 +91,9 @@ func testParse(t *testing.T, tests []parseTest) {
if variable.DefaultValue.GoString() != value.DefaultValue.GoString() {
t.Fatalf("Parser.parse() input variable %s expected '%s' but was '%s'", name, value.DefaultValue.GoString(), variable.DefaultValue.GoString())
}
if diff := cmp.Diff(variable.VarfileValue.GoString(), value.VarfileValue.GoString()); diff != "" {
t.Fatalf("Parser.parse(): varfile value differs: %s", diff)
}
} else {
t.Fatalf("Parser.parse() missing input variable. %s", name)
}

View File

@ -0,0 +1,4 @@
variable "foo" {
type = string
default = "bar"
}

View File

@ -0,0 +1 @@
foo = "wee"

View File

@ -240,6 +240,35 @@ func TestParse_variables(t *testing.T) {
[]packer.Build{},
false,
},
{"set variable from var-file",
defaultParser,
parseTestArgs{"testdata/variables/foo-string.variable.pkr.hcl", nil, []string{"testdata/variables/set-foo-too-wee.hcl"}},
&PackerConfig{
Basedir: filepath.Join("testdata", "variables"),
InputVariables: Variables{
"foo": &Variable{
DefaultValue: cty.StringVal("bar"),
Name: "foo",
VarfileValue: cty.StringVal("wee"),
},
},
},
false, false,
[]packer.Build{},
false,
},
{"unknown variable from var-file",
defaultParser,
parseTestArgs{"testdata/variables/empty.pkr.hcl", nil, []string{"testdata/variables/set-foo-too-wee.hcl"}},
&PackerConfig{
Basedir: filepath.Join("testdata", "variables"),
},
true, false,
[]packer.Build{},
false,
},
}
testParse(t, tests)
}