proto: fix merge semantics for oneof message
The proper semantics for a message field within a oneof
when unmarshaling is to merge into an existing message,
rather than replacing it.
Change-Id: I7c08f6e4fa958c6ee6241e9083f7311515a97e15
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185957
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/proto/merge_test.go b/proto/merge_test.go
index 109a413..c8c3b0a 100644
--- a/proto/merge_test.go
+++ b/proto/merge_test.go
@@ -27,8 +27,6 @@
src proto.Message
want proto.Message
mutator func(proto.Message) // if provided, is run on src after merging
-
- skipMarshalUnmarshal bool // TODO: Remove this when proto.Unmarshal is fixed for messages in oneofs
}{{
desc: "merge from nil message",
dst: new(testpb.TestAllTypes),
@@ -258,7 +256,6 @@
m := mi.(*testpb.TestAllTypes)
*m.OneofField.(*testpb.TestAllTypes_OneofNestedMessage).OneofNestedMessage.Corecursive.OptionalInt64++
},
- skipMarshalUnmarshal: true,
}, {
desc: "merge oneof scalar fields",
dst: &testpb.TestAllTypes{
@@ -382,7 +379,7 @@
if err != nil {
t.Fatalf("Unmarshal() error: %v", err)
}
- if !proto.Equal(dst, tt.want) && !tt.skipMarshalUnmarshal {
+ if !proto.Equal(dst, tt.want) {
t.Fatalf("Unmarshal(Marshal(dst)+Marshal(src)) mismatch: got %v, want %v", dst, tt.want)
}