github.com/aquasecurity/trivy-iac@v0.8.1-0.20240127024015-3d8e412cf0ab/pkg/scanners/azure/functions/less_test.go (about) 1 package functions 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func Test_Less(t *testing.T) { 10 tests := []struct { 11 name string 12 args []interface{} 13 expected interface{} 14 }{ 15 16 { 17 name: "less with nil and string", 18 args: []interface{}{ 19 nil, 20 "test", 21 }, 22 expected: false, 23 }, 24 { 25 name: "less with nil and nil", 26 args: []interface{}{ 27 nil, 28 nil, 29 }, 30 expected: false, 31 }, 32 { 33 name: "less with string and string", 34 args: []interface{}{ 35 "test", 36 "test", 37 }, 38 expected: false, 39 }, 40 { 41 name: "less with string and int", 42 args: []interface{}{ 43 "test", 44 1, 45 }, 46 expected: false, 47 }, 48 { 49 name: "less with int and int", 50 args: []interface{}{ 51 1, 52 1, 53 }, 54 expected: false, 55 }, 56 } 57 for _, tt := range tests { 58 t.Run(tt.name, func(t *testing.T) { 59 actual := Less(tt.args...) 60 assert.Equal(t, tt.expected, actual) 61 }) 62 } 63 } 64 65 func Test_LessThanOrEqual(t *testing.T) { 66 tests := []struct { 67 name string 68 args []interface{} 69 expected interface{} 70 }{ 71 72 { 73 name: "less with nil and string", 74 args: []interface{}{ 75 nil, 76 "test", 77 }, 78 expected: false, 79 }, 80 { 81 name: "less with nil and nil", 82 args: []interface{}{ 83 nil, 84 nil, 85 }, 86 expected: true, 87 }, 88 { 89 name: "less with string and string", 90 args: []interface{}{ 91 "test", 92 "test", 93 }, 94 expected: true, 95 }, 96 { 97 name: "less with string and int", 98 args: []interface{}{ 99 "test", 100 1, 101 }, 102 expected: false, 103 }, 104 { 105 name: "less with int and int", 106 args: []interface{}{ 107 1, 108 1, 109 }, 110 expected: true, 111 }, 112 } 113 for _, tt := range tests { 114 t.Run(tt.name, func(t *testing.T) { 115 actual := LessOrEquals(tt.args...) 116 assert.Equal(t, tt.expected, actual) 117 }) 118 } 119 }