peertest

package
v1.44.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 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
	ExpectedErrMsg      string
}

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 added in v1.7.0

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

MockChooserList is a mock of ChooserList interface

func NewMockChooserList added in v1.7.0

func NewMockChooserList(ctrl *gomock.Controller) *MockChooserList

NewMockChooserList creates a new mock instance

func (*MockChooserList) Choose added in v1.7.0

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

Choose mocks base method

func (*MockChooserList) EXPECT added in v1.7.0

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

func (*MockChooserList) IsRunning added in v1.7.0

func (m *MockChooserList) IsRunning() bool

IsRunning mocks base method

func (*MockChooserList) Start added in v1.7.0

func (m *MockChooserList) Start() error

Start mocks base method

func (*MockChooserList) Stop added in v1.7.0

func (m *MockChooserList) Stop() error

Stop mocks base method

func (*MockChooserList) Update added in v1.7.0

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

Update mocks base method

type MockChooserListMockRecorder added in v1.10.0

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

MockChooserListMockRecorder is the mock recorder for MockChooserList

func (*MockChooserListMockRecorder) Choose added in v1.10.0

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

Choose indicates an expected call of Choose

func (*MockChooserListMockRecorder) IsRunning added in v1.10.0

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

IsRunning indicates an expected call of IsRunning

func (*MockChooserListMockRecorder) Start added in v1.10.0

Start indicates an expected call of Start

func (*MockChooserListMockRecorder) Stop added in v1.10.0

Stop indicates an expected call of Stop

func (*MockChooserListMockRecorder) Update added in v1.10.0

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

Update indicates an expected call of Update

type MockChooserMockRecorder added in v1.10.0

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

MockChooserMockRecorder is the mock recorder for MockChooser

func (*MockChooserMockRecorder) Choose added in v1.10.0

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

Choose indicates an expected call of Choose

func (*MockChooserMockRecorder) IsRunning added in v1.10.0

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

IsRunning indicates an expected call of IsRunning

func (*MockChooserMockRecorder) Start added in v1.10.0

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

Start indicates an expected call of Start

func (*MockChooserMockRecorder) Stop added in v1.10.0

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 added in v1.10.0

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

MockIdentifierMockRecorder is the mock recorder for MockIdentifier

func (*MockIdentifierMockRecorder) Identifier added in v1.10.0

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 added in v1.10.0

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

MockListMockRecorder is the mock recorder for MockList

func (*MockListMockRecorder) Update added in v1.10.0

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 added in v1.10.0

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

MockPeerMockRecorder is the mock recorder for MockPeer

func (*MockPeerMockRecorder) EndRequest added in v1.10.0

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

EndRequest indicates an expected call of EndRequest

func (*MockPeerMockRecorder) Identifier added in v1.10.0

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

Identifier indicates an expected call of Identifier

func (*MockPeerMockRecorder) StartRequest added in v1.10.0

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

StartRequest indicates an expected call of StartRequest

func (*MockPeerMockRecorder) Status added in v1.10.0

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 added in v1.10.0

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

MockSubscriberMockRecorder is the mock recorder for MockSubscriber

func (*MockSubscriberMockRecorder) NotifyStatusChanged added in v1.10.0

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 added in v1.10.0

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

MockTransportMockRecorder is the mock recorder for MockTransport

func (*MockTransportMockRecorder) ReleasePeer added in v1.10.0

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

ReleasePeer indicates an expected call of ReleasePeer

func (*MockTransportMockRecorder) RetainPeer added in v1.10.0

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