github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/contains_test.go (about) 1 package functions 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func Test_Contains(t *testing.T) { 10 tests := []struct { 11 name string 12 args []interface{} 13 expected bool 14 }{ 15 { 16 name: "simple true string contains", 17 args: []interface{}{ 18 "hello, world", 19 "hell", 20 }, 21 expected: true, 22 }, 23 { 24 name: "simple false string contains", 25 args: []interface{}{ 26 "hello, world", 27 "help", 28 }, 29 expected: false, 30 }, 31 { 32 name: "simple true string contains with case sensitivity", 33 args: []interface{}{ 34 "hello, world", 35 "HELL", 36 }, 37 expected: true, 38 }, 39 { 40 name: "simple true string contains with number", 41 args: []interface{}{ 42 "You're my number 1", 43 1, 44 }, 45 expected: true, 46 }, 47 { 48 name: "true object contains key", 49 args: []interface{}{ 50 map[string]interface{}{ 51 "hello": "world", 52 }, 53 "hello", 54 }, 55 expected: true, 56 }, 57 { 58 name: "false object contains key", 59 args: []interface{}{ 60 map[string]interface{}{ 61 "hello": "world", 62 }, 63 "world", 64 }, 65 expected: false, 66 }, 67 { 68 name: "true array contains value", 69 args: []interface{}{ 70 []interface{}{ 71 "hello", "world", 72 }, 73 "hello", 74 }, 75 expected: true, 76 }, 77 { 78 name: "false array contains value", 79 args: []interface{}{ 80 []interface{}{ 81 "hello", "world", 82 }, 83 "help", 84 }, 85 expected: false, 86 }, 87 } 88 89 for _, tt := range tests { 90 t.Run(tt.name, func(t *testing.T) { 91 doesContain := Contains(tt.args...) 92 require.Equal(t, tt.expected, doesContain) 93 }) 94 } 95 }