@@ -146,124 +146,157 @@ func Test_buildTags(t *testing.T) {
146
146
pvc .SetName ("my-pvc" )
147
147
148
148
tests := []struct {
149
- name string
150
- defaultTags map [string ]string
151
- annotations map [string ]string
152
- want map [string ]string
153
- tagFormat string
149
+ name string
150
+ defaultTags map [string ]string
151
+ allowAllTags bool
152
+ annotations map [string ]string
153
+ want map [string ]string
154
+ tagFormat string
154
155
}{
155
156
{
156
- name : "ignore annotation set" ,
157
- defaultTags : map [string ]string {},
158
- annotations : map [string ]string {"aws-ebs-tagger/ignore" : "" },
159
- want : map [string ]string {},
157
+ name : "ignore annotation set" ,
158
+ defaultTags : map [string ]string {},
159
+ allowAllTags : false ,
160
+ annotations : map [string ]string {"aws-ebs-tagger/ignore" : "" },
161
+ want : map [string ]string {},
162
+ },
163
+ {
164
+ name : "ignore annotation set with default tags" ,
165
+ defaultTags : map [string ]string {"foo" : "bar" },
166
+ allowAllTags : false ,
167
+ annotations : map [string ]string {"aws-ebs-tagger/ignore" : "" },
168
+ want : map [string ]string {},
169
+ },
170
+ {
171
+ name : "ignore annotation set with tags annotation set" ,
172
+ defaultTags : map [string ]string {},
173
+ allowAllTags : false ,
174
+ annotations : map [string ]string {"aws-ebs-tagger/ignore" : "exists" , "aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" }" },
175
+ want : map [string ]string {},
160
176
},
161
177
{
162
- name : "ignore annotation set with default tags" ,
163
- defaultTags : map [string ]string {"foo" : "bar" },
164
- annotations : map [string ]string {"aws-ebs-tagger/ignore" : "" },
165
- want : map [string ]string {},
178
+ name : "tags annotation not set with default tags" ,
179
+ defaultTags : map [string ]string {"foo" : "bar" , "something" : "else" },
180
+ allowAllTags : false ,
181
+ annotations : map [string ]string {},
182
+ want : map [string ]string {"foo" : "bar" , "something" : "else" },
166
183
},
167
184
{
168
- name : "ignore annotation set with tags annotation set" ,
169
- defaultTags : map [string ]string {},
170
- annotations : map [string ]string {"aws-ebs-tagger/ignore" : "exists" , "aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" }" },
171
- want : map [string ]string {},
185
+ name : "tags annotation not set with no default tags" ,
186
+ defaultTags : map [string ]string {},
187
+ allowAllTags : false ,
188
+ annotations : map [string ]string {},
189
+ want : map [string ]string {},
172
190
},
173
191
{
174
- name : "tags annotation not set with default tags" ,
175
- defaultTags : map [string ]string {"foo" : "bar" , "something" : "else" },
176
- annotations : map [string ]string {},
177
- want : map [string ]string {"foo" : "bar" , "something" : "else" },
192
+ name : "tags annotation set empty with no default tags" ,
193
+ defaultTags : map [string ]string {},
194
+ allowAllTags : false ,
195
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "" },
196
+ want : map [string ]string {},
178
197
},
179
198
{
180
- name : "tags annotation not set with no default tags" ,
181
- defaultTags : map [string ]string {},
182
- annotations : map [string ]string {},
183
- want : map [string ]string {},
199
+ name : "tags annotation set with no default tags" ,
200
+ defaultTags : map [string ]string {},
201
+ allowAllTags : false ,
202
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" }" },
203
+ want : map [string ]string {"foo" : "bar" },
184
204
},
185
205
{
186
- name : "tags annotation set empty with no default tags" ,
187
- defaultTags : map [string ]string {},
188
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "" },
189
- want : map [string ]string {},
206
+ name : "tags annotation set with default tags" ,
207
+ defaultTags : map [string ]string {"foo" : "bar" },
208
+ allowAllTags : false ,
209
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" something\" : \" else\" }" },
210
+ want : map [string ]string {"foo" : "bar" , "something" : "else" },
190
211
},
191
212
{
192
- name : "tags annotation set with no default tags" ,
193
- defaultTags : map [string ]string {},
194
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" }" },
195
- want : map [string ]string {"foo" : "bar" },
213
+ name : "tags annotation set with default tags with override" ,
214
+ defaultTags : map [string ]string {"foo" : "foo" },
215
+ allowAllTags : false ,
216
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" , \" something\" : \" else\" }" },
217
+ want : map [string ]string {"foo" : "bar" , "something" : "else" },
196
218
},
197
219
{
198
- name : "tags annotation set with default tags" ,
199
- defaultTags : map [string ]string {"foo" : "bar" },
200
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" something\" : \" else\" }" },
201
- want : map [string ]string {"foo" : "bar" , "something" : "else" },
220
+ name : "tags annotation invalid json with no default tags" ,
221
+ defaultTags : map [string ]string {},
222
+ allowAllTags : false ,
223
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "'asdas:\" asdasd\" " },
224
+ want : map [string ]string {},
202
225
},
203
226
{
204
- name : "tags annotation set with default tags with override" ,
205
- defaultTags : map [string ]string {"foo" : "foo" },
206
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" , \" something\" : \" else\" }" },
207
- want : map [string ]string {"foo" : "bar" , "something" : "else" },
227
+ name : "tags annotation invalid json with default tags" ,
228
+ defaultTags : map [string ]string {"foo" : "bar" },
229
+ allowAllTags : false ,
230
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "'asdas:\" asdasd\" " },
231
+ want : map [string ]string {"foo" : "bar" },
208
232
},
209
233
{
210
- name : "tags annotation invalid json with no default tags" ,
211
- defaultTags : map [string ]string {},
212
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "'asdas:\" asdasd\" " },
213
- want : map [string ]string {},
234
+ name : "tags annotation set with invalid name with no default tags" ,
235
+ defaultTags : map [string ]string {},
236
+ allowAllTags : false ,
237
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" , \" kubernetes.io/foo\" : \" bar\" }" },
238
+ want : map [string ]string {"foo" : "bar" },
214
239
},
215
240
{
216
- name : "tags annotation invalid json with default tags" ,
217
- defaultTags : map [string ]string {"foo" : "bar" },
218
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "'asdas:\" asdasd\" " },
219
- want : map [string ]string {"foo" : "bar" },
241
+ name : "tags annotation set with invalid name but allowAllTags with no default tags" ,
242
+ defaultTags : map [string ]string {},
243
+ allowAllTags : true ,
244
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" , \" kubernetes.io/foo\" : \" bar\" }" },
245
+ want : map [string ]string {"foo" : "bar" , "kubernetes.io/foo" : "bar" },
220
246
},
221
247
{
222
- name : "tags annotation set with invalid name with no default tags" ,
223
- defaultTags : map [string ]string {},
224
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" , \" kubernetes.io/foo\" : \" bar\" }" },
225
- want : map [string ]string {"foo" : "bar" },
248
+ name : "tags annotation set with invalid name but allowAllTags with no default tags" ,
249
+ defaultTags : map [string ]string {},
250
+ allowAllTags : true ,
251
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" , \" Name\" : \" bar\" }" },
252
+ want : map [string ]string {"foo" : "bar" , "Name" : "bar" },
226
253
},
227
254
{
228
- name : "tags annotation set with invalid default tags" ,
229
- defaultTags : map [string ]string {"kubernetes.io/foo" : "bar" },
230
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" something\" : \" else\" }" },
231
- want : map [string ]string {"something" : "else" },
255
+ name : "tags annotation set with invalid default tags" ,
256
+ defaultTags : map [string ]string {"kubernetes.io/foo" : "bar" },
257
+ allowAllTags : false ,
258
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" something\" : \" else\" }" },
259
+ want : map [string ]string {"something" : "else" },
232
260
},
233
261
{
234
- name : "tags annotation not set with default tags - csv" ,
235
- defaultTags : map [string ]string {"foo" : "bar" , "something" : "else" },
236
- annotations : map [string ]string {},
237
- want : map [string ]string {"foo" : "bar" , "something" : "else" },
238
- tagFormat : "csv" ,
262
+ name : "tags annotation not set with default tags - csv" ,
263
+ defaultTags : map [string ]string {"foo" : "bar" , "something" : "else" },
264
+ allowAllTags : false ,
265
+ annotations : map [string ]string {},
266
+ want : map [string ]string {"foo" : "bar" , "something" : "else" },
267
+ tagFormat : "csv" ,
239
268
},
240
269
{
241
- name : "tags annotation not set with no default tags - csv" ,
242
- defaultTags : map [string ]string {},
243
- annotations : map [string ]string {},
244
- want : map [string ]string {},
245
- tagFormat : "csv" ,
270
+ name : "tags annotation not set with no default tags - csv" ,
271
+ defaultTags : map [string ]string {},
272
+ allowAllTags : false ,
273
+ annotations : map [string ]string {},
274
+ want : map [string ]string {},
275
+ tagFormat : "csv" ,
246
276
},
247
277
{
248
- name : "tags annotation set with default tags - csv" ,
249
- defaultTags : map [string ]string {"foo" : "bar" },
250
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "something=else" },
251
- want : map [string ]string {"foo" : "bar" , "something" : "else" },
252
- tagFormat : "csv" ,
278
+ name : "tags annotation set with default tags - csv" ,
279
+ defaultTags : map [string ]string {"foo" : "bar" },
280
+ allowAllTags : false ,
281
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "something=else" },
282
+ want : map [string ]string {"foo" : "bar" , "something" : "else" },
283
+ tagFormat : "csv" ,
253
284
},
254
285
{
255
- name : "tags annotation set with default tags with override - csv" ,
256
- defaultTags : map [string ]string {"foo" : "foo" },
257
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "foo=bar,something=else" },
258
- want : map [string ]string {"foo" : "bar" , "something" : "else" },
259
- tagFormat : "csv" ,
286
+ name : "tags annotation set with default tags with override - csv" ,
287
+ defaultTags : map [string ]string {"foo" : "foo" },
288
+ allowAllTags : false ,
289
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "foo=bar,something=else" },
290
+ want : map [string ]string {"foo" : "bar" , "something" : "else" },
291
+ tagFormat : "csv" ,
260
292
},
261
293
{
262
- name : "tags annotation set with invalid tags - csv" ,
263
- defaultTags : map [string ]string {},
264
- annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" }" },
265
- want : map [string ]string {},
266
- tagFormat : "csv" ,
294
+ name : "tags annotation set with invalid tags - csv" ,
295
+ defaultTags : map [string ]string {},
296
+ allowAllTags : false ,
297
+ annotations : map [string ]string {"aws-ebs-tagger/tags" : "{\" foo\" : \" bar\" }" },
298
+ want : map [string ]string {},
299
+ tagFormat : "csv" ,
267
300
},
268
301
269
302
// foo=bar,something=else
@@ -272,6 +305,7 @@ func Test_buildTags(t *testing.T) {
272
305
t .Run (tt .name , func (t * testing.T ) {
273
306
pvc .SetAnnotations (tt .annotations )
274
307
defaultTags = tt .defaultTags
308
+ allowAllTags = tt .allowAllTags
275
309
if tt .tagFormat != "" {
276
310
tagFormat = tt .tagFormat
277
311
} else {
0 commit comments