Skip to content

Commit

Permalink
Merge pull request #1 from ladydascalie/feature/fix-embedded-structs
Browse files Browse the repository at this point in the history
Fix embedded structs
  • Loading branch information
ladydascalie authored Jun 24, 2018
2 parents 00b4fc7 + 76b5e43 commit b74dbde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion v.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func Struct(structure interface{}) error {
// recurse if this is an embedded struct
if value.Kind() == reflect.Struct && field.PkgPath == "" {
// only exported fields should do this
return Struct(value.Interface())
if err := Struct(value.Interface()); err != nil {
return err
}
}

// get all the v tags
Expand Down
19 changes: 19 additions & 0 deletions v_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,25 @@ func TestStruct(t *testing.T) {
}
}

func Test_Embedding(t *testing.T) {
type A struct {
StrField string `v:"between:0..10"`
}
type B struct {
A
IntField int `v:"between:0..10"`
}
err := Struct(B{
A: A{
StrField: "hello world!", // this is not ok
},
IntField: 10, // this is ok
})
if err == nil {
t.Error("This should fail")
}
}

func Test_validationErorrs_Error(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit b74dbde

Please sign in to comment.