@@ -231,6 +231,18 @@ func AssertMapFieldError(t *testing.T, s map[string]*FieldError, field string, e
231231 EqualSkip (t , 2 , val .Tag , expectedTag )
232232}
233233
234+ func TestBadKeyValidation (t * testing.T ) {
235+ type Test struct {
236+ Name string `validate:"required, "`
237+ }
238+
239+ tst := & Test {
240+ Name : "test" ,
241+ }
242+
243+ PanicMatches (t , func () { validate .Struct (tst ) }, "Invalid validation tag on field Name" )
244+ }
245+
234246func TestFlattenValidation (t * testing.T ) {
235247
236248 type Inner struct {
@@ -606,13 +618,29 @@ func TestInterfaceErrValidation(t *testing.T) {
606618 Equal (t , err .IsPlaceholderErr , false )
607619 Equal (t , err .IsSliceOrArray , false )
608620 Equal (t , len (err .SliceOrArrayErrs ), 0 )
621+
622+ type MyStruct struct {
623+ A , B string
624+ C interface {}
625+ }
626+
627+ var a MyStruct
628+
629+ a .A = "value"
630+ a .C = "nu"
631+
632+ errs = validate .Struct (a )
633+ Equal (t , errs , nil )
609634}
610635
611636func TestMapDiveValidation (t * testing.T ) {
612637
638+ n := map [int ]interface {}{0 : nil }
639+ err := validate .Field (n , "omitempty,required" )
640+
613641 m := map [int ]string {0 : "ok" , 3 : "" , 4 : "ok" }
614642
615- err : = validate .Field (m , "len=3,dive,required" )
643+ err = validate .Field (m , "len=3,dive,required" )
616644 NotEqual (t , err , nil )
617645 Equal (t , err .IsPlaceholderErr , true )
618646 Equal (t , err .IsMap , true )
0 commit comments