@@ -213,49 +213,62 @@ func Test_Run(t *testing.T) {
213
213
},
214
214
}
215
215
tests := []struct {
216
- inputFieldPath string
217
- expectRunError bool
218
- expectKeywords []string
216
+ inputFieldPath string
217
+ disablePrintPath bool
218
+ showBrackets bool
219
+ expectRunError bool
220
+ expectKeywords []string
221
+ unexpectKeywords []string
219
222
}{
220
223
{
221
- inputFieldPath : "no.*pro" ,
222
- expectRunError : false ,
224
+ inputFieldPath : "no.*pro" ,
225
+ disablePrintPath : false ,
226
+ showBrackets : false ,
227
+ expectRunError : false ,
223
228
expectKeywords : []string {
224
229
"Node" ,
225
230
"providerID" ,
226
231
"PATH: nodes.spec.providerID" ,
227
232
},
228
233
},
229
234
{
230
- inputFieldPath : "node.*pro" ,
231
- expectRunError : false ,
235
+ inputFieldPath : "node.*pro" ,
236
+ disablePrintPath : false ,
237
+ showBrackets : false ,
238
+ expectRunError : false ,
232
239
expectKeywords : []string {
233
240
"Node" ,
234
241
"providerID" ,
235
242
"PATH: nodes.spec.providerID" ,
236
243
},
237
244
},
238
245
{
239
- inputFieldPath : "nodes.*pro" ,
240
- expectRunError : false ,
246
+ inputFieldPath : "nodes.*pro" ,
247
+ disablePrintPath : false ,
248
+ showBrackets : false ,
249
+ expectRunError : false ,
241
250
expectKeywords : []string {
242
251
"Node" ,
243
252
"providerID" ,
244
253
"PATH: nodes.spec.providerID" ,
245
254
},
246
255
},
247
256
{
248
- inputFieldPath : "providerID" ,
249
- expectRunError : false ,
257
+ inputFieldPath : "providerID" ,
258
+ disablePrintPath : false ,
259
+ showBrackets : false ,
260
+ expectRunError : false ,
250
261
expectKeywords : []string {
251
262
"Node" ,
252
263
"providerID" ,
253
264
"PATH: nodes.spec.providerID" ,
254
265
},
255
266
},
256
267
{
257
- inputFieldPath : "hpa.*own.*id" ,
258
- expectRunError : false ,
268
+ inputFieldPath : "hpa.*own.*id" ,
269
+ disablePrintPath : false ,
270
+ showBrackets : false ,
271
+ expectRunError : false ,
259
272
expectKeywords : []string {
260
273
"autoscaling" ,
261
274
"HorizontalPodAutoscaler" ,
@@ -264,8 +277,10 @@ func Test_Run(t *testing.T) {
264
277
},
265
278
},
266
279
{
267
- inputFieldPath : "horizontalpodautoscalers.*own.*id" ,
268
- expectRunError : false ,
280
+ inputFieldPath : "horizontalpodautoscalers.*own.*id" ,
281
+ disablePrintPath : false ,
282
+ showBrackets : false ,
283
+ expectRunError : false ,
269
284
expectKeywords : []string {
270
285
"autoscaling" ,
271
286
"HorizontalPodAutoscaler" ,
@@ -274,8 +289,10 @@ func Test_Run(t *testing.T) {
274
289
},
275
290
},
276
291
{
277
- inputFieldPath : "horizontalpodautoscaler.*own.*id" ,
278
- expectRunError : false ,
292
+ inputFieldPath : "horizontalpodautoscaler.*own.*id" ,
293
+ disablePrintPath : false ,
294
+ showBrackets : false ,
295
+ expectRunError : false ,
279
296
expectKeywords : []string {
280
297
"autoscaling" ,
281
298
"HorizontalPodAutoscaler" ,
@@ -284,8 +301,10 @@ func Test_Run(t *testing.T) {
284
301
},
285
302
},
286
303
{
287
- inputFieldPath : "csistoragecapacity.maximumVolumeSize" ,
288
- expectRunError : false ,
304
+ inputFieldPath : "csistoragecapacity.maximumVolumeSize" ,
305
+ disablePrintPath : false ,
306
+ showBrackets : false ,
307
+ expectRunError : false ,
289
308
expectKeywords : []string {
290
309
"CSIStorageCapacity" ,
291
310
"storage.k8s.io" ,
@@ -294,8 +313,10 @@ func Test_Run(t *testing.T) {
294
313
},
295
314
},
296
315
{
297
- inputFieldPath : "csistoragecapacities.maximumVolumeSize" ,
298
- expectRunError : false ,
316
+ inputFieldPath : "csistoragecapacities.maximumVolumeSize" ,
317
+ disablePrintPath : false ,
318
+ showBrackets : false ,
319
+ expectRunError : false ,
299
320
expectKeywords : []string {
300
321
"CSIStorageCapacity" ,
301
322
"storage.k8s.io" ,
@@ -304,19 +325,52 @@ func Test_Run(t *testing.T) {
304
325
},
305
326
},
306
327
{
307
- inputFieldPath : "CSIStorageCapacity.*VolumeSize" ,
308
- expectRunError : false ,
328
+ inputFieldPath : "CSIStorageCapacity.*VolumeSize" ,
329
+ disablePrintPath : false ,
330
+ showBrackets : false ,
331
+ expectRunError : false ,
309
332
expectKeywords : []string {
310
333
"CSIStorageCapacity" ,
311
334
"storage.k8s.io" ,
312
335
"v1" ,
313
336
"PATH: csistoragecapacities.maximumVolumeSize" ,
314
337
},
315
338
},
339
+ {
340
+ inputFieldPath : "nodes.status.conditions.type" ,
341
+ disablePrintPath : false ,
342
+ showBrackets : true ,
343
+ expectRunError : false ,
344
+ expectKeywords : []string {
345
+ "Node" ,
346
+ "type" ,
347
+ "PATH: nodes.status.conditions[].type" ,
348
+ },
349
+ },
350
+ {
351
+ inputFieldPath : "nodes.status.conditions.type" ,
352
+ disablePrintPath : true ,
353
+ showBrackets : true ,
354
+ expectRunError : false ,
355
+ expectKeywords : []string {
356
+ "Node" ,
357
+ "type" ,
358
+ },
359
+ unexpectKeywords : []string {
360
+ "PATH: nodes.status.conditions[].type" ,
361
+ "PATH: nodes.status.conditions.type" ,
362
+ },
363
+ },
316
364
}
317
365
for _ , tt := range tests {
318
366
for _ , version := range k8sVersions {
319
- t .Run (fmt .Sprintf ("version: %s inputFieldPath: %s" , version , tt .inputFieldPath ), func (t * testing.T ) {
367
+ t .Run (fmt .Sprintf (
368
+ "version: %s inputFieldPath: %s, disablePrintPath: %v, showBrackets: %v" ,
369
+ version ,
370
+ tt .inputFieldPath ,
371
+ tt .disablePrintPath ,
372
+ tt .showBrackets ,
373
+ ), func (t * testing.T ) {
320
374
fakeServer := fakeServers [version ]
321
375
fakeDiscoveryClient := discovery .NewDiscoveryClientForConfigOrDie (& rest.Config {Host : fakeServer .HttpServer .URL })
322
376
tf := cmdtesting .NewTestFactory ()
@@ -338,6 +392,8 @@ func Test_Run(t *testing.T) {
338
392
Out : & stdout ,
339
393
ErrOut : & errout ,
340
394
})
395
+ explore .SetDisablePrintPath (opts , tt .disablePrintPath )
396
+ explore .SetShowBrackets (opts , tt .showBrackets )
341
397
require .NoError (t , opts .Complete (tf , []string {tt .inputFieldPath }))
342
398
err := opts .Run ()
343
399
if tt .expectRunError {
@@ -348,6 +404,9 @@ func Test_Run(t *testing.T) {
348
404
for _ , keyword := range tt .expectKeywords {
349
405
require .Contains (t , stdout .String (), keyword )
350
406
}
407
+ for _ , keyword := range tt .unexpectKeywords {
408
+ require .NotContains (t , stdout .String (), keyword )
409
+ }
351
410
})
352
411
}
353
412
}
0 commit comments