All checks were successful
* Add plugin option for protogen in Makefile * Fix the generator for the plugin in util/protogen * Erase convertable types, move helpful methods to gRPC protobufs * Erase helpers for convertations * Generate StableMarshlal/StableSize for protobufs by the protoc plugin Signed-off-by: Airat Arifullin a.arifullin@yadro.com
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package messagetest
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
utilproto "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) proto.Message) {
|
|
for _, msgGen := range msgGens {
|
|
msg1 := msgGen(false)
|
|
|
|
t.Run("encoding", func(t *testing.T) {
|
|
t.Run(fmt.Sprintf("JSON_%T", msg1), func(t *testing.T) {
|
|
data, err := protojson.MarshalOptions{
|
|
EmitUnpopulated: true,
|
|
}.Marshal(
|
|
msg1,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
msg2 := msgGen(true)
|
|
require.NoError(t, protojson.Unmarshal(data, msg2))
|
|
|
|
require.True(t, proto.Equal(msg1, msg2))
|
|
})
|
|
|
|
if bm, ok := msg1.(utilproto.StableMarshaller); ok {
|
|
t.Run(fmt.Sprintf("Stable_%T", msg1), func(t *testing.T) {
|
|
data := bm.StableMarshal(nil)
|
|
|
|
require.Len(t, data, bm.StableSize())
|
|
|
|
msg2 := msgGen(true)
|
|
require.NoError(t, proto.Unmarshal(data, msg2))
|
|
|
|
require.True(t, proto.Equal(msg1, msg2))
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|