Documentation ¶
Overview ¶
Package rpctest holds helpers for development/testing. please check the example of the rpc/rpcpool/wrapper for a real word usage.
Index ¶
- func AssertCode(tb testing.TB, err error, expectedCode rpcstatus.StatusCode) bool
- func AssertStatus(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, ...) bool
- func AssertStatusContains(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, ...) bool
- func ConnectionWithLatency(conn rpcpool.RawConn, duration time.Duration) rpcpool.RawConn
- func RequireCode(tb testing.TB, err error, expectedCode rpcstatus.StatusCode)
- func RequireStatus(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, ...)
- func RequireStatusContains(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, ...)
- type CallRecorder
- type MessageHandler
- type MessageHook
- type MessageInterceptor
- func (l *MessageInterceptor) Close() error
- func (l *MessageInterceptor) Closed() <-chan struct{}
- func (l *MessageInterceptor) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error
- func (l *MessageInterceptor) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error)
- func (l *MessageInterceptor) Transport() drpc.Transport
- func (l *MessageInterceptor) Unblocked() <-chan struct{}
- type StubConnection
- func (s *StubConnection) Close() error
- func (s *StubConnection) Closed() <-chan struct{}
- func (s *StubConnection) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error
- func (s *StubConnection) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error)
- func (s *StubConnection) RegisterHandler(rpc string, invoker MessageHandler)
- func (s *StubConnection) Transport() drpc.Transport
- func (s *StubConnection) Unblocked() <-chan struct{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertCode ¶
AssertCode asserts that the error returned by an RPC has the expected code.
func AssertStatus ¶
func AssertStatus(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string) bool
AssertStatus asserts that the error returned by an RPC has the expected code and cause.
func AssertStatusContains ¶
func AssertStatusContains(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string) bool
AssertStatusContains asserts that the error returned by an RPC has the expected code and contains the cause substring.
func ConnectionWithLatency ¶
ConnectionWithLatency wraps the original connection and add certain latency to it.
func RequireCode ¶
func RequireCode(tb testing.TB, err error, expectedCode rpcstatus.StatusCode)
RequireCode requires that the error returned by an RPC has the expected code.
func RequireStatus ¶
func RequireStatus(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string)
RequireStatus requires that the error returned by an RPC has the expected code and cause.
func RequireStatusContains ¶
func RequireStatusContains(tb testing.TB, err error, expectedCode rpcstatus.StatusCode, expectedCause string)
RequireStatusContains requires that the error returned by an RPC has the expected code and contains the cause substring.
Types ¶
type CallRecorder ¶
type CallRecorder struct {
// contains filtered or unexported fields
}
CallRecorder wraps drpc.Conn and record the rpc names for each calls. It uses an internal Mutex, therefore it's not recommended for production or performance critical operations.
func NewCallRecorder ¶
func NewCallRecorder() CallRecorder
NewCallRecorder returns with a properly initialized RPCounter.
func (*CallRecorder) Attach ¶
func (r *CallRecorder) Attach(conn rpcpool.RawConn) rpcpool.RawConn
Attach wraps a drpc.Conn connection and returns with one where the counters are hooked in.
func (*CallRecorder) CountOf ¶
func (r *CallRecorder) CountOf(rpc string) int
CountOf returns the number of calls to one specific rpc method.
func (*CallRecorder) History ¶
func (r *CallRecorder) History() []string
History returns the list of rpc names which called on this connection.
func (*CallRecorder) RecordCall ¶
func (r *CallRecorder) RecordCall(rpc string)
RecordCall records the fact of one rpc call.
func (*CallRecorder) Reset ¶
func (r *CallRecorder) Reset()
Reset deletes all the existing counters and set everything to 0.
type MessageHandler ¶
type MessageHandler func(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error
MessageHandler is the logic called with the rpc message instead of the original backend.
type MessageHook ¶
MessageHook is a function which may be called before and after an rpc call.
type MessageInterceptor ¶
type MessageInterceptor struct { RequestHook MessageHook ResponseHook MessageHook // contains filtered or unexported fields }
MessageInterceptor is a drpc.Conn which wraps an original connection with more functionality.
func NewMessageInterceptor ¶
func NewMessageInterceptor(conn rpcpool.RawConn) MessageInterceptor
NewMessageInterceptor creates a MessageInterceptor, a connection which delegates all the call to the specific drpc.Conn.
func (*MessageInterceptor) Close ¶
func (l *MessageInterceptor) Close() error
Close closes underlying dprc connection.
func (*MessageInterceptor) Closed ¶
func (l *MessageInterceptor) Closed() <-chan struct{}
Closed returns a channel that is closed if the underlying connection is definitely closed.
func (*MessageInterceptor) Invoke ¶
func (l *MessageInterceptor) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error
Invoke the underlying connection but call the RequestHook/ResponseHook before and after. When the Invoker is set it will be invoked instead of the original connection.
func (*MessageInterceptor) NewStream ¶
func (l *MessageInterceptor) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error)
NewStream creates a new wrapped stream.
func (*MessageInterceptor) Transport ¶
func (l *MessageInterceptor) Transport() drpc.Transport
Transport returns the underlying Transport.
func (*MessageInterceptor) Unblocked ¶
func (l *MessageInterceptor) Unblocked() <-chan struct{}
Unblocked returns the unblocked channel from the delegate.
type StubConnection ¶
type StubConnection struct {
// contains filtered or unexported fields
}
StubConnection can wrap existing drpc.Conn and replaces.
func NewStubConnection ¶
func NewStubConnection() StubConnection
NewStubConnection create a properly initialized StubConnection.
func (*StubConnection) Close ¶
func (s *StubConnection) Close() error
Close simulates the close call (noop).
func (*StubConnection) Closed ¶
func (s *StubConnection) Closed() <-chan struct{}
Closed returns a channel that is closed if the underlying connection is definitely closed.
func (*StubConnection) Invoke ¶
func (s *StubConnection) Invoke(ctx context.Context, rpc string, enc drpc.Encoding, in, out drpc.Message) error
Invoke the underlying connection but call the RequestHook/ResponseHook before and after. When the Invoker is set it will be invoked instead of the original connection.
func (*StubConnection) NewStream ¶
func (s *StubConnection) NewStream(ctx context.Context, rpc string, enc drpc.Encoding) (drpc.Stream, error)
NewStream creates a new wrapped stream.
func (*StubConnection) RegisterHandler ¶
func (s *StubConnection) RegisterHandler(rpc string, invoker MessageHandler)
RegisterHandler saves the handler for specific rpc calls.
func (*StubConnection) Transport ¶
func (s *StubConnection) Transport() drpc.Transport
Transport returns a nil transport.
func (*StubConnection) Unblocked ¶
func (s *StubConnection) Unblocked() <-chan struct{}
Unblocked returns a closed channel.