forked from rezakhademix/govalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
in_test.go
65 lines (60 loc) · 1.62 KB
/
in_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package govalidator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_In(t *testing.T) {
tests := []struct {
name string
value any
acceptableValues []any
expectedResult bool
}{
{
name: "test integer value of `4` does not exist in acceptable values",
value: 4,
acceptableValues: []any{1, 2, 3},
expectedResult: false,
},
{
name: "test string value of `redis` does not exist in acceptable values",
value: "redis",
acceptableValues: []any{"mysql", "mariadb", "postgres"},
expectedResult: false,
},
{
name: "test empty string value does not exist in acceptable values",
value: "",
acceptableValues: []any{"pen", "pencil", "pipe"},
expectedResult: false,
},
{
name: "test empty space string value does not exist in acceptable values",
value: " ",
acceptableValues: []any{"joe", "jane", "john"},
expectedResult: false,
},
{
name: "test integer value of `20` exists in acceptable values",
value: 20,
acceptableValues: []any{10, 20, 30},
expectedResult: true,
},
{
name: "test string value of `go` exists in acceptable values",
value: "go",
acceptableValues: []any{"go", "php", "java"},
expectedResult: true,
},
}
for _, test := range tests {
result := In(test.value, test.acceptableValues...)
assert.Equalf(
t,
test.expectedResult,
result,
"test case %q failed: expected: %s, got: %s",
test.name, test.expectedResult, result,
)
}
}