From d3f80c10612c5050d30219a6f8ee3765f3046eff Mon Sep 17 00:00:00 2001 From: Loner1024 Date: Thu, 15 Sep 2022 20:13:51 +0800 Subject: [PATCH] test: supplement the unit testing of transport/grpc (#2371) * test:grpc codec test * style:go fmt * refactor:delete useless code * style:go fmt --- transport/grpc/codec_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 transport/grpc/codec_test.go diff --git a/transport/grpc/codec_test.go b/transport/grpc/codec_test.go new file mode 100644 index 000000000..534439ff9 --- /dev/null +++ b/transport/grpc/codec_test.go @@ -0,0 +1,28 @@ +package grpc + +import ( + "reflect" + "testing" + + "google.golang.org/protobuf/types/known/structpb" +) + +func TestCodec(t *testing.T) { + in, err := structpb.NewStruct(map[string]interface{}{"Golang": "Kratos"}) + if err != nil { + t.Errorf("grpc codec create input data error:%v", err) + } + c := codec{} + data, err := c.Marshal(in) + if err != nil { + t.Errorf("grpc codec marshal error:%v", err) + } + out := &structpb.Struct{} + err = c.Unmarshal(data, out) + if err != nil { + t.Errorf("grpc codec unmarshal error:%v", err) + } + if !reflect.DeepEqual(in, out) { + t.Errorf("grpc codec want %v, got %v", in, out) + } +}