mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
tests: add tests for invalid syntax cases
This commit is contained in:
@@ -382,7 +382,7 @@ func decodeAsAttribute(body hcl.Body, ctx *hcl.EvalContext, name string) (map[st
|
||||
diags = diags.Append(&hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: fmt.Sprintf("Duplicate %v block", name),
|
||||
Detail: fmt.Sprintf("Only one %v block is allowed. Another was defined at %s.",
|
||||
Detail: fmt.Sprintf("%v may not be defined more than once. Another definition is defined at %s.",
|
||||
name, attr.Range.String()),
|
||||
Subject: &bb.Blocks[0].DefRange,
|
||||
})
|
||||
|
||||
@@ -729,6 +729,54 @@ job "example" {
|
||||
require.Contains(t, err.Error(), "Duplicate env block")
|
||||
}
|
||||
|
||||
func Test_TaskEnvs_Invalid(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
envSnippet string
|
||||
expectedErr string
|
||||
}{
|
||||
{
|
||||
"attr: invalid expression",
|
||||
`env = { key = local.undefined_local }`,
|
||||
`does not have an attribute named "undefined_local"`,
|
||||
},
|
||||
{
|
||||
"block: invalid block expression",
|
||||
`env {
|
||||
for k in ["a", "b"]: k => k
|
||||
}`,
|
||||
"Invalid block definition",
|
||||
},
|
||||
{
|
||||
"attr: not make sense",
|
||||
`env = [ "a" ]`,
|
||||
"Unsuitable value: map of string required",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
hcl := `
|
||||
job "example" {
|
||||
group "group" {
|
||||
task "task" {
|
||||
driver = "docker"
|
||||
config {}
|
||||
|
||||
` + c.envSnippet + `
|
||||
}
|
||||
}
|
||||
}`
|
||||
_, err := ParseWithConfig(&ParseConfig{
|
||||
Path: "input.hcl",
|
||||
Body: []byte(hcl),
|
||||
})
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), c.expectedErr)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParse_Meta_Alternatives(t *testing.T) {
|
||||
hcl := ` job "example" {
|
||||
group "group" {
|
||||
|
||||
Reference in New Issue
Block a user