test

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorEqual

func ErrorEqual(got, want error) bool

ErrorEqual compares two errors for equivalence.

func ErrorHasCode

func ErrorHasCode(got error, wantCode codes.Code) bool

ErrorHasCode returns true if an error has the desired canonical code.

func ErrorHasMsg

func ErrorHasMsg(got error, wantStr string) bool

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.

func (*FakeSource) Seed

func (f *FakeSource) Seed(seed int64)

Seed is unimplemented.

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.

func NewServer

func NewServer() (*Server, error)

NewServer creates a new mock Pub/Sub Lite server.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the address that the server is listening on.

func (*Server) Close

func (s *Server) Close()

Close shuts down the server and releases all resources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL