diff --git a/template/parse_test.go b/template/parse_test.go index 77b63616d..03e9c23b3 100644 --- a/template/parse_test.go +++ b/template/parse_test.go @@ -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()) + } + } +} \ No newline at end of file diff --git a/template/test-fixtures/error-duplicate-config.json b/template/test-fixtures/error-duplicate-config.json new file mode 100644 index 000000000..19d2beeec --- /dev/null +++ b/template/test-fixtures/error-duplicate-config.json @@ -0,0 +1,11 @@ +{ + "variables": { + "var": "value" + }, + "builders": [ + { + "foo": "something", + "foo": "something" + } + ] +} diff --git a/template/test-fixtures/error-duplicate-variables.json b/template/test-fixtures/error-duplicate-variables.json new file mode 100644 index 000000000..c603b7fe0 --- /dev/null +++ b/template/test-fixtures/error-duplicate-variables.json @@ -0,0 +1,13 @@ +{ + "variables": { + "var": "value" + }, + "variables": { + "var": "value" + }, + "builders": [ + { + "foo": "something" + } + ] +}