-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_test.go
50 lines (42 loc) · 983 Bytes
/
validate_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
package validate
import (
"testing"
)
type C struct {
A string `validate:"notnull"`
B string `validate:"notnull,notempty"`
C string `validate:"nospace"`
D string `validate:"nospace,email"`
}
type M struct {
A string `validate:"notnull"`
B string `validate:"notnull,notempty"`
C C `validate:"xx"`
}
func TestValidate(t *testing.T) {
c := M{A: "N", B: "X", C: C{A: "", B: "", C: " ", D: "[email protected]"}}
errs := Validate(c)
if len(errs) == 0 {
t.Error("none strict mode not equals 0")
}
StrictMode(true)
c = M{A: "N", B: "X", C: C{A: "X", B: "B", C: "C", D: "[email protected]"}}
errs = Validate(c)
if len(errs) != 1 {
t.Error("strict mode error not equals 1")
}
}
func TestValidators(t *testing.T) {
var c = C{}
StrictMode(false)
c = C{A: "", B: "x", C: "", D: "[email protected]"}
errs := Validate(c)
if len(errs) != 0 {
t.Error("Errors must be 0")
}
c = C{A: "", B: "", C: " ", D: "[email protected]"}
errs = Validate(c)
if len(errs) != 2 {
t.Error("Errors must be 2")
}
}