Merge pull request #220 from go-playground/v8-development

Add new Anonymous test to hit new code
pull/228/head v8.14
Dean Karn 9 years ago
commit 43f534e655
  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