diff --git a/testproto/proto3opt/proto3opt_test.go b/testproto/proto3opt/proto3opt_test.go new file mode 100644 index 0000000..90e058b --- /dev/null +++ b/testproto/proto3opt/proto3opt_test.go @@ -0,0 +1,30 @@ +package proto3opt + +import ( + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" +) + +func TestEmptyBytesMarshalling(t *testing.T) { + a := &OptionalFieldInProto3{ + OptionalBytes: nil, + } + b := &OptionalFieldInProto3{ + OptionalBytes: []byte{}, + } + + type Message interface { + proto.Message + MarshalVT() ([]byte, error) + } + + for _, msg := range []Message{a, b} { + vt, err := msg.MarshalVT() + require.NoError(t, err) + goog, err := proto.Marshal(msg) + require.NoError(t, err) + require.Equal(t, goog, vt) + } +}