Documentation
¶
Overview ¶
Package mocklookups provides a mock implementation of the various Fact lookup RPCs. This is useful for unit testing.
Index ¶
- type Expected
- type LookupRequest
- type Mock
- func (mock *Mock) Expect(exp ...Expected)
- func (mock *Mock) LookupPO(ctx context.Context, req *rpc.LookupPORequest, resCh chan *rpc.LookupChunk) error
- func (mock *Mock) LookupPOCmp(ctx context.Context, req *rpc.LookupPOCmpRequest, resCh chan *rpc.LookupChunk) error
- func (mock *Mock) LookupS(ctx context.Context, req *rpc.LookupSRequest, resCh chan *rpc.LookupChunk) error
- func (mock *Mock) LookupSP(ctx context.Context, req *rpc.LookupSPRequest, resCh chan *rpc.LookupChunk) error
- func (mock *Mock) LookupSPO(ctx context.Context, req *rpc.LookupSPORequest, resCh chan *rpc.LookupChunk) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expected ¶
type Expected struct { // If non-nil, a pointer to the expected request. If nil, the actual request is // not checked (any request is acceptable). Request LookupRequest // Responses to send on the channel, in order. Replies []rpc.LookupChunk // If set, this will be returned by the lookup function after the replies // are sent. ReplyErr error }
Expected describes what Mock should do when it receives a single lookup request.
func Err ¶
func Err(req LookupRequest, replyErr error) Expected
Err is a convenience function for constructing Expected values. It returns a descriptor that expects the given request, sends it nothing, and returns the given error from the lookup function. 'req' may be nil to indicate that any request is acceptable.
func OK ¶
func OK(req LookupRequest, replies ...rpc.LookupChunk) Expected
OK is a convenience function for constructing Expected values. It returns a descriptor that expects the given request and sends the given replies to it. 'req' may be nil to indicate that any request is acceptable.
type LookupRequest ¶
LookupRequest is an interface that is satisfied by *rpc.LookupPORequest, *rpc.LookupPOCmpRequest, etc.
Note: Additional types that aren't lookup requests may happen to satisfy this interface, but using those with Mock will typically lead to assertion failures.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock is a combined client and server that implements lookups.All. Mock is thread-safe.
func New ¶
New constructs a combined client and server. It also returns a function that should be called before tearing down the test, which asserts that the Mock received all of the requests it expected. The given 't' is typically a *testing.T. The given 'expected' values instruct the Mock on how to behave when it gets its first lookup requests (in FIFO order).
func (*Mock) Expect ¶
Expect instructs the Mock on how to behave when it gets additional lookup requests (in FIFO order).
func (*Mock) LookupPO ¶
func (mock *Mock) LookupPO(ctx context.Context, req *rpc.LookupPORequest, resCh chan *rpc.LookupChunk) error
LookupPO implements lookups.PO.
func (*Mock) LookupPOCmp ¶
func (mock *Mock) LookupPOCmp(ctx context.Context, req *rpc.LookupPOCmpRequest, resCh chan *rpc.LookupChunk) error
LookupPOCmp implements lookups.POCmp.
func (*Mock) LookupS ¶
func (mock *Mock) LookupS(ctx context.Context, req *rpc.LookupSRequest, resCh chan *rpc.LookupChunk) error
LookupS implements lookups.S.
func (*Mock) LookupSP ¶
func (mock *Mock) LookupSP(ctx context.Context, req *rpc.LookupSPRequest, resCh chan *rpc.LookupChunk) error
LookupSP implements lookups.SP.
func (*Mock) LookupSPO ¶
func (mock *Mock) LookupSPO(ctx context.Context, req *rpc.LookupSPORequest, resCh chan *rpc.LookupChunk) error
LookupSPO implements lookups.SPO.