mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
template: error on missing key (#15141)
* Support error_on_missing_value for templates * Update docs for template stanza
This commit is contained in:
@@ -111,6 +111,9 @@ func normalizeTemplates(templates []*api.Template) {
|
||||
if t.Splay == nil {
|
||||
t.Splay = pointer.Of(5 * time.Second)
|
||||
}
|
||||
if t.ErrMissingKey == nil {
|
||||
t.ErrMissingKey = pointer.Of(false)
|
||||
}
|
||||
normalizeChangeScript(t.ChangeScript)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1052,3 +1052,19 @@ func TestWaitConfig(t *testing.T) {
|
||||
require.Equal(t, 5*time.Second, *tmpl.Wait.Min)
|
||||
require.Equal(t, 60*time.Second, *tmpl.Wait.Max)
|
||||
}
|
||||
|
||||
func TestErrMissingKey(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
hclBytes, err := os.ReadFile("test-fixtures/template-err-missing-key.hcl")
|
||||
require.NoError(t, err)
|
||||
job, err := ParseWithConfig(&ParseConfig{
|
||||
Path: "test-fixtures/template-err-missing-key.hcl",
|
||||
Body: hclBytes,
|
||||
AllowFS: false,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
tmpl := job.TaskGroups[0].Tasks[0].Templates[0]
|
||||
require.NotNil(t, tmpl)
|
||||
require.NotNil(t, tmpl.ErrMissingKey)
|
||||
require.True(t, *tmpl.ErrMissingKey)
|
||||
}
|
||||
|
||||
9
jobspec2/test-fixtures/template-err-missing-key.hcl
Normal file
9
jobspec2/test-fixtures/template-err-missing-key.hcl
Normal file
@@ -0,0 +1,9 @@
|
||||
job "example" {
|
||||
group "group" {
|
||||
task "task" {
|
||||
template {
|
||||
error_on_missing_key = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user