added CanSkipAlso

This commit is contained in:
Andrea Spacca
2018-02-02 10:22:43 +01:00
parent 453f112094
commit 5ed112e946
2 changed files with 59 additions and 5 deletions

View File

@@ -490,8 +490,8 @@ func TestPointer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !b {
t.Fatal("validation should be passed")
if b {
t.Fatal("validation should not be passed")
}
invalidEmail := "a@a"
@@ -523,3 +523,41 @@ func TestPointer(t *testing.T) {
t.Fatal("validation should not be passed")
}
}
func TestCanSkipAlso(t *testing.T) {
type User struct {
ID int
Email string `valid:"Email"`
ReqEmail string `valid:"Required;Email"`
MatchRange int `valid:"Range(10, 20)"`
}
u := User{
ReqEmail: "a@a.com",
Email: "",
MatchRange: 0,
}
valid := Validation{RequiredFirst: true}
b, err := valid.Valid(u)
if err != nil {
t.Fatal(err)
}
if b {
t.Fatal("validation should not be passed")
}
valid = Validation{RequiredFirst: true}
valid.CanSkipAlso("Range")
b, err = valid.Valid(u)
if err != nil {
t.Fatal(err)
}
if !b {
t.Fatal("validation should be passed")
}
}