peertest

package
v1.42.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package peertest is a generated GoMock package.

Package peertest is a generated GoMock package.

Package peertest is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyPeerListActions

func ApplyPeerListActions(t *testing.T, pl peer.Chooser, actions []PeerListAction, deps ListActionDeps)

ApplyPeerListActions runs all the PeerListActions on the PeerList

func ApplyTransportActions

func ApplyTransportActions(t *testing.T, transport peer.Transport, actions []TransportAction, d TransportDeps)

ApplyTransportActions runs all the TransportActions on the peer Transport

func CreatePeerIDs

func CreatePeerIDs(peerIDStrs []string) []peer.Identifier

CreatePeerIDs takes a slice of peerID strings and returns a slice of PeerIdentifiers

func CreateSubscriberMap

func CreateSubscriberMap(
	mockCtrl *gomock.Controller,
	subDefinitions []SubscriberDefinition,
) map[string]peer.Subscriber

CreateSubscriberMap will take a slice of SubscriberDefinitions and return a map of IDs to MockPeerSubscribers

func ExpectPeerReleases

func ExpectPeerReleases(
	transport *MockTransport,
	peerStrs []string,
	err error,
)

ExpectPeerReleases registers expectations on a MockTransport to release peers through the ReleasePeer function

func ExpectPeerRetains

func ExpectPeerRetains(
	transport *MockTransport,
	availablePeerStrs []string,
	unavailablePeerStrs []string,
) map[string]*LightMockPeer

ExpectPeerRetains registers expectations on a MockTransport to generate peers on the RetainPeer function

func ExpectPeerRetainsWithError

func ExpectPeerRetainsWithError(
	transport *MockTransport,
	peerStrs []string,
	err error,
)

ExpectPeerRetainsWithError registers expectations on a MockTransport return errors

Types

type ChooseAction

type ChooseAction struct {
	InputContext        context.Context
	InputContextTimeout time.Duration
	InputRequest        *transport.Request
	ExpectedPeer        string
	ExpectedErr         error
}

ChooseAction is an action for choosing a peer from the peerlist

func (ChooseAction) Apply

func (a ChooseAction) Apply(t *testing.T, pl peer.Chooser, deps ListActionDeps)

Apply runs "Choose" on the peerList and validates the peer && error

type ChooseMultiAction

type ChooseMultiAction struct {
	ExpectedPeers []string
}

ChooseMultiAction will run Choose multiple times on the PeerList It will assert if there are ANY failures

func (ChooseMultiAction) Apply

func (a ChooseMultiAction) Apply(t *testing.T, pl peer.Chooser, deps ListActionDeps)

Apply runs "Choose" on the peerList for every ExpectedPeer

type ConcurrentAction

type ConcurrentAction struct {
	Actions []PeerListAction
	Wait    time.Duration
}

ConcurrentAction will run a series of actions in parallel

func (ConcurrentAction) Apply

func (a ConcurrentAction) Apply(t *testing.T, pl peer.Chooser, deps ListActionDeps)

Apply runs all the ConcurrentAction's actions in goroutines with a delay of `Wait` between each action. Returns when all actions have finished executing

type LightMockPeer

type LightMockPeer struct {
	sync.Mutex

	MockPeerIdentifier

	PeerStatus peer.Status
}

LightMockPeer is a small simple wrapper around the Peer interface for mocking and changing a peer's attributes MockPeer is NOT thread safe

func NewLightMockPeer

func NewLightMockPeer(pid MockPeerIdentifier, conStatus peer.ConnectionStatus) *LightMockPeer

NewLightMockPeer returns a new MockPeer

func (*LightMockPeer) EndRequest

func (p *LightMockPeer) EndRequest()

EndRequest should be run after a MockPeer request has finished

func (*LightMockPeer) StartRequest

func (p *LightMockPeer) StartRequest()

StartRequest is run when a Request starts

func (*LightMockPeer) Status

func (p *LightMockPeer) Status() peer.Status

Status returns the Status Object of the MockPeer

type ListActionDeps

type ListActionDeps struct {
	Peers map[string]*LightMockPeer
}

ListActionDeps are passed through PeerListActions' Apply methods in order to allow the PeerListAction to modify state other than just the PeerList

type MockChooser

type MockChooser struct {
	// contains filtered or unexported fields
}

MockChooser is a mock of Chooser interface

func NewMockChooser

