Fix protogen empty messages marshaling #108
18 changed files with 59 additions and 1 deletions
BIN
accounting/grpc/service_frostfs.pb.go
generated
BIN
accounting/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
acl/grpc/types_frostfs.pb.go
generated
BIN
acl/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
apemanager/grpc/service_frostfs.pb.go
generated
BIN
apemanager/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
container/grpc/service_frostfs.pb.go
generated
BIN
container/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
container/grpc/types_frostfs.pb.go
generated
BIN
container/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
lock/grpc/types_frostfs.pb.go
generated
BIN
lock/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/service_frostfs.pb.go
generated
BIN
netmap/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
netmap/grpc/types_frostfs.pb.go
generated
BIN
netmap/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
object/grpc/service_frostfs.pb.go
generated
BIN
object/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
object/grpc/types_frostfs.pb.go
generated
BIN
object/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
refs/grpc/types_frostfs.pb.go
generated
BIN
refs/grpc/types_frostfs.pb.go
generated
Binary file not shown.
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/proto/encoding"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -68,6 +69,63 @@ func TestRPCMessage(t *testing.T, msgGens ...func(empty bool) message.Message) {
|
|||
require.Equal(t, bm, bm2)
|
||||
})
|
||||
}
|
||||
t.Run("compatibility", func(t *testing.T) {
|
||||
testCompatibility(t, msgGen)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testCompatibility(t *testing.T, msgGen func(empty bool) message.Message) {
|
||||
compareBinary := func(t *testing.T, msg message.Message) {
|
||||
am, ok := msg.(binaryMessage)
|
||||
if !ok {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
a := am.StableMarshal(nil)
|
||||
b := msg.ToGRPCMessage().(encoding.ProtoMarshaler).MarshalProtobuf(nil)
|
||||
if len(a) == 0 {
|
||||
require.Empty(t, b)
|
||||
} else {
|
||||
require.Equal(t, a, b)
|
||||
}
|
||||
}
|
||||
compareJSON := func(t *testing.T, msg message.Message) {
|
||||
am, ok := msg.(jsonMessage)
|
||||
if !ok {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
a, err := am.MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
|
||||
b, err := json.Marshal(msg.ToGRPCMessage())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.JSONEq(t, string(a), string(b))
|
||||
if len(a) == 0 {
|
||||
require.Empty(t, b)
|
||||
} else {
|
||||
require.Equal(t, a, b)
|
||||
}
|
||||
}
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
msg := msgGen(true)
|
||||
t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) {
|
||||
compareBinary(t, msg)
|
||||
})
|
||||
t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) {
|
||||
compareJSON(t, msg)
|
||||
})
|
||||
})
|
||||
t.Run("not empty", func(t *testing.T) {
|
||||
msg := msgGen(false)
|
||||
t.Run(fmt.Sprintf("Binary_%T", msg), func(t *testing.T) {
|
||||
compareBinary(t, msg)
|
||||
})
|
||||
t.Run(fmt.Sprintf("JSON_%T", msg), func(t *testing.T) {
|
||||
compareJSON(t, msg)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
BIN
session/grpc/service_frostfs.pb.go
generated
BIN
session/grpc/service_frostfs.pb.go
generated
Binary file not shown.
BIN
session/grpc/types_frostfs.pb.go
generated
BIN
session/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
status/grpc/types_frostfs.pb.go
generated
BIN
status/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
tombstone/grpc/types_frostfs.pb.go
generated
BIN
tombstone/grpc/types_frostfs.pb.go
generated
Binary file not shown.
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
Binary file not shown.
|
@ -174,7 +174,7 @@ func emitMarshalRaw(g *protogen.GeneratedFile, f *protogen.Field, name string) {
|
|||
name += "[i]"
|
||||
}
|
||||
|
||||
g.P("if ", notNil(name), " && ", name, ".StableSize() != 0 {")
|
||||
g.P("if ", notNil(name), " {")
|
||||
g.P(name, ".EmitProtobuf(mm.AppendMessage(", f.Desc.Number(), "))")
|
||||
g.P("}")
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue