From e0d666c29983b9eada7a68272eb5f66fc43a94f1 Mon Sep 17 00:00:00 2001 From: Ferenc Szabo Date: Fri, 6 Dec 2024 09:12:42 +0100 Subject: [PATCH] test: ensure that template names are not duplicated As we use the name as ID. --- templates_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates_test.go b/templates_test.go index 69c0634..bad97e4 100644 --- a/templates_test.go +++ b/templates_test.go @@ -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