100% test coverage

pull/307/head
Dean Karn 7 years ago
parent 0b5dc7605b
commit 0d09605a05
  1. 20
      validator_test.go

@ -7240,8 +7240,22 @@ func TestIsDefault(t *testing.T) {
Equal(t, fe.Namespace(), "Test.Inner") Equal(t, fe.Namespace(), "Test.Inner")
Equal(t, fe.Tag(), "isdefault") Equal(t, fe.Tag(), "isdefault")
validate.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "-" {
return ""
}
return name
})
type Inner2 struct {
String string `validate:"isdefault"`
}
type Test2 struct { type Test2 struct {
Inner Inner `validate:"isdefault"` Inner Inner2 `validate:"isdefault" json:"inner"`
} }
var t2 Test2 var t2 Test2
@ -7252,4 +7266,8 @@ func TestIsDefault(t *testing.T) {
errs = validate.Struct(t2) errs = validate.Struct(t2)
NotEqual(t, errs, nil) NotEqual(t, errs, nil)
fe = errs.(ValidationErrors)[0]
Equal(t, fe.Field(), "inner")
Equal(t, fe.Namespace(), "Test2.inner")
Equal(t, fe.Tag(), "isdefault")
} }

Loading…
Cancel
Save