peertest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

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 {
	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
}

Mock of Chooser interface

func NewMockChooser

func NewMockChooser(ctrl *gomock.Controller) *MockChooser

func (*MockChooser) Choose

func (_m *MockChooser) Choose(_param0 context.Context, _param1 *transport.Request) (peer.Peer, func(error), error)

func (*MockChooser) EXPECT

func (_m *MockChooser) EXPECT() *_MockChooserRecorder

func (*MockChooser) IsRunning

func (_m *MockChooser) IsRunning() bool

func (*MockChooser) Start

func (_m *MockChooser) Start() error

func (*MockChooser) Stop

func (_m *MockChooser) Stop() error

type MockIdentifier

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

Mock of Identifier interface

func NewMockIdentifier

func NewMockIdentifier(ctrl *gomock.Controller) *MockIdentifier

func (*MockIdentifier) EXPECT

func (_m *MockIdentifier) EXPECT() *_MockIdentifierRecorder

func (*MockIdentifier) Identifier

func (_m *MockIdentifier) Identifier() string

type MockList

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

Mock of List interface

func NewMockList

func NewMockList(ctrl *gomock.Controller) *MockList

func (*MockList) EXPECT

func (_m *MockList) EXPECT() *_MockListRecorder

func (*MockList) Update

func (_m *MockList) Update(_param0 peer.ListUpdates) error

type MockPeer

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

Mock of Peer interface

func NewMockPeer

func NewMockPeer(ctrl *gomock.Controller) *MockPeer

func (*MockPeer) EXPECT

func (_m *MockPeer) EXPECT() *_MockPeerRecorder

func (*MockPeer) EndRequest

func (_m *MockPeer) EndRequest()

func (*MockPeer) Identifier

func (_m *MockPeer) Identifier() string

func (*MockPeer) StartRequest

func (_m *MockPeer) StartRequest()

func (*MockPeer) Status

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

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 MockSubscriber

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

Mock of Subscriber interface

func NewMockSubscriber

func NewMockSubscriber(ctrl *gomock.Controller) *MockSubscriber

func (*MockSubscriber) EXPECT

func (_m *MockSubscriber) EXPECT() *_MockSubscriberRecorder

func (*MockSubscriber) NotifyStatusChanged

func (_m *MockSubscriber) NotifyStatusChanged(_param0 peer.Identifier)

type MockTransport

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

Mock of Transport interface

func NewMockTransport

func NewMockTransport(ctrl *gomock.Controller) *MockTransport

func (*MockTransport) EXPECT

func (_m *MockTransport) EXPECT() *_MockTransportRecorder

func (*MockTransport) ReleasePeer

func (_m *MockTransport) ReleasePeer(_param0 peer.Identifier, _param1 peer.Subscriber) error

func (*MockTransport) RetainPeer

func (_m *MockTransport) RetainPeer(_param0 peer.Identifier, _param1 peer.Subscriber) (peer.Peer, error)

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
}

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