func NewMockChooser(ctrl *gomock.Controller) *MockChooser

NewMockChooser creates a new mock instance

func (*MockChooser) Choose

func (m *MockChooser) Choose(arg0 context.Context, arg1 *transport.Request) (peer.Peer, func(error), error)

Choose mocks base method

func (*MockChooser) EXPECT

func (m *MockChooser) EXPECT() *MockChooserMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockChooser) IsRunning

func (m *MockChooser) IsRunning() bool

IsRunning mocks base method

func (*MockChooser) Start

func (m *MockChooser) Start() error

Start mocks base method

func (*MockChooser) Stop

func (m *MockChooser) Stop() error

Stop mocks base method

type MockChooserList

type MockChooserList struct {
	// contains filtered or unexported fields
}

MockChooserList is a mock of ChooserList interface

func NewMockChooserList

func NewMockChooserList(ctrl *gomock.Controller) *MockChooserList

NewMockChooserList creates a new mock instance

func (*MockChooserList) Choose

func (m *MockChooserList) Choose(arg0 context.Context, arg1 *transport.Request) (peer.Peer, func(error), error)

Choose mocks base method

func (*MockChooserList) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockChooserList) IsRunning

func (m *MockChooserList) IsRunning() bool

IsRunning mocks base method

func (*MockChooserList) Start

func (m *MockChooserList) Start() error

Start mocks base method

func (*MockChooserList) Stop

func (m *MockChooserList) Stop() error

Stop mocks base method

func (*MockChooserList) Update

func (m *MockChooserList) Update(arg0 peer.ListUpdates) error

Update mocks base method

type MockChooserListMockRecorder

type MockChooserListMockRecorder struct {
	// contains filtered or unexported fields
}

MockChooserListMockRecorder is the mock recorder for MockChooserList

func (*MockChooserListMockRecorder) Choose

func (mr *MockChooserListMockRecorder) Choose(arg0, arg1 interface{}) *gomock.Call

Choose indicates an expected call of Choose

func (*MockChooserListMockRecorder) IsRunning

func (mr *MockChooserListMockRecorder) IsRunning() *gomock.Call

IsRunning indicates an expected call of IsRunning

func (*MockChooserListMockRecorder) Start

Start indicates an expected call of Start

func (*MockChooserListMockRecorder) Stop

Stop indicates an expected call of Stop

func (*MockChooserListMockRecorder) Update

func (mr *MockChooserListMockRecorder) Update(arg0 interface{}) *gomock.Call

Update indicates an expected call of Update

type MockChooserMockRecorder

type MockChooserMockRecorder struct {
	// contains filtered or unexported fields
}

MockChooserMockRecorder is the mock recorder for MockChooser

func (*MockChooserMockRecorder) Choose

func (mr *MockChooserMockRecorder) Choose(arg0, arg1 interface{}) *gomock.Call

Choose indicates an expected call of Choose

func (*MockChooserMockRecorder) IsRunning

func (mr *MockChooserMockRecorder) IsRunning() *gomock.Call

IsRunning indicates an expected call of IsRunning

func (*MockChooserMockRecorder) Start

func (mr *MockChooserMockRecorder) Start() *gomock.Call

Start indicates an expected call of Start

func (*MockChooserMockRecorder) Stop

func (mr *MockChooserMockRecorder) Stop() *gomock.Call

Stop indicates an expected call of Stop

type MockIdentifier

type MockIdentifier struct {
	// contains filtered or unexported fields
}

MockIdentifier is a mock of Identifier interface

func NewMockIdentifier

func NewMockIdentifier(ctrl *gomock.Controller) *MockIdentifier

NewMockIdentifier creates a new mock instance

func (*MockIdentifier) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockIdentifier) Identifier

func (m *MockIdentifier) Identifier() string

Identifier mocks base method

type MockIdentifierMockRecorder

type MockIdentifierMockRecorder struct {
	// contains filtered or unexported fields
}

MockIdentifierMockRecorder is the mock recorder for MockIdentifier

func (*MockIdentifierMockRecorder) Identifier

func (mr *MockIdentifierMockRecorder) Identifier() *gomock.Call

Identifier indicates an expected call of Identifier

type MockList

type MockList struct {
	// contains filtered or unexported fields
}

MockList is a mock of List interface

func NewMockList

func NewMockList(ctrl *gomock.Controller) *MockList

NewMockList creates a new mock instance

