Documentation ¶
Index ¶
- func ErrorEqual(got, want error) bool
- func ErrorHasCode(got error, wantCode codes.Code) bool
- func ErrorHasMsg(got error, wantStr string) bool
- type FakeSource
- type MockServer
- type RPCVerifier
- func (v *RPCVerifier) Flush()
- func (v *RPCVerifier) Pop(gotRequest interface{}) (interface{}, error)
- func (v *RPCVerifier) Push(wantRequest interface{}, retResponse interface{}, retErr error)
- func (v *RPCVerifier) PushWithBlock(wantRequest interface{}, retResponse interface{}, retErr error) chan struct{}
- func (v *RPCVerifier) TryPop() (bool, interface{}, error)
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorEqual ¶
ErrorEqual compares two errors for equivalence.
func ErrorHasCode ¶
ErrorHasCode returns true if an error has the desired canonical code.
func ErrorHasMsg ¶
ErrorHasMsg returns true if an error message contains the desired substring.
Types ¶
type FakeSource ¶
type FakeSource struct {
Ret int64
}
FakeSource is a fake source that returns a configurable constant.
func (*FakeSource) Int63 ¶
func (f *FakeSource) Int63() int64
Int63 returns the configured fake random number.
type MockServer ¶
type MockServer interface { // OnTestStart must be called at the start of each test to clear any existing // state and set the verifier for unary RPCs. OnTestStart(globalVerifier *RPCVerifier) // OnTestEnd should be called at the end of each test to flush the verifiers // (i.e. check whether any expected requests were not sent to the server). OnTestEnd() // AddPublishStream adds a verifier for a publish stream of a topic partition. AddPublishStream(topic string, partition int, streamVerifier *RPCVerifier) // AddSubscribeStream adds a verifier for a subscribe stream of a partition. AddSubscribeStream(subscription string, partition int, streamVerifier *RPCVerifier) // AddCommitStream adds a verifier for a commit stream of a partition. AddCommitStream(subscription string, partition int, streamVerifier *RPCVerifier) // AddAssignmentStream adds a verifier for a partition assignment stream for a // subscription. AddAssignmentStream(subscription string, streamVerifier *RPCVerifier) }
MockServer is an in-memory mock implementation of a Pub/Sub Lite service, which allows unit tests to inspect requests received by the server and send fake responses. This is the interface that should be used by tests.
type RPCVerifier ¶
type RPCVerifier struct {
// contains filtered or unexported fields
}
RPCVerifier stores an queue of requests expected from the client, and the corresponding response or error to return.
func NewRPCVerifier ¶
func NewRPCVerifier(t *testing.T) *RPCVerifier
NewRPCVerifier creates a new verifier for requests received by the server.
func (*RPCVerifier) Flush ¶
func (v *RPCVerifier) Flush()
Flush logs an error for any remaining {request, response, error} tuples, in case the client terminated early.
func (*RPCVerifier) Pop ¶
func (v *RPCVerifier) Pop(gotRequest interface{}) (interface{}, error)
Pop validates the received request with the next {request, response, error} tuple.
func (*RPCVerifier) Push ¶
func (v *RPCVerifier) Push(wantRequest interface{}, retResponse interface{}, retErr error)
Push appends a new {request, response, error} tuple.
func (*RPCVerifier) PushWithBlock ¶
func (v *RPCVerifier) PushWithBlock(wantRequest interface{}, retResponse interface{}, retErr error) chan struct{}
PushWithBlock is like Push, but returns a channel that the test should close when it would like the response to be sent to the client. This is useful for synchronizing with work that needs to be done on the client.
func (*RPCVerifier) TryPop ¶
func (v *RPCVerifier) TryPop() (bool, interface{}, error)
TryPop should be used only for streams. It checks whether the request in the next tuple is nil, in which case the response or error should be returned to the client without waiting for a request. Useful for streams where the server continuously sends data (e.g. subscribe stream).
type Server ¶
type Server struct { LiteServer MockServer // contains filtered or unexported fields }
Server is a mock Pub/Sub Lite server that can be used for unit testing.