mocklookups

package
v0.0.0-...-6719cd2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package mocklookups provides a mock implementation of the various Fact lookup RPCs. This is useful for unit testing.

Index

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

type LookupRequest interface {
	ProtoMessage()
	String() string
	GetIndex() uint64
}

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

func New(t assert.TestingT, expected ...Expected) (*Mock, func())

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

func (mock *Mock) Expect(exp ...Expected)

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.

Jump to

Keyboard shortcuts

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