func (*MockList) EXPECT

func (m *MockList) EXPECT() *MockListMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockList) Update

func (m *MockList) Update(arg0 peer.ListUpdates) error

Update mocks base method

type MockListMockRecorder

type MockListMockRecorder struct {
	// contains filtered or unexported fields
}

MockListMockRecorder is the mock recorder for MockList

func (*MockListMockRecorder) Update

func (mr *MockListMockRecorder) Update(arg0 interface{}) *gomock.Call

Update indicates an expected call of Update

type MockPeer

type MockPeer struct {
	// contains filtered or unexported fields
}

MockPeer is a mock of Peer interface

func NewMockPeer

func NewMockPeer(ctrl *gomock.Controller) *MockPeer

NewMockPeer creates a new mock instance

func (*MockPeer) EXPECT

func (m *MockPeer) EXPECT() *MockPeerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockPeer) EndRequest

func (m *MockPeer) EndRequest()

EndRequest mocks base method

func (*MockPeer) Identifier

func (m *MockPeer) Identifier() string

Identifier mocks base method

func (*MockPeer) StartRequest

func (m *MockPeer) StartRequest()

StartRequest mocks base method

func (*MockPeer) Status

func (m *MockPeer) Status() peer.Status

Status mocks base method

type MockPeerIdentifier

type MockPeerIdentifier string

MockPeerIdentifier is a small wrapper around the PeerIdentifier interfaces for a string unfortunately gomock + assert.Equal has difficulty seeing between mock objects of the same type.

func (MockPeerIdentifier) Identifier

func (pid MockPeerIdentifier) Identifier() string

Identifier returns a unique identifier for MockPeerIDs

type MockPeerMockRecorder

type MockPeerMockRecorder struct {
	// contains filtered or unexported fields
}

MockPeerMockRecorder is the mock recorder for MockPeer

func (*MockPeerMockRecorder) EndRequest

func (mr *MockPeerMockRecorder) EndRequest() *gomock.Call

EndRequest indicates an expected call of EndRequest

func (*MockPeerMockRecorder) Identifier

func (mr *MockPeerMockRecorder) Identifier() *gomock.Call

Identifier indicates an expected call of Identifier

func (*MockPeerMockRecorder) StartRequest

func (mr *MockPeerMockRecorder) StartRequest() *gomock.Call

StartRequest indicates an expected call of StartRequest

func (*MockPeerMockRecorder) Status

func (mr *MockPeerMockRecorder) Status() *gomock.Call

Status indicates an expected call of Status

type MockSubscriber

type MockSubscriber struct {
	// contains filtered or unexported fields
}

MockSubscriber is a mock of Subscriber interface

func NewMockSubscriber

func NewMockSubscriber(ctrl *gomock.Controller) *MockSubscriber

NewMockSubscriber creates a new mock instance

func (*MockSubscriber) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockSubscriber) NotifyStatusChanged

func (m *MockSubscriber) NotifyStatusChanged(arg0 peer.Identifier)

NotifyStatusChanged mocks base method

type MockSubscriberMockRecorder

type MockSubscriberMockRecorder struct {
	// contains filtered or unexported fields
}

MockSubscriberMockRecorder is the mock recorder for MockSubscriber

func (*MockSubscriberMockRecorder) NotifyStatusChanged

func (mr *MockSubscriberMockRecorder) NotifyStatusChanged(arg0 interface{}) *gomock.Call

NotifyStatusChanged indicates an expected call of NotifyStatusChanged

type MockTransport

type MockTransport struct {
	// contains filtered or unexported fields
}

MockTransport is a mock of Transport interface

func NewMockTransport

func NewMockTransport(ctrl *gomock.Controller) *MockTransport

NewMockTransport creates a new mock instance

func (*MockTransport) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockTransport) ReleasePeer

func (m *MockTransport) ReleasePeer(arg0 peer.Identifier, arg1 peer.Subscriber) error

ReleasePeer mocks base method

func (*MockTransport) RetainPeer

func (m *MockTransport) RetainPeer(arg0 peer.Identifier, arg1 peer.Subscriber) (peer.Peer, error)

RetainPeer mocks base method

type MockTransportMockRecorder

type MockTransportMockRecorder struct {
	// contains filtered or unexported fields
}

MockTransportMockRecorder is the mock recorder for MockTransport

func (*MockTransportMockRecorder) ReleasePeer

