mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
fix: fix miss makezero bug (#125132)
* fix: fix miss makezero bug Signed-off-by: alingse <alingse@foxmail.com> * add testcase for new verb * Update create_role_test.go --------- Signed-off-by: alingse <alingse@foxmail.com>
This commit is contained in:
parent
e43e68fdc3
commit
5b06498cb2
@ -116,7 +116,7 @@ var (
|
|||||||
func AddSpecialVerb(verb string, gr schema.GroupResource) {
|
func AddSpecialVerb(verb string, gr schema.GroupResource) {
|
||||||
resources, ok := specialVerbs[verb]
|
resources, ok := specialVerbs[verb]
|
||||||
if !ok {
|
if !ok {
|
||||||
resources = make([]schema.GroupResource, 1)
|
resources = make([]schema.GroupResource, 0, 1)
|
||||||
}
|
}
|
||||||
resources = append(resources, gr)
|
resources = append(resources, gr)
|
||||||
specialVerbs[verb] = resources
|
specialVerbs[verb] = resources
|
||||||
|
@ -684,14 +684,17 @@ func TestAddSpecialVerb(t *testing.T) {
|
|||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
verb string
|
verb string
|
||||||
resource schema.GroupResource
|
resource schema.GroupResource
|
||||||
|
isNew bool
|
||||||
}{
|
}{
|
||||||
"existing verb": {
|
"existing verb": {
|
||||||
verb: "use",
|
verb: "use",
|
||||||
resource: schema.GroupResource{Group: "my.custom.io", Resource: "one"},
|
resource: schema.GroupResource{Group: "my.custom.io", Resource: "one"},
|
||||||
|
isNew: false,
|
||||||
},
|
},
|
||||||
"new verb": {
|
"new verb": {
|
||||||
verb: "new",
|
verb: "new",
|
||||||
resource: schema.GroupResource{Group: "my.custom.io", Resource: "two"},
|
resource: schema.GroupResource{Group: "my.custom.io", Resource: "two"},
|
||||||
|
isNew: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -703,6 +706,16 @@ func TestAddSpecialVerb(t *testing.T) {
|
|||||||
t.Errorf("missing expected verb: %s", tc.verb)
|
t.Errorf("missing expected verb: %s", tc.verb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tc.isNew {
|
||||||
|
if len(resources) != 1 {
|
||||||
|
t.Errorf("new verb should only contain one resource resources:%#v", resources)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(tc.resource, resources[0]) {
|
||||||
|
t.Errorf("miss expected resource:%#v", tc.resource)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
if reflect.DeepEqual(tc.resource, res) {
|
if reflect.DeepEqual(tc.resource, res) {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user