@@ -8,10 +8,26 @@ import (
88 . "gopkg.in/check.v1"
99)
1010
11+ type I interface {
12+ Foo () string
13+ }
14+
15+ type Impl struct {
16+ F string `validate:"len=3"`
17+ }
18+
19+ func (i * Impl ) Foo () string {
20+ return i .F
21+ }
22+
1123type SubTest struct {
1224 Test string `validate:"required"`
1325}
1426
27+ type TestInterface struct {
28+ Iface I
29+ }
30+
1531type TestString struct {
1632 Required string `validate:"required"`
1733 Len string `validate:"len=10"`
@@ -24,6 +40,7 @@ type TestString struct {
2440 Anonymous struct {
2541 A string `validate:"required"`
2642 }
43+ Iface I
2744}
2845
2946type TestInt32 struct {
@@ -116,6 +133,9 @@ func (ms *MySuite) TestFlattening(c *C) {
116133 }{
117134 A : "1" ,
118135 },
136+ Iface : & Impl {
137+ F : "123" ,
138+ },
119139 }
120140
121141 err1 := validator .ValidateStruct (tSuccess ).Flatten ()
@@ -136,6 +156,9 @@ func (ms *MySuite) TestFlattening(c *C) {
136156 }{
137157 A : "" ,
138158 },
159+ Iface : & Impl {
160+ F : "12" ,
161+ },
139162 }
140163
141164 err2 := validator .ValidateStruct (tFail ).Flatten ()
@@ -151,6 +174,9 @@ func (ms *MySuite) TestFlattening(c *C) {
151174
152175 // Assert Anonymous Struct Field
153176 AssertMapFieldError (err2 , "Anonymous.A" , "required" , c )
177+
178+ // Assert Interface Field
179+ AssertMapFieldError (err2 , "Iface.F" , "len" , c )
154180}
155181
156182func (ms * MySuite ) TestStructStringValidation (c * C ) {
@@ -173,6 +199,9 @@ func (ms *MySuite) TestStructStringValidation(c *C) {
173199 }{
174200 A : "1" ,
175201 },
202+ Iface : & Impl {
203+ F : "123" ,
204+ },
176205 }
177206
178207 err := validator .ValidateStruct (tSuccess )
@@ -193,6 +222,9 @@ func (ms *MySuite) TestStructStringValidation(c *C) {
193222 }{
194223 A : "" ,
195224 },
225+ Iface : & Impl {
226+ F : "12" ,
227+ },
196228 }
197229
198230 err = validator .ValidateStruct (tFail )
@@ -201,7 +233,7 @@ func (ms *MySuite) TestStructStringValidation(c *C) {
201233 c .Assert (err , NotNil )
202234 c .Assert (err .Struct , Equals , "TestString" )
203235 c .Assert (len (err .Errors ), Equals , 6 )
204- c .Assert (len (err .StructErrors ), Equals , 2 )
236+ c .Assert (len (err .StructErrors ), Equals , 3 )
205237
206238 // Assert Fields
207239 AssertFieldError (err , "Required" , "required" , c )
0 commit comments