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

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