add test
Some checks failed
lint / lint (pull_request) Failing after 1m14s
test / test (pull_request) Successful in 3m40s

This commit is contained in:
Денис Евстигнеев 2024-12-19 23:34:52 +03:00
parent bec0e310e9
commit 6022b1719a

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