github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/azure/functions/concat_test.go (about)

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func Test_StringConcatenation(t *testing.T) {
    10  	tests := []struct {
    11  		name     string
    12  		args     []interface{}
    13  		expected string
    14  	}{
    15  		{
    16  			name: "simple string concatenation",
    17  			args: []interface{}{
    18  				"hello",
    19  				", ",
    20  				"world",
    21  				"!",
    22  			},
    23  			expected: "hello, world!",
    24  		},
    25  		{
    26  			name: "string concatenation with non strings",
    27  			args: []interface{}{
    28  				"pi to 3 decimal places is ",
    29  				3.142,
    30  			},
    31  			expected: "pi to 3 decimal places is 3.142",
    32  		},
    33  		{
    34  			name: "string concatenation with multiple primitives",
    35  			args: []interface{}{
    36  				"to say that ",
    37  				3,
    38  				" is greater than ",
    39  				5,
    40  				" would be ",
    41  				false,
    42  			},
    43  			expected: "to say that 3 is greater than 5 would be false",
    44  		},
    45  	}
    46  
    47  	for _, tt := range tests {
    48  		t.Run(tt.name, func(t *testing.T) {
    49  			concatenated := Concat(tt.args...)
    50  			require.Equal(t, tt.expected, concatenated)
    51  		})
    52  	}
    53  }
    54  
    55  func Test_ArrayConcatenation(t *testing.T) {
    56  	tests := []struct {
    57  		name     string
    58  		args     []interface{}
    59  		expected []interface{}
    60  	}{
    61  		{
    62  			name: "simple array concatenation",
    63  			args: []interface{}{
    64  				[]interface{}{1, 2, 3},
    65  				[]interface{}{4, 5, 6},
    66  			},
    67  			expected: []interface{}{1, 2, 3, 4, 5, 6},
    68  		},
    69  		{
    70  			name: "array concatenation with non arrays",
    71  			args: []interface{}{
    72  				[]interface{}{1, 2, 3},
    73  				4,
    74  			},
    75  			expected: []interface{}{1, 2, 3},
    76  		},
    77  		{
    78  			name: "array concatenation with multiple primitives",
    79  			args: []interface{}{
    80  				[]interface{}{1, 2, 3},
    81  				4,
    82  				[]interface{}{5, 6, 7},
    83  			},
    84  			expected: []interface{}{1, 2, 3, 5, 6, 7},
    85  		},
    86  	}
    87  
    88  	for _, tt := range tests {
    89  		t.Run(tt.name, func(t *testing.T) {
    90  			concatenated := Concat(tt.args...)
    91  			require.Equal(t, tt.expected, concatenated)
    92  		})
    93  	}
    94  }