initial call_test.go
This commit is contained in:
15
call_test.go
15
call_test.go
@ -34,7 +34,6 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
@ -49,15 +48,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
expectedRequest = []byte("ping")
|
expectedRequest = "ping"
|
||||||
expectedResponse = []byte("pong")
|
expectedResponse = "pong"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCodec struct {
|
type testCodec struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testCodec) Marshal(v interface{}) ([]byte, error) {
|
func (testCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
return v.([]byte), nil
|
return []byte(*(v.(*string))), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testCodec) Unmarshal(data []byte, v interface{}) error {
|
func (testCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
@ -91,12 +90,12 @@ func (h *testStreamHandler) handleStream(t *testing.T, s *transport.Stream) {
|
|||||||
if err := codec.Unmarshal(req, &v); err != nil {
|
if err := codec.Unmarshal(req, &v); err != nil {
|
||||||
t.Fatalf("Failed to unmarshal the received message %v", err)
|
t.Fatalf("Failed to unmarshal the received message %v", err)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(req, expectedRequest) {
|
if v != expectedRequest {
|
||||||
t.Fatalf("handleStream got %v, want %v", p, req)
|
t.Fatalf("handleStream got %v, want %v", v, expectedRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// send a response back to end the stream.
|
// send a response back to end the stream.
|
||||||
reply, err := encode(testCodec{}, expectedResponse, compressionNone)
|
reply, err := encode(testCodec{}, &expectedResponse, compressionNone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to encode the response: %v", err)
|
t.Fatalf("Failed to encode the response: %v", err)
|
||||||
}
|
}
|
||||||
@ -190,7 +189,7 @@ func setUp(t *testing.T, port int, maxStreams uint32) (*server, *ClientConn) {
|
|||||||
func TestInvoke(t *testing.T) {
|
func TestInvoke(t *testing.T) {
|
||||||
server, cc := setUp(t, 0, math.MaxUint32)
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
var reply string
|
var reply string
|
||||||
if err := Invoke(context.Background(), "/foo/bar", expectedRequest, &reply, cc); err != nil {
|
if err := Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply, cc); err != nil || reply != expectedResponse {
|
||||||
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want <nil>", err)
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) = %v, want <nil>", err)
|
||||||
}
|
}
|
||||||
server.stop()
|
server.stop()
|
||||||
|
Reference in New Issue
Block a user