Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation of non-nullable fields #25

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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