Add tests for check of json duplicate fields

This commit is contained in:
Moss 2020-02-12 14:34:20 +01:00
parent a6d90babbf
commit d654898ebf
3 changed files with 43 additions and 0 deletions

View File

@ -560,3 +560,22 @@ func TestParse_bad(t *testing.T) {
} }
} }
} }
func TestParse_checkForDuplicateFields(t *testing.T) {
cases := []struct {
File string
Expected string
}{
{"error-duplicate-variables.json", "template has duplicate field: variables"},
{"error-duplicate-config.json", "template has duplicate field: foo"},
}
for _, tc := range cases {
_, err := ParseFile(fixtureDir(tc.File))
if err == nil {
t.Fatalf("expected error")
}
if !strings.Contains(err.Error(), tc.Expected) {
t.Fatalf("file: %s\nExpected: %s\n%s\n", tc.File, tc.Expected, err.Error())
}
}
}

View File

@ -0,0 +1,11 @@
{
"variables": {
"var": "value"
},
"builders": [
{
"foo": "something",
"foo": "something"
}
]
}

View File

@ -0,0 +1,13 @@
{
"variables": {
"var": "value"
},
"variables": {
"var": "value"
},
"builders": [
{
"foo": "something"
}
]
}