Skip to content

Commit

Permalink
test: supplement the unit testing of transport/grpc (#2371)
Browse files Browse the repository at this point in the history
* test:grpc codec test

* style:go fmt

* refactor:delete useless code

* style:go fmt
  • Loading branch information
Loner1024 authored Sep 15, 2022
1 parent b0b49be commit d3f80c1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions transport/grpc/codec_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit d3f80c1

Please sign in to comment.