github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/internal/adapters/terraform/aws/apigateway/namesv2_test.go (about) 1 package apigateway 2 3 import ( 4 "testing" 5 6 v2 "github.com/aquasecurity/defsec/pkg/providers/aws/apigateway/v2" 7 "github.com/aquasecurity/trivy-iac/internal/adapters/terraform/tftestutil" 8 "github.com/aquasecurity/trivy-iac/test/testutil" 9 ) 10 11 func Test_adaptDomainNamesV2(t *testing.T) { 12 tests := []struct { 13 name string 14 terraform string 15 expected []v2.DomainName 16 }{ 17 { 18 name: "defaults", 19 terraform: ` 20 resource "aws_apigatewayv2_domain_name" "example" { 21 } 22 `, 23 expected: []v2.DomainName{ 24 { 25 Name: String(""), 26 SecurityPolicy: String("TLS_1_0"), 27 }, 28 }, 29 }, 30 { 31 name: "fully populated", 32 terraform: ` 33 resource "aws_apigatewayv2_domain_name" "example" { 34 domain_name = "testing.com" 35 domain_name_configuration { 36 security_policy = "TLS_1_2" 37 } 38 } 39 `, 40 expected: []v2.DomainName{ 41 { 42 Name: String("testing.com"), 43 SecurityPolicy: String("TLS_1_2"), 44 }, 45 }, 46 }, 47 } 48 49 for _, test := range tests { 50 t.Run(test.name, func(t *testing.T) { 51 modules := tftestutil.CreateModulesFromSource(t, test.terraform, ".tf") 52 adapted := adaptDomainNamesV2(modules) 53 testutil.AssertDefsecEqual(t, test.expected, adapted) 54 }) 55 } 56 }