proto/test: Add repeated message test
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
eba18f6e67
commit
bed8c7f00d
4 changed files with 18 additions and 0 deletions
|
@ -113,6 +113,10 @@ func repPrimitivesEqual(t *testing.T, a *generated.RepPrimitives, b *test.RepPri
|
|||
require.Equal(t, a.FieldE, b.FieldE)
|
||||
require.Equal(t, a.FieldF, b.FieldF)
|
||||
require.Equal(t, a.FieldFu, b.FieldFu)
|
||||
require.Equal(t, len(a.GetFieldAux()), len(b.GetFieldAux()))
|
||||
for i := range a.FieldAux {
|
||||
require.Equal(t, a.GetFieldAux()[i].GetInnerField(), b.GetFieldAux()[i].GetInnerField())
|
||||
}
|
||||
}
|
||||
|
||||
func randIntSlice[T protoInt](n int, includeZero bool) []T {
|
||||
|
@ -129,6 +133,14 @@ func randIntSlice[T protoInt](n int, includeZero bool) []T {
|
|||
return r
|
||||
}
|
||||
|
||||
func uint32SliceToAux(s []uint32) []*generated.RepPrimitives_Aux {
|
||||
r := make([]*generated.RepPrimitives_Aux, len(s))
|
||||
for i := range s {
|
||||
r[i] = &generated.RepPrimitives_Aux{s[i]}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func TestStableMarshalRep(t *testing.T) {
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
marshalCases := []struct {
|
||||
|
@ -176,6 +188,9 @@ func TestStableMarshalRep(t *testing.T) {
|
|||
{name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](1, true)}},
|
||||
{name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, true)}},
|
||||
{name: "uint64", input: &generated.RepPrimitives{FieldFu: randIntSlice[uint64](2, false)}},
|
||||
{name: "message", input: &generated.RepPrimitives{FieldAux: uint32SliceToAux(randIntSlice[uint32](1, true))}},
|
||||
{name: "message", input: &generated.RepPrimitives{FieldAux: uint32SliceToAux(randIntSlice[uint32](2, true))}},
|
||||
{name: "message", input: &generated.RepPrimitives{FieldAux: uint32SliceToAux(randIntSlice[uint32](2, false))}},
|
||||
}
|
||||
for _, tc := range marshalCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
|
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
BIN
util/proto/test/custom/test_frostfs.pb.go
generated
Binary file not shown.
BIN
util/proto/test/test.pb.go
generated
BIN
util/proto/test/test.pb.go
generated
Binary file not shown.
|
@ -40,4 +40,7 @@ message RepPrimitives {
|
|||
repeated int64 field_e = 5;
|
||||
repeated uint64 field_f = 6;
|
||||
repeated uint64 field_fu = 7 [ packed = false ];
|
||||
|
||||
message Aux { uint32 inner_field = 1; }
|
||||
repeated Aux field_aux = 8;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue