Skip to content

Commit

Permalink
testproto: add test for empty byte marshalling
Browse files Browse the repository at this point in the history
Signed-off-by: Vicent Marti <[email protected]>
  • Loading branch information
vmg committed Jan 27, 2023
1 parent 9bfe855 commit d192986
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions testproto/proto3opt/proto3opt_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit d192986

Please sign in to comment.