Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/testing/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,19 @@ func Parse(configFile string) (testSuite *TestSuite, err error) {
// ParseFromData parses data and returns the test suite
func ParseFromData(data []byte) (testSuite *TestSuite, err error) {
testSuite = &TestSuite{}
err = yaml.Unmarshal(data, testSuite)
if err = yaml.Unmarshal(data, testSuite); err != nil {
return
}

names := map[string]struct{}{}
for _, item := range testSuite.Items {
if _, ok := names[item.Name]; !ok {
names[item.Name] = struct{}{}
} else {
err = fmt.Errorf("having duplicated name '%s'", item.Name)
break
}
}
return
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/testing/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func TestParse(t *testing.T) {
assert.NotNil(t, err)
}

func TestDuplicatedNames(t *testing.T) {
_, err := Parse("testdata/duplicated-names.yaml")
assert.NotNil(t, err)

_, err = ParseFromData([]byte("fake"))
assert.NotNil(t, err)
}

func TestRequestRender(t *testing.T) {
tests := []struct {
name string
Expand Down
8 changes: 8 additions & 0 deletions pkg/testing/testdata/duplicated-names.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: duplicated names
items:
- name: projects
request:
api: https://foo
- name: projects
request:
api: https://foo