1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

test: arrangement test proto and add test (#1567)

* arrangement test proto and add test
This commit is contained in:
海雨
2021-10-20 21:43:44 +08:00
committed by GitHub
parent 63b1764a04
commit fecfb7dc86
5 changed files with 639 additions and 263 deletions
+32 -2
View File
@@ -3,8 +3,13 @@ package form
import (
"testing"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/fieldmaskpb"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
"github.com/go-kratos/kratos/v2/encoding"
"github.com/go-kratos/kratos/v2/internal/complex"
"github.com/go-kratos/kratos/v2/internal/testdata/complex"
"github.com/stretchr/testify/require"
)
@@ -68,10 +73,35 @@ func TestProtoEncodeDecode(t *testing.T) {
NoOne: "2233",
Simple: &complex.Simple{Component: "5566"},
Simples: []string{"3344", "5566"},
B: true,
Sex: complex.Sex_woman,
Age: 18,
A: 19,
Count: 3,
Price: 11.23,
D: 22.22,
Byte: []byte("123"),
Map: map[string]string{"kratos": "https://go-kratos.dev/"},
Timestamp: &timestamppb.Timestamp{Seconds: 20, Nanos: 2},
Duration: &durationpb.Duration{Seconds: 120, Nanos: 22},
Field: &fieldmaskpb.FieldMask{Paths: []string{"1", "2"}},
Double: &wrapperspb.DoubleValue{Value: 12.33},
Float: &wrapperspb.FloatValue{Value: 12.34},
Int64: &wrapperspb.Int64Value{Value: 64},
Int32: &wrapperspb.Int32Value{Value: 32},
Uint64: &wrapperspb.UInt64Value{Value: 64},
Uint32: &wrapperspb.UInt32Value{Value: 32},
Bool: &wrapperspb.BoolValue{Value: false},
String_: &wrapperspb.StringValue{Value: "go-kratos"},
Bytes: &wrapperspb.BytesValue{Value: []byte("123")},
}
content, err := encoding.GetCodec(contentType).Marshal(in)
require.NoError(t, err)
require.Equal(t, "id=2233&numberOne=2233&simples=3344&simples=5566&very_simple.component=5566", string(content))
require.Equal(t, "a=19&age=18&b=true&bool=false&byte=MTIz&bytes=MTIz&count=3&d=22.22&double=12.33&duration="+
"2m0.000000022s&field=1%2C2&float=12.34&id=2233&int32=32&int64=64&map%5Bkratos%5D=https%3A%2F%2Fgo-kratos.dev%2F&"+
"numberOne=2233&price=11.23&sex=woman&simples=3344&simples=5566&string=go-kratos"+
"&timestamp=1970-01-01T00%3A00%3A20.000000002Z&uint32=32&uint64=64&very_simple.component=5566", string(content))
in2 := &complex.Complex{}
err = encoding.GetCodec(contentType).Unmarshal(content, in2)
require.NoError(t, err)