add test
All checks were successful
lint / lint (pull_request) Successful in 54s
test / test (pull_request) Successful in 2m17s

This commit is contained in:
Денис Евстигнеев 2024-12-19 23:34:52 +03:00
parent bec0e310e9
commit 78664a34ed
2 changed files with 67 additions and 1 deletions

66
codec_test.go Normal file
View File

@ -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")
}
}

View File

@ -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