mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-04-16 08:42:29 +00:00
proto: refactor merge tests
Use protobuild to generate test messages, both to simplify generating proto2/proto3/extension variants of each test where appropriate and to make it easier to test alternative message generators in the future. Add various additional merge tests. Change-Id: I4ba3ce232304e1d8325543680e2b6aae61de7364 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/219146 Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
parent
cf33a9a274
commit
c7aa53a3e0
@ -144,6 +144,8 @@ func fieldValue(fd pref.FieldDescriptor, v interface{}) pref.Value {
|
|||||||
case pref.EnumKind:
|
case pref.EnumKind:
|
||||||
v = fd.Enum().Values().ByName(pref.Name(o)).Number()
|
v = fd.Enum().Values().ByName(pref.Name(o)).Number()
|
||||||
}
|
}
|
||||||
|
case []byte:
|
||||||
|
return pref.ValueOf(append([]byte{}, o...))
|
||||||
}
|
}
|
||||||
return pref.ValueOf(v)
|
return pref.ValueOf(v)
|
||||||
}
|
}
|
||||||
|
1053
proto/merge_test.go
1053
proto/merge_test.go
File diff suppressed because it is too large
Load Diff
@ -45,6 +45,22 @@ func makeMessages(in protobuild.Message, messages ...proto.Message) []proto.Mess
|
|||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func templateMessages(messages ...proto.Message) []protoreflect.MessageType {
|
||||||
|
if len(messages) == 0 {
|
||||||
|
messages = []proto.Message{
|
||||||
|
(*testpb.TestAllTypes)(nil),
|
||||||
|
(*test3pb.TestAllTypes)(nil),
|
||||||
|
(*testpb.TestAllExtensions)(nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var out []protoreflect.MessageType
|
||||||
|
for _, m := range messages {
|
||||||
|
out = append(out, m.ProtoReflect().Type())
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var testValidMessages = []testProto{
|
var testValidMessages = []testProto{
|
||||||
{
|
{
|
||||||
desc: "basic scalar types",
|
desc: "basic scalar types",
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/protobuf/internal/encoding/pack"
|
"google.golang.org/protobuf/internal/encoding/pack"
|
||||||
"google.golang.org/protobuf/internal/flags"
|
"google.golang.org/protobuf/internal/flags"
|
||||||
|
"google.golang.org/protobuf/internal/protobuild"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
testpb "google.golang.org/protobuf/internal/testprotos/test"
|
testpb "google.golang.org/protobuf/internal/testprotos/test"
|
||||||
@ -19,6 +20,7 @@ func init() {
|
|||||||
if flags.ProtoLegacy {
|
if flags.ProtoLegacy {
|
||||||
testValidMessages = append(testValidMessages, testWeakValidMessages...)
|
testValidMessages = append(testValidMessages, testWeakValidMessages...)
|
||||||
testInvalidMessages = append(testInvalidMessages, testWeakInvalidMessages...)
|
testInvalidMessages = append(testInvalidMessages, testWeakInvalidMessages...)
|
||||||
|
testMerges = append(testMerges, testWeakMerges...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +67,36 @@ var testWeakInvalidMessages = []testProto{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var testWeakMerges = []testMerge{
|
||||||
|
{
|
||||||
|
desc: "clone weak message",
|
||||||
|
src: protobuild.Message{
|
||||||
|
"weak_message1": protobuild.Message{
|
||||||
|
"a": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
types: []proto.Message{&testpb.TestWeak{}},
|
||||||
|
}, {
|
||||||
|
desc: "merge weak message",
|
||||||
|
dst: protobuild.Message{
|
||||||
|
"weak_message1": protobuild.Message{
|
||||||
|
"a": 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
src: protobuild.Message{
|
||||||
|
"weak_message1": protobuild.Message{
|
||||||
|
"a": 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: protobuild.Message{
|
||||||
|
"weak_message1": protobuild.Message{
|
||||||
|
"a": 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
types: []proto.Message{&testpb.TestWeak{}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func TestWeakNil(t *testing.T) {
|
func TestWeakNil(t *testing.T) {
|
||||||
if !flags.ProtoLegacy {
|
if !flags.ProtoLegacy {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user