Skip to content

Commit

Permalink
Merge pull request #25 from TheThingsIndustries/fix/non-nullable
Browse files Browse the repository at this point in the history
Fix validation of non-nullable fields
  • Loading branch information
rvolosatovs authored Feb 26, 2019
2 parents 7015bcf + a199579 commit cbc52bc
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 48 deletions.
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo h1:vtoerBb3MHbzeUM0+w/bBpIhzT+yCaD1QrDN1/p7F2A=
github.com/TheThingsIndustries/protoc-gen-star v0.4.7-gogo/go.mod h1:lIqzPBz4CG/TSsK9fPQvo7iVfbxEWc+76AVxeiHMcT4=
github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask h1:f9Of0TRMdB+A2mZVJFUadESOOx0RfvBXR2FBFz/9hyI=
github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask h1:vIdGpbSKd0SJJoC+BEZc/17W+N3CKh6qjfpXKbyCw7g=
github.com/TheThingsIndustries/protoc-gen-validate v0.0.13-fieldmask/go.mod h1:65OEzdQPsbLDokGIF3GQjCTWOuuVuHqxh7a08yYe0tw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
39 changes: 38 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ func TestFieldMaskPaths(t *testing.T) {
"a.a.d",
"a.a.h",
"a.a.h.nested_field",
"a.a.i",
"a.a.i.nested_field_2",
"a.a.testNestedNestedOneOf",
"a.a.testNestedNestedOneOf.e",
"a.a.testNestedNestedOneOf.f",
Expand All @@ -160,6 +162,8 @@ func TestFieldMaskPaths(t *testing.T) {
"b.a.d",
"b.a.h",
"b.a.h.nested_field",
"b.a.i",
"b.a.i.nested_field_2",
"b.a.testNestedNestedOneOf",
"b.a.testNestedNestedOneOf.e",
"b.a.testNestedNestedOneOf.f",
Expand All @@ -177,6 +181,8 @@ func TestFieldMaskPaths(t *testing.T) {
"c.a.d",
"c.a.h",
"c.a.h.nested_field",
"c.a.i",
"c.a.i.nested_field_2",
"c.a.testNestedNestedOneOf",
"c.a.testNestedNestedOneOf.e",
"c.a.testNestedNestedOneOf.f",
Expand Down Expand Up @@ -212,6 +218,8 @@ func TestFieldMaskPaths(t *testing.T) {
"a.d",
"a.h",
"a.h.nested_field",
"a.i",
"a.i.nested_field_2",
"a.testNestedNestedOneOf",
"a.testNestedNestedOneOf.e",
"a.testNestedNestedOneOf.f",
Expand All @@ -238,6 +246,8 @@ func TestFieldMaskPaths(t *testing.T) {
"d",
"h",
"h.nested_field",
"i",
"i.nested_field_2",
"testNestedNestedOneOf",
"testNestedNestedOneOf.e",
"testNestedNestedOneOf.f",
Expand All @@ -249,6 +259,7 @@ func TestFieldMaskPaths(t *testing.T) {
"c",
"d",
"h",
"i",
"testNestedNestedOneOf",
})
}
Expand Down Expand Up @@ -496,13 +507,16 @@ func TestValidateFields(t *testing.T) {
A: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
A: 42,
Test_TestNested_TestNestedNested_TestNestedNestedEmbed2: testdata.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2{
NestedField_2: 2,
},
},
C: func(v time.Duration) *time.Duration { return &v }(43 * time.Second),
},
},
},
{
Name: "nil paths/invalid",
Name: "nil paths/invalid a.a.a",
Message: &testdata.Test{
A: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
Expand All @@ -512,6 +526,29 @@ func TestValidateFields(t *testing.T) {
},
ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) },
},
{
Name: "a.a.i/valid a.a.i.nested_field_2",
Message: &testdata.Test{
A: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
Test_TestNested_TestNestedNested_TestNestedNestedEmbed2: testdata.Test_TestNested_TestNestedNested_TestNestedNestedEmbed2{
NestedField_2: 2,
},
},
},
},
Paths: []string{"a.a.i"},
},
{
Name: "a.a.i/invalid a.a.i.nested_field_2",
Message: &testdata.Test{
A: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
Paths: []string{"a.a.i"},
ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) },
},
{
Name: "non-existent sub-field",
Message: &testdata.Test{},
Expand Down
135 changes: 91 additions & 44 deletions testdata/testdata.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions testdata/testdata.pb.paths.fm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions testdata/testdata.pb.setters.fm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cbc52bc

Please sign in to comment.