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 ¶
- Variables
- func MetadataNew(m map[string][]byte) metadata.MD
- func RegisterHandlerTestService(reg grpchan.ServiceRegistry, srv TestServiceServer)deprecated
- func RegisterTestServiceServer(s grpc.ServiceRegistrar, srv TestServiceServer)
- func RunChannelTestCases(t *testing.T, ch grpc.ClientConnInterface, supportsFullDuplex bool)
- type Message
- func (*Message) Descriptor() ([]byte, []int)deprecated
- func (x *Message) GetCode() int32
- func (x *Message) GetCount() int32
- func (x *Message) GetDelayMillis() int32
- func (x *Message) GetErrorDetails() []*anypb.Any
- func (x *Message) GetHeaders() map[string][]byte
- func (x *Message) GetPayload() []byte
- func (x *Message) GetTrailers() map[string][]byte
- func (*Message) ProtoMessage()
- func (x *Message) ProtoReflect() protoreflect.Message
- func (x *Message) Reset()
- func (x *Message) String() string
- 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
- type UnimplementedTestServiceServer
- func (UnimplementedTestServiceServer) BidiStream(TestService_BidiStreamServer) error
- func (UnimplementedTestServiceServer) ClientStream(TestService_ClientStreamServer) error
- func (UnimplementedTestServiceServer) ServerStream(*Message, TestService_ServerStreamServer) error
- func (UnimplementedTestServiceServer) Unary(context.Context, *Message) (*Message, error)
- func (UnimplementedTestServiceServer) UseExternalMessageTwice(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
- type UnsafeTestServiceServer
Constants ¶
This section is empty.
Variables ¶
var File_grpchantesting_test_proto protoreflect.FileDescriptor
var TestService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "grpchantesting.TestService", HandlerType: (*TestServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Unary", Handler: _TestService_Unary_Handler, }, { MethodName: "UseExternalMessageTwice", Handler: _TestService_UseExternalMessageTwice_Handler, }, }, Streams: []grpc.StreamDesc{ { StreamName: "ClientStream", Handler: _TestService_ClientStream_Handler, ClientStreams: true, }, { StreamName: "ServerStream", Handler: _TestService_ServerStream_Handler, ServerStreams: true, }, { StreamName: "BidiStream", Handler: _TestService_BidiStream_Handler, ServerStreams: true, ClientStreams: true, }, }, Metadata: "grpchantesting/test.proto", }
TestService_ServiceDesc is the grpc.ServiceDesc for TestService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)
Functions ¶
func RegisterHandlerTestService
deprecated
func RegisterHandlerTestService(reg grpchan.ServiceRegistry, srv TestServiceServer)
Deprecated: Use RegisterTestServiceServer instead.
func RegisterTestServiceServer ¶
func RegisterTestServiceServer(s grpc.ServiceRegistrar, srv TestServiceServer)
func RunChannelTestCases ¶
func RunChannelTestCases(t *testing.T, ch grpc.ClientConnInterface, supportsFullDuplex bool)
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][]byte `` /* 155-byte string literal not displayed */ Trailers map[string][]byte `` /* 157-byte string literal not displayed */ ErrorDetails []*anypb.Any `protobuf:"bytes,7,rep,name=error_details,json=errorDetails,proto3" json:"error_details,omitempty"` // contains filtered or unexported fields }
func (*Message) Descriptor
deprecated
func (*Message) GetDelayMillis ¶
func (*Message) GetErrorDetails ¶
func (*Message) GetHeaders ¶
func (*Message) GetPayload ¶
func (*Message) GetTrailers ¶
func (*Message) ProtoMessage ¶
func (*Message) ProtoMessage()
func (*Message) ProtoReflect ¶ added in v1.1.0
func (x *Message) ProtoReflect() protoreflect.Message
type TestServer ¶
type TestServer struct {
UnimplementedTestServiceServer
}
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 *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) }
TestServiceClient is the client API for TestService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewTestServiceChannelClient
deprecated
func NewTestServiceChannelClient(ch grpc.ClientConnInterface) TestServiceClient
Deprecated: Use NewTestServiceClient instead.
func NewTestServiceClient ¶
func NewTestServiceClient(cc grpc.ClientConnInterface) 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, *emptypb.Empty) (*emptypb.Empty, error) // contains filtered or unexported methods }
TestServiceServer is the server API for TestService service. All implementations must embed UnimplementedTestServiceServer for forward compatibility
type TestService_ServerStreamClient ¶
type TestService_ServerStreamClient interface { Recv() (*Message, error) grpc.ClientStream }
type TestService_ServerStreamServer ¶
type TestService_ServerStreamServer interface { Send(*Message) error grpc.ServerStream }
type UnimplementedTestServiceServer ¶ added in v1.1.0
type UnimplementedTestServiceServer struct { }
UnimplementedTestServiceServer must be embedded to have forward compatible implementations.
func (UnimplementedTestServiceServer) BidiStream ¶ added in v1.1.0
func (UnimplementedTestServiceServer) BidiStream(TestService_BidiStreamServer) error
func (UnimplementedTestServiceServer) ClientStream ¶ added in v1.1.0
func (UnimplementedTestServiceServer) ClientStream(TestService_ClientStreamServer) error
func (UnimplementedTestServiceServer) ServerStream ¶ added in v1.1.0
func (UnimplementedTestServiceServer) ServerStream(*Message, TestService_ServerStreamServer) error
func (UnimplementedTestServiceServer) UseExternalMessageTwice ¶ added in v1.1.0
type UnsafeTestServiceServer ¶ added in v1.1.0
type UnsafeTestServiceServer interface {
// contains filtered or unexported methods
}
UnsafeTestServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to TestServiceServer will result in compilation errors.