actually honor var files (#9592)

Apparently, we missed passing VarFile argument, so var files were
ignored.

Fixes #9588
This commit is contained in:
Mahmood Ali 2020-12-09 14:12:48 -05:00 committed by GitHub
parent 0a3a748053
commit 9a3da14a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 4 deletions

View File

@ -457,6 +457,7 @@ func (j *JobGetter) ApiJobWithArgs(jpath string, vars []string, varfiles []strin
Body: buf.Bytes(), Body: buf.Bytes(),
ArgVars: vars, ArgVars: vars,
AllowFS: true, AllowFS: true,
VarFiles: varfiles,
}) })
if err != nil { if err != nil {

View File

@ -328,6 +328,50 @@ func TestJobGetter_LocalFile_InvalidHCL2(t *testing.T) {
} }
} }
// TestJobGetter_HCL2_Variables asserts variable arguments from CLI
// and varfiles are both honored
func TestJobGetter_HCL2_Variables(t *testing.T) {
t.Parallel()
hcl := `
variables {
var1 = "default-val"
var2 = "default-val"
var3 = "default-val"
}
job "example" {
datacenters = ["${var.var1}", "${var.var2}", "${var.var3}"]
}
`
cliArgs := []string{`var2=from-cli`}
fileVars := `var3 = "from-varfile"`
expected := []string{"default-val", "from-cli", "from-varfile"}
hclf, err := ioutil.TempFile("", "hcl")
require.NoError(t, err)
defer os.Remove(hclf.Name())
defer hclf.Close()
_, err = hclf.WriteString(hcl)
require.NoError(t, err)
vf, err := ioutil.TempFile("", "var.hcl")
require.NoError(t, err)
defer os.Remove(vf.Name())
defer vf.Close()
_, err = vf.WriteString(fileVars + "\n")
require.NoError(t, err)
j, err := (&JobGetter{}).ApiJobWithArgs(hclf.Name(), cliArgs, []string{vf.Name()})
require.NoError(t, err)
require.NotNil(t, j)
require.Equal(t, expected, j.Datacenters)
}
// Test StructJob with jobfile from HTTP Server // Test StructJob with jobfile from HTTP Server
func TestJobGetter_HTTPServer(t *testing.T) { func TestJobGetter_HTTPServer(t *testing.T) {
t.Parallel() t.Parallel()