Skip to content

Commit

Permalink
test: ensure that template names are not duplicated
Browse files Browse the repository at this point in the history
As we use the name as ID.
  • Loading branch information
frncmx committed Dec 6, 2024
1 parent 4d378c2 commit e0d666c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,21 @@ func TestTemplates(t *testing.T) {
require.NotPanics(t, func() {
templates := policylib.Templates()
require.Greater(t, len(templates), 1, "should have templates")
assertUniqueNames(t, templates, "template names must be unique")
}, "embedded templates should not panic")
}

func assertUniqueNames(t *testing.T, templates []policylib.Template, msg string) int {
set := map[string]bool{}
for _, template := range templates {
if set[template.Name] {
assert.Failf(t, "duplicate template name: "+template.Name, msg)
}
set[template.Name] = true
}
return len(set)
}

func TestTemplates_Parsing(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit e0d666c

Please sign in to comment.