func (mr *MockTransportMockRecorder) ReleasePeer(arg0, arg1 interface{}) *gomock.Call

ReleasePeer indicates an expected call of ReleasePeer

func (*MockTransportMockRecorder) RetainPeer

func (mr *MockTransportMockRecorder) RetainPeer(arg0, arg1 interface{}) *gomock.Call

RetainPeer indicates an expected call of RetainPeer

type NotifyStatusChangeAction

type NotifyStatusChangeAction struct {
	// PeerID is a unique identifier to the Peer we want use in the notification
	PeerID string

	// NewConnectionStatus is the new ConnectionStatus of the Peer
	NewConnectionStatus peer.ConnectionStatus

	// Unretained indicates that this notify occurs to a peer that has never been
	// retained on the transport (to test edge cases).
	Unretained bool
}

NotifyStatusChangeAction will run the NotifyStatusChange function on a PeerList with a specified Peer after changing the peer's ConnectionStatus

func (NotifyStatusChangeAction) Apply

Apply will run the NotifyStatusChanged function on the PeerList with the provided Peer

type PeerIdentifierMatcher

type PeerIdentifierMatcher string

PeerIdentifierMatcher is used to match a Peer/PeerIdentifier by comparing The peer's .Identifier function with the Matcher string

func (PeerIdentifierMatcher) Matches

func (pim PeerIdentifierMatcher) Matches(got interface{}) bool

Matches returns true of got is equivalent to the PeerIdentifier Matching string

func (PeerIdentifierMatcher) String

func (pim PeerIdentifierMatcher) String() string

String returns a description of the matcher

type PeerListAction

type PeerListAction interface {
	// Apply runs a function on the PeerList and asserts the result
	Apply(*testing.T, peer.Chooser, ListActionDeps)
}

PeerListAction defines actions that can be applied to a PeerList

type ReleaseAction

type ReleaseAction struct {
	InputIdentifierID string
	InputSubscriberID string
	ExpectedErrType   error
}

ReleaseAction will execute the ReleasePeer method on the Transport

func (ReleaseAction) Apply

func (a ReleaseAction) Apply(t *testing.T, transport peer.Transport, deps TransportDeps)

Apply will execute the ReleasePeer method on the Transport

type RetainAction

type RetainAction struct {
	InputIdentifierID string
	InputSubscriberID string
	ExpectedErr       error
	ExpectedPeerID    string
}

RetainAction will execute the RetainPeer method on the Transport

func (RetainAction) Apply

func (a RetainAction) Apply(t *testing.T, transport peer.Transport, deps TransportDeps)

Apply will execute the RetainPeer method on the Transport

type StartAction

type StartAction struct {
	ExpectedErr error
}

StartAction is an action for testing PeerList.Start

func (StartAction) Apply

func (a StartAction) Apply(t *testing.T, pl peer.Chooser, deps ListActionDeps)

Apply runs "Start" on the peerList and validates the error

type StopAction

type StopAction struct {
	ExpectedErr error
}

StopAction is an action for testing PeerList.Stop

func (StopAction) Apply

func (a StopAction) Apply(t *testing.T, pl peer.Chooser, deps ListActionDeps)

Apply runs "Stop" on the peerList and validates the error

type SubscriberDefinition

type SubscriberDefinition struct {
	ID                  string
	ExpectedNotifyCount int
}

SubscriberDefinition is an abstraction for defining a PeerSubscriber with an ID so it can be referenced later.

type TransportAction

type TransportAction interface {
	// Apply runs a function on the Transport and asserts the result
	Apply(*testing.T, peer.Transport, TransportDeps)
}

TransportAction defines actions that can be applied to an Transport

type TransportDeps

type TransportDeps struct {
	PeerIdentifiers map[string]peer.Identifier
	Subscribers     map[string]peer.Subscriber
}

TransportDeps are passed through all the TransportActions in order to pass certain state in between Actions

type UpdateAction

type UpdateAction struct {
	AddedPeerIDs   []string
	RemovedPeerIDs []string
	ExpectedErr    error
}

UpdateAction is an action for adding/removing multiple peers on the PeerList

func (UpdateAction) Apply

func (a UpdateAction) Apply(t *testing.T, pl peer.Chooser, deps ListActionDeps)

Apply runs "Update" on the peer.Chooser after casting it to a peer.List and validates the error

Jump to

Keyboard shortcuts

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