mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Allow adding new verbs in AddSpecialVerb
This commit is contained in:
parent
d58f42961c
commit
790396caba
@ -114,10 +114,12 @@ var (
|
||||
|
||||
// AddSpecialVerb allows the addition of items to the `specialVerbs` map for non-k8s native resources.
|
||||
func AddSpecialVerb(verb string, gr schema.GroupResource) {
|
||||
if resources, ok := specialVerbs[verb]; ok {
|
||||
resources, ok := specialVerbs[verb]
|
||||
if !ok {
|
||||
resources = make([]schema.GroupResource, 1)
|
||||
}
|
||||
resources = append(resources, gr)
|
||||
specialVerbs[verb] = resources
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceOptions holds the related options for '--resource' option
|
||||
|
@ -680,27 +680,34 @@ func TestComplete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAddSpecialVerb(t *testing.T) {
|
||||
resource := schema.GroupResource{
|
||||
Group: "my.custom.io",
|
||||
Resource: "things",
|
||||
testCases := map[string]struct {
|
||||
verb string
|
||||
resource schema.GroupResource
|
||||
}{
|
||||
"existing verb": {
|
||||
verb: "use",
|
||||
resource: schema.GroupResource{Group: "my.custom.io", Resource: "one"},
|
||||
},
|
||||
"new verb": {
|
||||
verb: "new",
|
||||
resource: schema.GroupResource{Group: "my.custom.io", Resource: "two"},
|
||||
},
|
||||
}
|
||||
|
||||
AddSpecialVerb("use", resource)
|
||||
|
||||
found := false
|
||||
resources, ok := specialVerbs["use"]
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
AddSpecialVerb(tc.verb, tc.resource)
|
||||
resources, ok := specialVerbs[tc.verb]
|
||||
if !ok {
|
||||
t.Errorf("expected resources for verb: use, found none\n")
|
||||
t.Errorf("missing expected verb: %s", tc.verb)
|
||||
}
|
||||
|
||||
for _, res := range resources {
|
||||
if reflect.DeepEqual(resource, res) {
|
||||
found = true
|
||||
break
|
||||
if reflect.DeepEqual(tc.resource, res) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
t.Errorf("expected resource:\n%v\nnot found", resource)
|
||||
t.Errorf("missing expected resource:%#v", tc.resource)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user