mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +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.
|
// AddSpecialVerb allows the addition of items to the `specialVerbs` map for non-k8s native resources.
|
||||||
func AddSpecialVerb(verb string, gr schema.GroupResource) {
|
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)
|
resources = append(resources, gr)
|
||||||
specialVerbs[verb] = resources
|
specialVerbs[verb] = resources
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceOptions holds the related options for '--resource' option
|
// ResourceOptions holds the related options for '--resource' option
|
||||||
|
@ -680,27 +680,34 @@ func TestComplete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSpecialVerb(t *testing.T) {
|
func TestAddSpecialVerb(t *testing.T) {
|
||||||
resource := schema.GroupResource{
|
testCases := map[string]struct {
|
||||||
Group: "my.custom.io",
|
verb string
|
||||||
Resource: "things",
|
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)
|
for name, tc := range testCases {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
found := false
|
AddSpecialVerb(tc.verb, tc.resource)
|
||||||
resources, ok := specialVerbs["use"]
|
resources, ok := specialVerbs[tc.verb]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("expected resources for verb: use, found none\n")
|
t.Errorf("missing expected verb: %s", tc.verb)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
if reflect.DeepEqual(resource, res) {
|
if reflect.DeepEqual(tc.resource, res) {
|
||||||
found = true
|
return
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
t.Errorf("missing expected resource:%#v", tc.resource)
|
||||||
if !found {
|
})
|
||||||
t.Errorf("expected resource:\n%v\nnot found", resource)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user