test: supplement the unit testing of transport/grpc (#2371)

* test:grpc codec test

* style:go fmt

* refactor:delete useless code

* style:go fmt
pull/2327/head
Loner1024 2 years ago committed by GitHub
parent b0b49be383
commit d3f80c1061
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      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)
}
}
Loading…
Cancel
Save