Documentation
¶
Overview ¶
Package grpcmock provides functionalities for testing grpc client and server.
Index ¶
- Constants
- func FromMethodType(t MethodType) (isClientStream bool, isServerStream bool)
- func InvokeBidirectionalStream(ctx context.Context, method string, handle ClientStreamHandler, ...) error
- func InvokeClientStream(ctx context.Context, method string, handle ClientStreamHandler, ...) error
- func InvokeServerStream(ctx context.Context, method string, in interface{}, handle ClientStreamHandler, ...) error
- func InvokeUnary(ctx context.Context, method string, in interface{}, out interface{}, ...) error
- func IsMethodBidirectionalStream(t MethodType) bool
- func IsMethodClientStream(t MethodType) bool
- func IsMethodServerStream(t MethodType) bool
- func IsMethodUnary(t MethodType) bool
- type ClientStreamHandler
- type ContextDialer
- type InvokeOption
- func WithBufConnDialer(l *bufconn.Listener) InvokeOption
- func WithCallOptions(opts ...grpc.CallOption) InvokeOption
- func WithContextDialer(d ContextDialer) InvokeOption
- func WithDialOptions(opts ...grpc.DialOption) InvokeOption
- func WithHeader(key, value string) InvokeOption
- func WithHeaders(header map[string]string) InvokeOption
- func WithInsecure() InvokeOption
- type MethodType
- type ServiceMethod
- type TestingT
Constants ¶
const ( // ErrMissingMethod indicates that there is no method in the url. ErrMissingMethod err = "missing method" // ErrMalformedMethod indicates that the method is malformed. ErrMalformedMethod err = "malformed method" )
Variables ¶
This section is empty.
Functions ¶
func FromMethodType ¶ added in v0.5.0
func FromMethodType(t MethodType) (isClientStream bool, isServerStream bool)
FromMethodType returns the checks if method type is client stream or server stream.
func InvokeBidirectionalStream ¶ added in v0.3.0
func InvokeBidirectionalStream( ctx context.Context, method string, handle ClientStreamHandler, opts ...InvokeOption, ) error
InvokeBidirectionalStream invokes a bidirectional-stream method.
func InvokeClientStream ¶ added in v0.2.0
func InvokeClientStream( ctx context.Context, method string, handle ClientStreamHandler, out interface{}, opts ...InvokeOption, ) error
InvokeClientStream invokes a client-stream method.
func InvokeServerStream ¶ added in v0.2.0
func InvokeServerStream( ctx context.Context, method string, in interface{}, handle ClientStreamHandler, opts ...InvokeOption, ) error
InvokeServerStream invokes a server-stream method.
func InvokeUnary ¶
func InvokeUnary( ctx context.Context, method string, in interface{}, out interface{}, opts ...InvokeOption, ) error
InvokeUnary invokes a unary method.
func IsMethodBidirectionalStream ¶ added in v0.5.0
func IsMethodBidirectionalStream(t MethodType) bool
IsMethodBidirectionalStream checks whether the method is client-and-server-stream.
func IsMethodClientStream ¶ added in v0.5.0
func IsMethodClientStream(t MethodType) bool
IsMethodClientStream checks whether the method is client-stream.
func IsMethodServerStream ¶ added in v0.5.0
func IsMethodServerStream(t MethodType) bool
IsMethodServerStream checks whether the method is server-stream.
func IsMethodUnary ¶ added in v0.5.0
func IsMethodUnary(t MethodType) bool
IsMethodUnary checks whether the method is unary.
Types ¶
type ClientStreamHandler ¶ added in v0.2.0
type ClientStreamHandler func(stream grpc.ClientStream) error
ClientStreamHandler handles a client stream.
func RecvAll ¶ added in v0.2.0
func RecvAll(out interface{}) ClientStreamHandler
RecvAll reads everything from the stream and put into the output.
func SendAll ¶ added in v0.2.0
func SendAll(in interface{}) ClientStreamHandler
SendAll sends everything to the stream.
func SendAndRecvAll ¶ added in v0.3.0
func SendAndRecvAll(in interface{}, out interface{}) ClientStreamHandler
SendAndRecvAll sends and receives messages to and from grpc server in turn until server sends the io.EOF.
func (ClientStreamHandler) Handle ¶ added in v0.2.0
func (h ClientStreamHandler) Handle(stream grpc.ClientStream) error
Handle handles a client stream.
type ContextDialer ¶
ContextDialer is to set up the dialer.
type InvokeOption ¶
type InvokeOption func(c *invokeConfig)
InvokeOption sets invoker config.
func WithBufConnDialer ¶
func WithBufConnDialer(l *bufconn.Listener) InvokeOption
WithBufConnDialer sets a *bufconn.Listener as the context dialer.
See:
- grpcmock.WithContextDialer()
func WithCallOptions ¶ added in v0.4.0
func WithCallOptions(opts ...grpc.CallOption) InvokeOption
WithCallOptions sets call options.
func WithContextDialer ¶
func WithContextDialer(d ContextDialer) InvokeOption
WithContextDialer sets a context dialer to create connections.
See:
- grpcmock.WithBufConnDialer()
func WithDialOptions ¶
func WithDialOptions(opts ...grpc.DialOption) InvokeOption
WithDialOptions sets dial options.
func WithHeaders ¶
func WithHeaders(header map[string]string) InvokeOption
WithHeaders sets request header.
func WithInsecure ¶
func WithInsecure() InvokeOption
WithInsecure disables transport security for the connections.
type MethodType ¶ added in v0.5.0
type MethodType string
MethodType is service method type.
const ( // MethodTypeUnary indicates that the method is unary. MethodTypeUnary MethodType = "Unary" // MethodTypeClientStream indicates that the method is client-stream. MethodTypeClientStream MethodType = "ClientStream" // MethodTypeServerStream indicates that the method is server-stream. MethodTypeServerStream MethodType = "ServerStream" // MethodTypeBidirectionalStream indicates that the method is bidirectional-stream. MethodTypeBidirectionalStream MethodType = "BidirectionalStream" )
func ToMethodType ¶ added in v0.5.0
func ToMethodType(isClientStream, isServerStream bool) MethodType
ToMethodType defines the method type by checking if it's a client or server strean.
type ServiceMethod ¶ added in v0.5.0
type ServiceMethod struct {
ServiceName string
MethodName string
MethodType MethodType
Input interface{}
Output interface{}
}
ServiceMethod contains description of a grpc service.
func (ServiceMethod) FullName ¶ added in v0.5.0
func (m ServiceMethod) FullName() string
FullName returns the full name of the service method.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package assert provides assertions for grpc.
|
Package assert provides assertions for grpc. |
|
internal
|
|
|
mock/grpc
Package grpc provides mock for grpc types.
|
Package grpc provides mock for grpc types. |
|
test
Package test provides functionalities for testing the project.
|
Package test provides functionalities for testing the project. |
|
test/grpctest
Package grpctest provides the test implementation for the grpctest Service.
|
Package grpctest provides the test implementation for the grpctest Service. |
|
Package invoker constructs a grpc request and executes it.
|
Package invoker constructs a grpc request and executes it. |
|
Package reflect provides a simple reflection on the grpc server.
|
Package reflect provides a simple reflection on the grpc server. |
