Add tests for check of json duplicate fields
This commit is contained in:
parent
a6d90babbf
commit
d654898ebf
@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
template/test-fixtures/error-duplicate-config.json
Normal file
11
template/test-fixtures/error-duplicate-config.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"variables": {
|
||||||
|
"var": "value"
|
||||||
|
},
|
||||||
|
"builders": [
|
||||||
|
{
|
||||||
|
"foo": "something",
|
||||||
|
"foo": "something"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
13
template/test-fixtures/error-duplicate-variables.json
Normal file
13
template/test-fixtures/error-duplicate-variables.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"variables": {
|
||||||
|
"var": "value"
|
||||||
|
},
|
||||||
|
"variables": {
|
||||||
|
"var": "value"
|
||||||
|
},
|
||||||
|
"builders": [
|
||||||
|
{
|
||||||
|
"foo": "something"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user