Documentation ¶
Overview ¶
Package grpchantesting helps with testing implementations of alternate gRPC transports. Its main value is in a method that, given a channel, will ensure the channel behaves correctly under various conditions.
It tests successful RPCs, failures, timeouts and client-side cancellations. It also covers all kinds of RPCs: unary, client-streaming, server-streaming and bidirectional-streaming. It can optionally test full-duplex bidi streams if the underlying channel supports that.
The channel must be connected to a server that exposes the test server implementation contained in this package: &grpchantesting.TestServer{}
Index ¶
- func RegisterHandlerTestService(reg grpchan.ServiceRegistry, srv TestServiceServer)
- func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer)
- func RunChannelTestCases(t *testing.T, ch grpchan.Channel, supportsFullDuplex bool)
- type Message
- func (*Message) Descriptor() ([]byte, []int)
- func (m *Message) GetCode() int32
- func (m *Message) GetCount() int32
- func (m *Message) GetDelayMillis() int32
- func (m *Message) GetErrorDetails() []*any.Any
- func (m *Message) GetHeaders() map[string]string
- func (m *Message) GetPayload() []byte
- func (m *Message) GetTrailers() map[string]string
- func (*Message) ProtoMessage()
- func (m *Message) Reset()
- func (m *Message) String() string
- func (m *Message) XXX_DiscardUnknown()
- func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Message) XXX_Merge(src proto.Message)
- func (m *Message) XXX_Size() int
- func (m *Message) XXX_Unmarshal(b []byte) error
- type TestServer
- func (s *TestServer) BidiStream(str TestService_BidiStreamServer) error
- func (s *TestServer) ClientStream(cs TestService_ClientStreamServer) error
- func (s *TestServer) ServerStream(req *Message, ss TestService_ServerStreamServer) error
- func (s *TestServer) Unary(ctx context.Context, req *Message) (*Message, error)
- func (s *TestServer) UseExternalMessageTwice(ctx context.Context, in *empty.Empty) (*empty.Empty, error)
- type TestServiceClient
- type TestServiceServer
- type TestService_BidiStreamClient
- type TestService_BidiStreamServer
- type TestService_ClientStreamClient
- type TestService_ClientStreamServer
- type TestService_ServerStreamClient
- type TestService_ServerStreamServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterHandlerTestService ¶
func RegisterHandlerTestService(reg grpchan.ServiceRegistry, srv TestServiceServer)
func RegisterTestServiceServer ¶
func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer)
func RunChannelTestCases ¶
RunChannelTestCases runs numerous test cases to exercise the behavior of the given channel. The server side of the channel needs to have a *TestServer (in this package) registered to provide the implementation of fsgrpc.TestService (proto in this package). If the channel does not support full-duplex communication, it must provide at least half-duplex support for bidirectional streams.
The test cases will be defined as child tests by invoking t.Run on the given *testing.T.
Types ¶
type Message ¶
type Message struct { Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count,omitempty"` Code int32 `protobuf:"varint,3,opt,name=code,proto3" json:"code,omitempty"` DelayMillis int32 `protobuf:"varint,4,opt,name=delay_millis,json=delayMillis,proto3" json:"delay_millis,omitempty"` Headers map[string]string `` /* 155-byte string literal not displayed */ Trailers map[string]string `` /* 157-byte string literal not displayed */ ErrorDetails []*any.Any `protobuf:"bytes,7,rep,name=error_details,json=errorDetails,proto3" json:"error_details,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Message) Descriptor ¶
func (*Message) GetDelayMillis ¶
func (*Message) GetErrorDetails ¶
func (*Message) GetHeaders ¶
func (*Message) GetPayload ¶
func (*Message) GetTrailers ¶
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
func (*Message) XXX_DiscardUnknown ¶
func (m *Message) XXX_DiscardUnknown()
func (*Message) XXX_Marshal ¶
func (*Message) XXX_Unmarshal ¶
type TestServer ¶
type TestServer struct{}
TestServer has default responses to the various kinds of methods.
func (*TestServer) BidiStream ¶
func (s *TestServer) BidiStream(str TestService_BidiStreamServer) error
BidiStream implements the TestService server interface.
func (*TestServer) ClientStream ¶
func (s *TestServer) ClientStream(cs TestService_ClientStreamServer) error
ClientStream implements the TestService server interface.
func (*TestServer) ServerStream ¶
func (s *TestServer) ServerStream(req *Message, ss TestService_ServerStreamServer) error
ServerStream implements the TestService server interface.
func (*TestServer) UseExternalMessageTwice ¶
func (s *TestServer) UseExternalMessageTwice(ctx context.Context, in *empty.Empty) (*empty.Empty, error)
UseExternalMessageTwice implements the TestService server interface.
type TestServiceClient ¶
type TestServiceClient interface { Unary(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Message, error) ClientStream(ctx context.Context, opts ...grpc.CallOption) (TestService_ClientStreamClient, error) ServerStream(ctx context.Context, in *Message, opts ...grpc.CallOption) (TestService_ServerStreamClient, error) BidiStream(ctx context.Context, opts ...grpc.CallOption) (TestService_BidiStreamClient, error) // UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in UseExternalMessageTwice(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) }
TestServiceClient is the client API for TestService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewTestServiceChannelClient ¶
func NewTestServiceChannelClient(ch grpchan.Channel) TestServiceClient
func NewTestServiceClient ¶
func NewTestServiceClient(cc *grpc.ClientConn) TestServiceClient
type TestServiceServer ¶
type TestServiceServer interface { Unary(context.Context, *Message) (*Message, error) ClientStream(TestService_ClientStreamServer) error ServerStream(*Message, TestService_ServerStreamServer) error BidiStream(TestService_BidiStreamServer) error // UseExternalMessageTwice is here purely to test the protoc-gen-grpchan plug-in UseExternalMessageTwice(context.Context, *empty.Empty) (*empty.Empty, error) }
TestServiceServer is the server API for TestService service.
type TestService_ServerStreamClient ¶
type TestService_ServerStreamClient interface { Recv() (*Message, error) grpc.ClientStream }
type TestService_ServerStreamServer ¶
type TestService_ServerStreamServer interface { Send(*Message) error grpc.ServerStream }