add test for new nil validation

pull/523/head
Dean Karn 5 years ago
parent 06f92248de
commit 9593a0f77e
  1. 25
      validator_test.go

@ -8839,3 +8839,28 @@ func TestLookup(t *testing.T) {
}
Equal(t, New().Struct(lookup), nil)
}
func TestAbilityToValidateNils(t *testing.T) {
type TestStruct struct {
Test *string `validate:"nil"`
}
ts := TestStruct{}
val := New()
fn := func(fl FieldLevel) bool {
return fl.Field().Kind() == reflect.Ptr && fl.Field().IsNil()
}
err := val.RegisterValidation("nil", fn, true)
Equal(t, err, nil)
errs := val.Struct(ts)
Equal(t, errs, nil)
str := "string"
ts.Test = &str
errs = val.Struct(ts)
NotEqual(t, errs, nil)
}

Loading…
Cancel
Save