@@ -409,3 +409,49 @@ func TestFilterAndListValues(t *testing.T) {
409
409
})
410
410
}
411
411
}
412
+
413
+ func TestBuildComponentYqExpression (t * testing.T ) {
414
+ tests := []struct {
415
+ name string
416
+ component string
417
+ includeAbstract bool
418
+ componentType string
419
+ expected string
420
+ }{
421
+ {
422
+ name : "basic component without including abstract" ,
423
+ component : "vpc" ,
424
+ includeAbstract : false ,
425
+ componentType : "terraform" ,
426
+ expected : ".components.terraform.\" vpc\" | select(has(\" abstract\" ) == false or .abstract == false) | .vars" ,
427
+ },
428
+ {
429
+ name : "basic component including abstract" ,
430
+ component : "vpc" ,
431
+ includeAbstract : true ,
432
+ componentType : "terraform" ,
433
+ expected : ".components.terraform.\" vpc\" | .vars" ,
434
+ },
435
+ {
436
+ name : "nested component without including abstract" ,
437
+ component : "nested/vpc" ,
438
+ includeAbstract : false ,
439
+ componentType : "terraform" ,
440
+ expected : ".components.terraform.\" nested/vpc\" | select(has(\" abstract\" ) == false or .abstract == false) | .vars" ,
441
+ },
442
+ {
443
+ name : "helmfile component" ,
444
+ component : "nginx" ,
445
+ includeAbstract : false ,
446
+ componentType : "helmfile" ,
447
+ expected : ".components.helmfile.\" nginx\" | select(has(\" abstract\" ) == false or .abstract == false) | .vars" ,
448
+ },
449
+ }
450
+
451
+ for _ , tt := range tests {
452
+ t .Run (tt .name , func (t * testing.T ) {
453
+ result := buildComponentYqExpression (tt .component , tt .includeAbstract , tt .componentType )
454
+ assert .Equal (t , tt .expected , result )
455
+ })
456
+ }
457
+ }
0 commit comments