mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
check and return error from parsing var-files (#10569)
* check and return error from parsing var-files * changelog entry for 1.1.0 and 1.0.5
This commit is contained in:
@@ -88,6 +88,10 @@ func decode(c *jobConfig) error {
|
||||
|
||||
for _, varFile := range config.VarFiles {
|
||||
parsedVarFile, ds := parseFile(varFile)
|
||||
if parsedVarFile == nil || ds.HasErrors() {
|
||||
return fmt.Errorf("unable to parse var file: %v", ds.Error())
|
||||
}
|
||||
|
||||
config.parsedVarFiles = append(config.parsedVarFiles, parsedVarFile)
|
||||
diags = append(diags, ds...)
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ job "example" {
|
||||
defer os.Remove(varFile.Name())
|
||||
|
||||
content := `dc_var = "set_dc"
|
||||
region_var = "set_region"`
|
||||
region_var = "set_region"`
|
||||
_, err = varFile.WriteString(content)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -162,6 +162,18 @@ region_var = "set_region"`
|
||||
require.NotNil(t, out.Region)
|
||||
require.Equal(t, "set_region", *out.Region)
|
||||
})
|
||||
|
||||
t.Run("var-file does not exist", func(t *testing.T) {
|
||||
|
||||
out, err := ParseWithConfig(&ParseConfig{
|
||||
Path: "input.hcl",
|
||||
Body: []byte(hcl),
|
||||
VarFiles: []string{"does-not-exist.hcl"},
|
||||
AllowFS: true,
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Nil(t, out)
|
||||
})
|
||||
}
|
||||
|
||||
// TestParse_UnknownVariables asserts that unknown variables are left intact for further processing
|
||||
|
||||
Reference in New Issue
Block a user