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