Add ControllerRoles Test

Added a test to check that if a controller role includes `List`, it also includes `Watch`.

Signed-off-by: Mitsuru Kariya <mitsuru.kariya@nttdata.com>
This commit is contained in:
Mitsuru Kariya 2025-02-25 16:47:05 +09:00
parent 019c9b4d2d
commit 7826934ada
No known key found for this signature in database
GPG Key ID: D04A2FC72FE3C396

View File

@ -18,6 +18,7 @@ package bootstrappolicy
import (
"reflect"
"slices"
"testing"
"k8s.io/apimachinery/pkg/api/meta"
@ -91,3 +92,15 @@ func TestControllerRoleLabel(t *testing.T) {
}
}
}
func TestControllerRoleVerbsConsistensy(t *testing.T) {
roles := ControllerRoles()
for _, role := range roles {
for _, rule := range role.Rules {
verbs := rule.Verbs
if slices.Contains(verbs, "list") && !slices.Contains(verbs, "watch") {
t.Errorf("The ClusterRole %s has Verb `List` but does not have Verb `Watch`.", role.Name)
}
}
}
}