Skip to content

Commit

Permalink
Append tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evgfedotov committed Nov 20, 2023
1 parent 7894a28 commit c13c5eb
Show file tree
Hide file tree
Showing 4 changed files with 445 additions and 20 deletions.
106 changes: 86 additions & 20 deletions testproto/pool/pool.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions testproto/pool/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ option go_package = "testproto/pool";

import "github.com/planetscale/vtprotobuf/vtproto/ext.proto";

message OptionalMessage{
option (vtproto.mempool) = true;
}

message MemoryPoolExtension {
option (vtproto.mempool) = true;
string foo1 = 1;
uint64 foo2 = 2;
optional OptionalMessage foo3 = 3;
}
22 changes: 22 additions & 0 deletions testproto/pool/pool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pool

import (
"google.golang.org/protobuf/proto"
"log"
"testing"

Expand Down Expand Up @@ -163,3 +164,24 @@ func Test_Pool_Oneof(t *testing.T) {
require.NoError(t, t8.UnmarshalVT(t4Bytes))
require.Equal(t, &t4, &t8)
}

func Test_Pool_Optional(t *testing.T) {
m := &MemoryPoolExtension{
Foo1: "foo1",
Foo2: 123,
Foo3: &OptionalMessage{},
}

mBytes, err := m.MarshalVT()
require.NoError(t, err)

mUnmarshal := &MemoryPoolExtension{}
err = proto.Unmarshal(mBytes, mUnmarshal)
require.NoError(t, err)

require.True(t, m.EqualVT(mUnmarshal))

m.ReturnToVTPool()
mFromPool := MemoryPoolExtensionFromVTPool()
require.True(t, mFromPool.EqualVT(&MemoryPoolExtension{}))
}
Loading

0 comments on commit c13c5eb

Please sign in to comment.