mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 18:50:50 +00:00
Fix after test failure
This commit is contained in:
parent
ee9cf05796
commit
faa3341603
@ -245,9 +245,14 @@ func (v *Validation) ZipCode(obj interface{}, key string) *Result {
|
||||
}
|
||||
|
||||
func (v *Validation) apply(chk Validator, obj interface{}) *Result {
|
||||
if reflect.TypeOf(obj).Kind() == reflect.Ptr {
|
||||
validatorName := reflect.TypeOf(chk).Name()
|
||||
if nil == obj {
|
||||
if chk.IsSatisfied(obj) {
|
||||
return &Result{Ok: true}
|
||||
}
|
||||
} else if reflect.TypeOf(obj).Kind() == reflect.Ptr {
|
||||
if reflect.ValueOf(obj).IsNil() {
|
||||
if "Required" != chk.GetKey() {
|
||||
if "Required" != validatorName {
|
||||
return &Result{Ok: true}
|
||||
}
|
||||
} else {
|
||||
|
@ -442,3 +442,56 @@ func TestSkipValid(t *testing.T) {
|
||||
t.Fatal("validation should be passed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPointer(t *testing.T) {
|
||||
type User struct {
|
||||
ID int
|
||||
|
||||
Email *string `valid:"Email"`
|
||||
ReqEmail *string `valid:"Required;Email"`
|
||||
}
|
||||
|
||||
u := User{
|
||||
ReqEmail: nil,
|
||||
Email: nil,
|
||||
}
|
||||
|
||||
valid := Validation{}
|
||||
b, err := valid.Valid(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b {
|
||||
t.Fatal("validation should not be passed")
|
||||
}
|
||||
|
||||
validEmail := "a@a.com"
|
||||
u = User{
|
||||
ReqEmail: &validEmail,
|
||||
Email: nil,
|
||||
}
|
||||
|
||||
valid = Validation{RequiredFirst: true}
|
||||
b, err = valid.Valid(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !b {
|
||||
t.Fatal("validation should be passed")
|
||||
}
|
||||
|
||||
invalidEmail := "a@a"
|
||||
u = User{
|
||||
ReqEmail: &validEmail,
|
||||
Email: &invalidEmail,
|
||||
}
|
||||
|
||||
valid = Validation{}
|
||||
b, err = valid.Valid(u)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b {
|
||||
t.Fatal("validation should not be passed")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user