diff --git a/codec_test.go b/codec_test.go new file mode 100644 index 0000000..54b9e90 --- /dev/null +++ b/codec_test.go @@ -0,0 +1,66 @@ +package grpc + +import ( + "context" + "go.unistack.org/micro/v3/codec" + gmetadata "google.golang.org/grpc/metadata" + "testing" +) + +type mockStream struct { + msg any +} + +func (m mockStream) Header() (gmetadata.MD, error) { + return nil, nil +} + +func (m mockStream) Trailer() gmetadata.MD { + return nil +} + +func (m mockStream) CloseSend() error { + return nil +} + +func (m mockStream) Context() context.Context { + return nil +} + +func (m *mockStream) SendMsg(msg any) error { + m.msg = msg + return nil +} + +func (m *mockStream) RecvMsg(msg any) error { + + c := msg.(*codec.Frame) + c.Data = m.msg.(*codec.Frame).Data + + return nil +} + +func Test_ReadWrap(t *testing.T) { + + wp := wrapStream{ + &mockStream{}, + } + + write, err := wp.Write([]byte("test_data")) + if err != nil { + t.Fatal(err) + } + if write != 9 { + t.Error("uncorrected number wrote bytes") + } + + b := make([]byte, write) + read, err := wp.Read(b) + if err != nil { + t.Fatal(err) + } + + if read != 9 || string(b) != "test_data" { + t.Error("uncorrected number wrote bytes or data") + } +} diff --git a/grpc_pool.go b/grpc_pool.go index f602710..026e222 100644 --- a/grpc_pool.go +++ b/grpc_pool.go @@ -130,7 +130,7 @@ func (p *ConnPool) Get(ctx context.Context, addr string, opts ...grpc.DialOption } p.Unlock() - // create new conn) + // nolint (TODO need fix) create new conn) cc, err := grpc.DialContext(ctx, addr, opts...) if err != nil { return nil, err