github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/union_test.go (about) 1 package functions 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_Union(t *testing.T) { 10 tests := []struct { 11 name string 12 args []interface{} 13 expected interface{} 14 }{ 15 { 16 name: "union single array", 17 args: []interface{}{ 18 []interface{}{"a", "b", "c"}, 19 }, 20 expected: []interface{}{"a", "b", "c"}, 21 }, 22 { 23 name: "union two arrays", 24 args: []interface{}{ 25 []interface{}{"a", "b", "c"}, 26 []interface{}{"b", "c", "d"}, 27 }, 28 expected: []interface{}{"a", "b", "c", "d"}, 29 }, 30 { 31 name: "union two arrays", 32 args: []interface{}{ 33 []interface{}{"a", "b", "c"}, 34 []interface{}{"b", "c", "d"}, 35 []interface{}{"b", "c", "d", "e"}, 36 }, 37 expected: []interface{}{"a", "b", "c", "d", "e"}, 38 }, 39 { 40 name: "union single maps", 41 args: []interface{}{ 42 map[string]interface{}{ 43 "a": "a", 44 "b": "b", 45 "c": "c", 46 }, 47 }, 48 expected: map[string]interface{}{ 49 "a": "a", 50 "b": "b", 51 "c": "c", 52 }, 53 }, 54 { 55 name: "union two maps", 56 args: []interface{}{ 57 map[string]interface{}{ 58 "a": "a", 59 "b": "b", 60 "c": "c", 61 }, 62 map[string]interface{}{ 63 "b": "b", 64 "c": "c", 65 "d": "d", 66 }, 67 }, 68 expected: map[string]interface{}{ 69 "a": "a", 70 "b": "b", 71 "c": "c", 72 "d": "d", 73 }, 74 }, 75 { 76 name: "union three maps", 77 args: []interface{}{ 78 map[string]interface{}{ 79 "a": "a", 80 "b": "b", 81 "c": "c", 82 }, 83 map[string]interface{}{ 84 "b": "b", 85 "c": "c", 86 "d": "d", 87 }, 88 map[string]interface{}{ 89 "b": "b", 90 "c": "c", 91 "e": "e", 92 }, 93 }, 94 expected: map[string]interface{}{ 95 "a": "a", 96 "b": "b", 97 "c": "c", 98 "d": "d", 99 "e": "e", 100 }, 101 }, 102 } 103 104 for _, tt := range tests { 105 t.Run(tt.name, func(t *testing.T) { 106 actual := Union(tt.args...) 107 assert.Equal(t, tt.expected, actual) 108 }) 109 } 110 }