mirror of
https://github.com/Fishwaldo/validator.git
synced 2025-03-15 11:41:32 +00:00
Merge pull request #219 from joeybloggs/v8-development
Add new Anonymous test to hit new code
This commit is contained in:
commit
8040a52f21
1 changed files with 54 additions and 0 deletions
|
@ -296,6 +296,60 @@ type TestStructReturnValidationErrors struct {
|
|||
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) {
|
||||
config := &Config{
|
||||
TagName: "validate",
|
||||
|
|
Loading…
Add table
Reference in a new issue