From 14907ba1b1bdc3d0c9d7c3033c8080b7cacb36a0 Mon Sep 17 00:00:00 2001 From: Adrian-Stefan Mares Date: Mon, 23 Sep 2019 13:52:51 +0200 Subject: [PATCH 1/2] testdata: Add nested oneof test --- main_test.go | 43 +++++++++++ testdata/testdata.pb.go | 110 ++++++++++++++++------------- testdata/testdata.pb.paths.fm.go | 20 ++++++ testdata/testdata.pb.setters.fm.go | 24 +++++++ testdata/testdata.pb.validate.go | 13 +++- testdata/testdata.proto | 1 + 6 files changed, 162 insertions(+), 49 deletions(-) diff --git a/main_test.go b/main_test.go index cc9663e..2ea984d 100644 --- a/main_test.go +++ b/main_test.go @@ -202,6 +202,26 @@ func TestFieldMaskPaths(t *testing.T) { "testOneof.d", "testOneof.e", "testOneof.f", + "testOneof.k", + "testOneof.k.a", + "testOneof.k.a.a", + "testOneof.k.a.b", + "testOneof.k.a.c", + "testOneof.k.a.d", + "testOneof.k.a.h", + "testOneof.k.a.h.nested_field", + "testOneof.k.a.i", + "testOneof.k.a.i.nested_field_2", + "testOneof.k.a.testNestedNestedOneOf", + "testOneof.k.a.testNestedNestedOneOf.e", + "testOneof.k.a.testNestedNestedOneOf.f", + "testOneof.k.a.testNestedNestedOneOf.g", + "testOneof.k.b", + "testOneof.k.c", + "testOneof.k.d", + "testOneof.k.e", + "testOneof.k.f", + "testOneof.k.g", }) a.So(testdata.TestFieldPathsTopLevel, should.Resemble, []string{ "a", @@ -391,6 +411,29 @@ func TestSetFields(t *testing.T) { G: &testdata.Empty{}, }, }, + { + Name: "testOneof.k.a.a", + Destination: &testdata.Test{}, + Source: &testdata.Test{ + TestOneof: &testdata.Test_K{ + K: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{ + A: 42, + }, + }, + }, + }, + Paths: []string{"testOneof.k.a.a"}, + Result: &testdata.Test{ + TestOneof: &testdata.Test_K{ + K: &testdata.Test_TestNested{ + A: &testdata.Test_TestNested_TestNestedNested{ + A: 42, + }, + }, + }, + }, + }, { Name: "testOneof.e", Destination: &testdata.Test{ diff --git a/testdata/testdata.pb.go b/testdata/testdata.pb.go index e18a1a9..c218f8d 100644 --- a/testdata/testdata.pb.go +++ b/testdata/testdata.pb.go @@ -66,6 +66,7 @@ type Test struct { // *Test_D // *Test_CustomNameOneof // *Test_F + // *Test_K TestOneof isTest_TestOneof `protobuf_oneof:"testOneof"` G *Empty `protobuf:"bytes,7,opt,name=g,proto3" json:"g,omitempty"` H *types.StringValue `protobuf:"bytes,8,opt,name=h,proto3" json:"h,omitempty"` @@ -112,10 +113,14 @@ type Test_CustomNameOneof struct { type Test_F struct { F []byte `protobuf:"bytes,6,opt,name=f,proto3,oneof"` } +type Test_K struct { + K *Test_TestNested `protobuf:"bytes,10,opt,name=k,proto3,oneof"` +} func (*Test_D) isTest_TestOneof() {} func (*Test_CustomNameOneof) isTest_TestOneof() {} func (*Test_F) isTest_TestOneof() {} +func (*Test_K) isTest_TestOneof() {} func (m *Test) GetTestOneof() isTest_TestOneof { if m != nil { @@ -166,6 +171,13 @@ func (m *Test) GetF() []byte { return nil } +func (m *Test) GetK() *Test_TestNested { + if x, ok := m.GetTestOneof().(*Test_K); ok { + return x.K + } + return nil +} + func (m *Test) GetG() *Empty { if m != nil { return m.G @@ -193,6 +205,7 @@ func (*Test) XXX_OneofWrappers() []interface{} { (*Test_D)(nil), (*Test_CustomNameOneof)(nil), (*Test_F)(nil), + (*Test_K)(nil), } } @@ -492,52 +505,53 @@ func init() { func init() { proto.RegisterFile("testdata.proto", fileDescriptor_40c4782d007dfce9) } var fileDescriptor_40c4782d007dfce9 = []byte{ - // 741 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcb, 0x6e, 0xd3, 0x4c, - 0x14, 0xee, 0x24, 0xce, 0x6d, 0x92, 0xa6, 0xd1, 0xfc, 0x7f, 0xa9, 0xb1, 0x80, 0x84, 0xb2, 0x20, - 0x8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, 0x6d, 0xa2, 0x56, 0xb4, 0x13, 0x0f, 0xcf, 0x30, 0xdf, 0xf4, - 0xc5, 0x96, 0xdd, 0x26, 0x06, 0x96, 0xbe, 0x8e, 0x98, 0x96, 0x7a, 0xe8, 0x65, 0xb4, 0x3d, 0x1b, - 0xe7, 0xad, 0xda, 0xc4, 0x59, 0xa6, 0x13, 0x51, 0xda, 0x52, 0x56, 0x60, 0x5a, 0x80, 0x83, 0x4a, - 0x30, 0x79, 0x40, 0x86, 0x82, 0x11, 0x8d, 0x1d, 0xd1, 0xff, 0x30, 0x75, 0xc8, 0x9e, 0xc6, 0xc9, - 0x98, 0xd7, 0x84, 0xb1, 0x9e, 0x58, 0x03, 0xca, 0x3a, 0x5c, 0x3c, 0xb6, 0x38, 0xba, 0x0a, 0x0b, - 0x0e, 0x37, 0xf7, 0xb9, 0xb4, 0x26, 0xd5, 0xf2, 0xe2, 0xee, 0x31, 0xbb, 0x52, 0x9e, 0xc0, 0x0b, - 0xc7, 0x0f, 0x86, 0xea, 0xb0, 0x18, 0x4f, 0xde, 0x6f, 0x4e, 0xe4, 0x91, 0x19, 0x63, 0x49, 0x49, - 0x64, 0x13, 0x5a, 0x21, 0x56, 0xa7, 0x89, 0x97, 0xe0, 0x22, 0x9d, 0x2a, 0xb4, 0xeb, 0x90, 0xdd, - 0x2e, 0x2e, 0xc1, 0x1c, 0x73, 0xf0, 0x3f, 0x1b, 0x4a, 0xfe, 0xc4, 0x00, 0xdf, 0x7f, 0x75, 0xef, - 0x3c, 0x4b, 0xd1, 0x4e, 0x73, 0xf7, 0xed, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x3c, 0xb6, 0x20, - 0x4b, 0xef, 0x06, 0x00, 0x00, + // 753 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0xcd, 0x6e, 0xd3, 0x4a, + 0x14, 0xee, 0x24, 0xce, 0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0x26, 0x76, 0x6c, 0x8f, 0x0e, 0x56, + 0xbf, 0x64, 0xa1, 0xd4, 0x20, 0x01, 0x45, 0x57, 0x21, 0xd0, 0x65, 0x50, 0x02, 0xe5, 0x6c, 0xfd, + 0x7f, 0xf5, 0x17, 0x15, 0x2c, 0xc5, 0x7f, 0xf6, 0x48, 0x40, 0x89, 0xa1, 0x01, 0x1d, 0xad, 0x43, + 0xd0, 0x94, 0x63, 0x73, 0x80, 0x38, 0x7f, 0x3c, 0x2c, 0xc2, 0x87, 0xfd, 0x80, 0xba, 0xf6, 0x9e, + 0x6e, 0x13, 0x0d, 0x34, 0xd1, 0x6d, 0x08, 0x5a, 0x72, 0x7c, 0x5e, 0x61, 0x6e, 0x84, 0x13, 0x6f, + 0x41, 0xac, 0x00, 0x3e, 0x0d, 0x8b, 0x0b, 0x1a, 0x68, 0xa1, 0x3c, 0x04, 0x86, 0x2c, 0x95, 0x40, + 0x39, 0xf1, 0x64, 0x41, 0x03, 0x06, 0xba, 0x02, 0x01, 0x91, 0x13, 0x25, 0x50, 0x5e, 0xc4, 0xff, + 0x1c, 0x0f, 0x8b, 0x4b, 0xd1, 0x23, 0xfb, 0x0e, 0x71, 0xdb, 0x0c, 0x44, 0x58, 0x51, 0x5b, 0x4e, + 0x96, 0x40, 0x39, 0xc7, 0xe2, 0x36, 0xba, 0x06, 0x41, 0x57, 0x86, 0x73, 0xde, 0x66, 0xd0, 0x2e, + 0xba, 0x08, 0x81, 0x29, 0xa7, 0x38, 0x74, 0x29, 0x82, 0x72, 0xb6, 0x34, 0x60, 0xa2, 0x0a, 0x04, + 0x1d, 0x39, 0xcd, 0xd3, 0x17, 0x54, 0xc1, 0xb2, 0x1a, 0xb2, 0xac, 0x1e, 0x50, 0xdf, 0x72, 0xcc, + 0x67, 0x7a, 0xaf, 0x4f, 0x34, 0xd0, 0x41, 0x37, 0x20, 0xb0, 0xe4, 0xcc, 0x7c, 0x2c, 0x96, 0xc4, + 0xc7, 0x5a, 0xca, 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+ 0x00, } diff --git a/testdata/testdata.pb.paths.fm.go b/testdata/testdata.pb.paths.fm.go index f31268c..d8ea151 100644 --- a/testdata/testdata.pb.paths.fm.go +++ b/testdata/testdata.pb.paths.fm.go @@ -72,6 +72,26 @@ var TestFieldPathsNested = []string{ "testOneof.d", "testOneof.e", "testOneof.f", + "testOneof.k", + "testOneof.k.a", + "testOneof.k.a.a", + "testOneof.k.a.b", + "testOneof.k.a.c", + "testOneof.k.a.d", + "testOneof.k.a.h", + "testOneof.k.a.h.nested_field", + "testOneof.k.a.i", + "testOneof.k.a.i.nested_field_2", + "testOneof.k.a.testNestedNestedOneOf", + "testOneof.k.a.testNestedNestedOneOf.e", + "testOneof.k.a.testNestedNestedOneOf.f", + "testOneof.k.a.testNestedNestedOneOf.g", + "testOneof.k.b", + "testOneof.k.c", + "testOneof.k.d", + "testOneof.k.e", + "testOneof.k.f", + "testOneof.k.g", } var TestFieldPathsTopLevel = []string{ diff --git a/testdata/testdata.pb.setters.fm.go b/testdata/testdata.pb.setters.fm.go index c01870f..4141ec1 100644 --- a/testdata/testdata.pb.setters.fm.go +++ b/testdata/testdata.pb.setters.fm.go @@ -175,6 +175,30 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { } else { dst.TestOneof.(*Test_F).F = nil } + case "k": + if _, ok := dst.TestOneof.(*Test_K); !ok { + dst.TestOneof = &Test_K{} + } + if len(oneofSubs) > 0 { + newDst := dst.TestOneof.(*Test_K).K + if newDst == nil { + newDst = &Test_TestNested{} + dst.TestOneof.(*Test_K).K = newDst + } + var newSrc *Test_TestNested + if src != nil { + newSrc = src.GetK() + } + if err := newDst.SetFields(newSrc, subs...); err != nil { + return err + } + } else { + if src != nil { + dst.TestOneof.(*Test_K).K = src.GetK() + } else { + dst.TestOneof.(*Test_K).K = nil + } + } default: return fmt.Errorf("invalid oneof field: '%s.%s'", name, oneofName) diff --git a/testdata/testdata.pb.validate.go b/testdata/testdata.pb.validate.go index 49165c8..77c2a5a 100644 --- a/testdata/testdata.pb.validate.go +++ b/testdata/testdata.pb.validate.go @@ -188,7 +188,7 @@ func (m *Test) ValidateFields(paths ...string) error { case "testOneof": if len(subs) == 0 { subs = []string{ - "d", "e", "f", + "d", "e", "f", "k", } } for name, subs := range _processPaths(subs) { @@ -200,6 +200,17 @@ func (m *Test) ValidateFields(paths ...string) error { // no validation rules for CustomNameOneof case "f": // no validation rules for F + case "k": + + if v, ok := interface{}(m.GetK()).(interface{ ValidateFields(...string) error }); ok { + if err := v.ValidateFields(subs...); err != nil { + return TestValidationError{ + field: "k", + reason: "embedded message failed validation", + cause: err, + } + } + } default: return TestValidationError{ diff --git a/testdata/testdata.proto b/testdata/testdata.proto index e082085..4b641bb 100644 --- a/testdata/testdata.proto +++ b/testdata/testdata.proto @@ -65,6 +65,7 @@ message Test { int32 d = 4; uint32 e = 5 [(gogoproto.customname) = "CustomNameOneof"]; bytes f = 6; + TestNested k = 10; } Empty g = 7; google.protobuf.StringValue h = 8; From 2b197584d645f939a0230dda8c317636cc66cd22 Mon Sep 17 00:00:00 2001 From: Adrian-Stefan Mares Date: Mon, 23 Sep 2019 13:53:55 +0200 Subject: [PATCH 2/2] setter.go: Use correct subpaths in oneOfs --- module/setter.go | 4 ++-- testdata/testdata.pb.setters.fm.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/setter.go b/module/setter.go index fcf3988..766bac0 100644 --- a/module/setter.go +++ b/module/setter.go @@ -141,10 +141,10 @@ func (m *setterModule) buildSetFieldsCase(buf *strings.Builder, imports importMa )) } - buildIndented(buf, tabCount+1, ` if err := newDst.SetFields(newSrc, subs...); err != nil { + buildIndented(buf, tabCount+1, fmt.Sprintf(` if err := newDst.SetFields(newSrc, %s...); err != nil { return err } -} else {`) +} else {`, subs)) if err := buildFinal(tabCount + 2); err != nil { return err } diff --git a/testdata/testdata.pb.setters.fm.go b/testdata/testdata.pb.setters.fm.go index 4141ec1..5d48fcc 100644 --- a/testdata/testdata.pb.setters.fm.go +++ b/testdata/testdata.pb.setters.fm.go @@ -189,7 +189,7 @@ func (dst *Test) SetFields(src *Test, paths ...string) error { if src != nil { newSrc = src.GetK() } - if err := newDst.SetFields(newSrc, subs...); err != nil { + if err := newDst.SetFields(newSrc, oneofSubs...); err != nil { return err } } else { @@ -409,7 +409,7 @@ func (dst *Test_TestNested_TestNestedNested) SetFields(src *Test_TestNested_Test if src != nil { newSrc = src.GetE() } - if err := newDst.SetFields(newSrc, subs...); err != nil { + if err := newDst.SetFields(newSrc, oneofSubs...); err != nil { return err } } else {