forked from go-ozzo/ozzo-validation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnot_in_test.go
116 lines (107 loc) · 1.47 KB
/
not_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2016 Qiang Xue, Google LLC. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package validation
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNotIn(t *testing.T) {
v := 1
var v2 *int
var tests = []struct {
tag string
values []any
value any
err string
}{
{
"t0",
[]any{
1,
2,
},
0,
"",
},
{
"t1",
[]any{
1,
2,
},
1,
"must not be in list",
},
{
"t2",
[]any{
1,
2,
},
2,
"must not be in list",
},
{
"t3",
[]any{
1,
2,
},
3,
"",
},
{
"t4",
[]any{},
3,
"",
},
{
"t5",
[]any{
1,
2,
},
"1",
"",
},
{
"t6",
[]any{
1,
2,
},
&v,
"must not be in list",
},
{
"t7",
[]any{
1,
2,
},
v2,
"",
},
}
for _, test := range tests {
r := NotIn(test.values...)
err := r.Validate(test.value)
assertError(t, test.err, err, test.tag)
}
}
func Test_NotInRule_Error(t *testing.T) {
r := NotIn(1, 2, 3)
assert.Equal(t, "must not be in list", r.Validate(1).Error())
r = r.Error("123")
assert.Equal(t, "123", r.err.Message())
}
func TestNotInRule_ErrorObject(t *testing.T) {
r := NotIn(1, 2, 3)
err := NewError("code", "abc")
r = r.ErrorObject(err)
assert.Equal(t, err, r.err)
assert.Equal(t, err.Code(), r.err.Code())
assert.Equal(t, err.Message(), r.err.Message())
}