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

Relax oneof set fields validation #43

Merged
merged 4 commits into from
Apr 13, 2022
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 .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '~1.15'
go-version: '~1.17'
- name: Initialize Go module cache
uses: actions/cache@v2
with:
Expand Down
13 changes: 12 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/TheThingsIndustries/protoc-gen-fieldmask

go 1.15
go 1.17

replace github.com/lyft/protoc-gen-star => github.com/TheThingsIndustries/protoc-gen-star v0.5.2-gogo.1

Expand All @@ -17,3 +17,14 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/smartystreets/assertions v1.0.1
)

require (
github.com/iancoleman/strcase v0.1.2 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/spf13/afero v1.4.1 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.3.0 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/tools v0.0.0-20210106214847-113979e3529a // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
Expand Down
308 changes: 302 additions & 6 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/TheThingsIndustries/protoc-gen-fieldmask/testdata"
"github.com/gogo/protobuf/types"
"github.com/kr/pretty"
"github.com/mohae/deepcopy"
"github.com/smartystreets/assertions"
Expand Down Expand Up @@ -490,12 +491,29 @@ var setFieldsTestCases = []struct {
},
Paths: []string{"testOneof.d"},
Result: &testdata.Test{
TestOneof: &testdata.Test_CustomNameOneof{
CustomNameOneof: 42,
TestOneof: &testdata.Test_D{
D: 42,
},
G: &testdata.Empty{},
},
},
{
Name: "destination testOneof empty",
Destination: &testdata.Test{
G: &testdata.Empty{},
},
Source: &testdata.Test{
TestOneof: &testdata.Test_D{
D: 42,
},
},
Paths: []string{"testOneof.d"},
Result: &testdata.Test{
TestOneof: &testdata.Test_D{
D: 42,
},
G: &testdata.Empty{},
},
ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) },
},
{
Name: "source testOneof mismatch",
Expand All @@ -512,12 +530,48 @@ var setFieldsTestCases = []struct {
},
Paths: []string{"testOneof.d"},
Result: &testdata.Test{
TestOneof: &testdata.Test_D{
D: 42,
G: &testdata.Empty{},
},
},
{
Name: "source testOneof empty",
Destination: &testdata.Test{
G: &testdata.Empty{},
},
Source: &testdata.Test{},
Paths: []string{"testOneof.d"},
Result: &testdata.Test{
G: &testdata.Empty{},
},
},
{
Name: "source+destination testOneof mismatch",
Destination: &testdata.Test{
TestOneof: &testdata.Test_F{
F: []byte{0x42},
},
G: &testdata.Empty{},
},
ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) },
Source: &testdata.Test{
TestOneof: &testdata.Test_CustomNameOneof{
CustomNameOneof: 42,
},
},
Paths: []string{"testOneof.d"},
Result: &testdata.Test{
G: &testdata.Empty{},
},
},
{
Name: "source+destination testOneof empty",
Destination: &testdata.Test{
G: &testdata.Empty{},
},
Source: &testdata.Test{},
Paths: []string{"testOneof.d"},
Result: &testdata.Test{
G: &testdata.Empty{},
},
},
{
Name: "unset testOneof",
Expand Down Expand Up @@ -567,6 +621,248 @@ var setFieldsTestCases = []struct {
},
},
},
{
Name: "source testOneof.k.a.testNestedNestedOneOf.g mismatch",
Destination: &testdata.Test{},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_F{
F: 42,
},
},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g"},
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
},
{
Name: "source testOneof.k.a.testNestedNestedOneOf.g.a mismatch",
Destination: &testdata.Test{},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_F{
F: 42,
},
},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g.a"},
ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) },
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
},
{
Name: "source testOneof.k.a.testNestedNestedOneOf.g empty",
Destination: &testdata.Test{},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g"},
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
},
{
Name: "destination testOneof.k.a.testNestedNestedOneOf.g mismatch",
Destination: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_F{
F: 42,
},
},
},
},
},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_G{
G: &types.UInt64Value{
Value: 42,
},
},
},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g"},
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_G{
G: &types.UInt64Value{
Value: 42,
},
},
},
},
},
},
},
{
Name: "destination testOneof.k.a.testNestedNestedOneOf.g.a mismatch",
Destination: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_F{
F: 42,
},
},
},
},
},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_G{
G: &types.UInt64Value{
Value: 42,
},
},
},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g.a"},
ErrorAssertion: func(t *testing.T, err error) bool { return assertions.New(t).So(err, should.BeError) },
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_F{
F: 42,
},
},
},
},
},
},
{
Name: "destination testOneof.k.a.testNestedNestedOneOf.g empty",
Destination: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_G{
G: &types.UInt64Value{
Value: 42,
},
},
},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g"},
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_G{
G: &types.UInt64Value{
Value: 42,
},
},
},
},
},
},
},
{
Name: "source+destination testOneof.k.a.testNestedNestedOneOf.g mismatch",
Destination: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_F{
F: 42,
},
},
},
},
},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{
TestNestedNestedOneOf: &testdata.Test_TestNested_TestNestedNested_E{
E: &testdata.Empty{},
},
},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g"},
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
},
{
Name: "source+destination testOneof.k.a.testNestedNestedOneOf.g empty",
Destination: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
Source: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
Paths: []string{"testOneof.k.a.testNestedNestedOneOf.g"},
Result: &testdata.Test{
TestOneof: &testdata.Test_K{
K: &testdata.Test_TestNested{
A: &testdata.Test_TestNested_TestNestedNested{},
},
},
},
},
{
Name: "non-nullable c.a",
Destination: &testdata.Test{
Expand Down
Loading