[#111] proto/test: Add repeated message test

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-08-27 15:02:16 +03:00
parent eba18f6e67
commit a2025376fc
4 changed files with 18 additions and 0 deletions

View file

@ -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) {

Binary file not shown.

Binary file not shown.

View file

@ -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;
}