github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/cloudformation/parser/fn_if_test.go (about)

     1  package parser
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/aquasecurity/defsec/pkg/types"
     7  
     8  	"github.com/aquasecurity/trivy-iac/pkg/scanners/cloudformation/cftypes"
     9  
    10  	"github.com/stretchr/testify/assert"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  func Test_resolve_if_value(t *testing.T) {
    15  
    16  	property := &Property{
    17  		ctx:  &FileContext{},
    18  		name: "BucketName",
    19  		rng:  types.NewRange("testfile", 1, 1, "", nil),
    20  		Inner: PropertyInner{
    21  			Type: cftypes.Map,
    22  			Value: map[string]*Property{
    23  				"Fn::If": {
    24  					Inner: PropertyInner{
    25  						Type: cftypes.List,
    26  						Value: []*Property{
    27  							{
    28  								Inner: PropertyInner{
    29  									Type:  cftypes.Bool,
    30  									Value: true,
    31  								},
    32  							},
    33  							{
    34  								Inner: PropertyInner{
    35  									Type:  cftypes.String,
    36  									Value: "foo",
    37  								},
    38  							},
    39  							{
    40  								Inner: PropertyInner{
    41  									Type:  cftypes.String,
    42  									Value: "bar",
    43  								},
    44  							},
    45  						},
    46  					},
    47  				},
    48  			},
    49  		},
    50  	}
    51  
    52  	resolvedProperty, success := ResolveIntrinsicFunc(property)
    53  	require.True(t, success)
    54  
    55  	assert.Equal(t, "foo", resolvedProperty.String())
    56  }