Add new Anonymous test to hit new code

* now have 100% test coverage again.
pull/219/head
joeybloggs 9 years ago
parent 0794474f60
commit 934bef0ce5
  1. 54
      validator_test.go

@ -296,6 +296,60 @@ type TestStructReturnValidationErrors struct {
Inner1 *TestStructReturnValidationErrorsInner1 Inner1 *TestStructReturnValidationErrorsInner1
} }
func TestAnonymous(t *testing.T) {
v2 := New(&Config{TagName: "validate", FieldNameTag: "json"})
type Test struct {
Anonymous struct {
A string `validate:"required" json:"EH"`
}
AnonymousB struct {
B string `validate:"required" json:"BEE"`
}
anonymousC struct {
c string `validate:"required" json:"SEE"`
}
}
tst := &Test{
Anonymous: struct {
A string `validate:"required" json:"EH"`
}{
A: "1",
},
AnonymousB: struct {
B string `validate:"required" json:"BEE"`
}{
B: "",
},
anonymousC: struct {
c string `validate:"required" json:"SEE"`
}{
c: "",
},
}
err := v2.Struct(tst)
NotEqual(t, err, nil)
errs := err.(ValidationErrors)
Equal(t, len(errs), 1)
AssertError(t, errs, "Test.AnonymousB.B", "B", "required")
Equal(t, errs["Test.AnonymousB.B"].Field, "B")
Equal(t, errs["Test.AnonymousB.B"].Name, "BEE")
s := struct {
c string `validate:"required" json:"SEE"`
}{
c: "",
}
err = v2.Struct(s)
Equal(t, err, nil)
}
func TestStructLevelReturnValidationErrors(t *testing.T) { func TestStructLevelReturnValidationErrors(t *testing.T) {
config := &Config{ config := &Config{
TagName: "validate", TagName: "validate",

Loading…
Cancel
Save