mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Add Additional Tests
Added tests to check that if NodeRules, ClusterRoles, and NamespaceRoles include `List`, it also include `Watch`. Signed-off-by: Mitsuru Kariya <mitsuru.kariya@nttdata.com>
This commit is contained in:
parent
1d3fafa1c7
commit
dbf78217a1
@ -20,6 +20,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
@ -285,3 +286,39 @@ func TestClusterRoleLabel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeRuleVerbsConsistency(t *testing.T) {
|
||||
rules := bootstrappolicy.NodeRules()
|
||||
for _, rule := range rules {
|
||||
verbs := rule.Verbs
|
||||
if slices.Contains(verbs, "list") && !slices.Contains(verbs, "watch") {
|
||||
t.Errorf("The NodeRule has Verb `List` but does not have Verb `Watch`.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClusterRoleVerbsConsistency(t *testing.T) {
|
||||
roles := bootstrappolicy.ClusterRoles()
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNamespaceRoleVerbsConsistency(t *testing.T) {
|
||||
namespaceRoles := bootstrappolicy.NamespaceRoles()
|
||||
for namespace, roles := range namespaceRoles {
|
||||
for _, role := range roles {
|
||||
for _, rule := range role.Rules {
|
||||
verbs := rule.Verbs
|
||||
if slices.Contains(verbs, "list") && !slices.Contains(verbs, "watch") {
|
||||
t.Errorf("The Role %s/%s has Verb `List` but does not have Verb `Watch`.", namespace, role.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user