github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/coalesce_test.go (about) 1 package functions 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_Coalesce(t *testing.T) { 10 tests := []struct { 11 name string 12 args []interface{} 13 expected interface{} 14 }{ 15 { 16 name: "coalesce with nil", 17 args: []interface{}{ 18 nil, 19 }, 20 expected: nil, 21 }, 22 { 23 name: "coalesce with nil and string", 24 args: []interface{}{ 25 nil, 26 "test", 27 }, 28 expected: "test", 29 }, 30 { 31 name: "coalesce with nil and string and int", 32 args: []interface{}{ 33 nil, 34 "test", 35 1, 36 }, 37 expected: "test", 38 }, 39 { 40 name: "coalesce with nil and nil and array", 41 args: []interface{}{ 42 nil, 43 nil, 44 []interface{}{"a", "b", "c"}, 45 }, 46 expected: []interface{}{"a", "b", "c"}, 47 }, 48 } 49 50 for _, tt := range tests { 51 t.Run(tt.name, func(t *testing.T) { 52 actual := Coalesce(tt.args...) 53 assert.Equal(t, tt.expected, actual) 54 }) 55 } 56 }