@@ -118,12 +118,22 @@ func (t *testCase) expandResourceAttributes() []authv1.ResourceAttributes {
118
118
verbExpansions := make ([]authv1.ResourceAttributes , 0 )
119
119
if len (t .data .verbs ) > 0 {
120
120
for _ , verb := range t .data .verbs {
121
- for _ , ra := range ras {
122
- // copy the ResourceAttributes object to avoid modifying the original object
123
- // and make it safe to user in the next iterations
124
- copy := ra
125
- copy .Verb = verb
126
- verbExpansions = append (verbExpansions , copy )
121
+ // If an expansion already take place, we need to copy and
122
+ // change the existing objects
123
+ if len (ras ) > 0 {
124
+ for _ , ra := range ras {
125
+ // copy the ResourceAttributes object to avoid modifying the original object
126
+ // and make it safe to user in the next iterations
127
+ copy := ra
128
+ copy .Verb = verb
129
+ verbExpansions = append (verbExpansions , copy )
130
+ }
131
+ } else {
132
+ // If no expansion has taken place, we need to create a new object
133
+ ra := authv1.ResourceAttributes {
134
+ Verb : verb ,
135
+ }
136
+ verbExpansions = append (verbExpansions , ra )
127
137
}
128
138
}
129
139
// we update the expanded list with verb expansions
@@ -134,10 +144,17 @@ func (t *testCase) expandResourceAttributes() []authv1.ResourceAttributes {
134
144
apiGroupExpansions := make ([]authv1.ResourceAttributes , 0 )
135
145
if len (t .data .apiGroups ) > 0 {
136
146
for _ , apiGroup := range t .data .apiGroups {
137
- for _ , ra := range ras {
138
- copy := ra
139
- copy .Group = apiGroup
140
- apiGroupExpansions = append (apiGroupExpansions , copy )
147
+ if len (ras ) > 0 {
148
+ for _ , ra := range ras {
149
+ copy := ra
150
+ copy .Group = apiGroup
151
+ apiGroupExpansions = append (apiGroupExpansions , copy )
152
+ }
153
+ } else {
154
+ ra := authv1.ResourceAttributes {
155
+ Group : apiGroup ,
156
+ }
157
+ apiGroupExpansions = append (apiGroupExpansions , ra )
141
158
}
142
159
}
143
160
// we update the expanded list with apiGroup expansions
@@ -148,24 +165,44 @@ func (t *testCase) expandResourceAttributes() []authv1.ResourceAttributes {
148
165
resourceExpansions := make ([]authv1.ResourceAttributes , 0 )
149
166
if len (t .data .resources ) > 0 {
150
167
for _ , resource := range t .data .resources {
151
- for _ , ra := range ras {
152
- copy := ra
168
+ if len (ras ) > 0 {
169
+ for _ , ra := range ras {
170
+ copy := ra
171
+ // split the resource string to get the group, resource and subresource
172
+ parts := strings .Split (resource , "/" )
173
+ if len (parts ) > 1 {
174
+ switch len (parts ) {
175
+ case 2 :
176
+ copy .Group = parts [0 ]
177
+ copy .Resource = parts [1 ]
178
+ case 3 :
179
+ copy .Group = parts [0 ]
180
+ copy .Resource = parts [1 ]
181
+ copy .Subresource = parts [2 ]
182
+ }
183
+ } else {
184
+ copy .Resource = parts [0 ]
185
+ }
186
+ resourceExpansions = append (resourceExpansions , copy )
187
+ }
188
+ } else {
189
+ ra := authv1.ResourceAttributes {}
153
190
// split the resource string to get the group, resource and subresource
154
191
parts := strings .Split (resource , "/" )
155
192
if len (parts ) > 1 {
156
193
switch len (parts ) {
157
194
case 2 :
158
- copy .Group = parts [0 ]
159
- copy .Resource = parts [1 ]
195
+ ra .Group = parts [0 ]
196
+ ra .Resource = parts [1 ]
160
197
case 3 :
161
- copy .Group = parts [0 ]
162
- copy .Resource = parts [1 ]
163
- copy .Subresource = parts [2 ]
198
+ ra .Group = parts [0 ]
199
+ ra .Resource = parts [1 ]
200
+ ra .Subresource = parts [2 ]
164
201
}
165
202
} else {
166
- copy .Resource = parts [0 ]
203
+ ra .Resource = parts [0 ]
167
204
}
168
- resourceExpansions = append (resourceExpansions , copy )
205
+ resourceExpansions = append (resourceExpansions , ra )
169
206
}
170
207
}
171
208
// we update the expanded list with resource expansions
@@ -176,10 +213,17 @@ func (t *testCase) expandResourceAttributes() []authv1.ResourceAttributes {
176
213
subresourceExpansions := make ([]authv1.ResourceAttributes , 0 )
177
214
if len (t .data .subresources ) > 0 {
178
215
for _ , subresource := range t .data .subresources {
179
- for _ , ra := range ras {
180
- copy := ra
181
- copy .Subresource = subresource
182
- subresourceExpansions = append (subresourceExpansions , copy )
216
+ if len (ras ) > 0 {
217
+ for _ , ra := range ras {
218
+ copy := ra
219
+ copy .Subresource = subresource
220
+ subresourceExpansions = append (subresourceExpansions , copy )
221
+ }
222
+ } else {
223
+ ra := authv1.ResourceAttributes {
224
+ Subresource : subresource ,
225
+ }
226
+ subresourceExpansions = append (subresourceExpansions , ra )
183
227
}
184
228
}
185
229
// we update the expanded list with subresource expansions
@@ -190,10 +234,17 @@ func (t *testCase) expandResourceAttributes() []authv1.ResourceAttributes {
190
234
nameExpansions := make ([]authv1.ResourceAttributes , 0 )
191
235
if len (t .data .names ) > 0 {
192
236
for _ , name := range t .data .names {
193
- for _ , ra := range ras {
194
- copy := ra
195
- copy .Name = name
196
- nameExpansions = append (nameExpansions , copy )
237
+ if len (ras ) > 0 {
238
+ for _ , ra := range ras {
239
+ copy := ra
240
+ copy .Name = name
241
+ nameExpansions = append (nameExpansions , copy )
242
+ }
243
+ } else {
244
+ ra := authv1.ResourceAttributes {
245
+ Name : name ,
246
+ }
247
+ nameExpansions = append (nameExpansions , ra )
197
248
}
198
249
}
199
250
// we update the expanded list with name expansions
0 commit comments