peertest

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAgentActions

func ApplyAgentActions(t *testing.T, agent peer.Agent, actions []AgentAction, d AgentDeps)

ApplyAgentActions runs all the AgentActions on the peer Agent

func ApplyPeerListActions

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

ApplyPeerListActions runs all the PeerListActions on the PeerList

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(
	agent *MockAgent,
	peerStrs []string,
	err error,
)

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

func ExpectPeerRetains

func ExpectPeerRetains(
	agent *MockAgent,
	availablePeerStrs []string,
	unavailablePeerStrs []string,
) map[string]*LightMockPeer

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

func ExpectPeerRetainsWithError

func ExpectPeerRetainsWithError(
	agent *MockAgent,
	peerStrs []string,
	err error,
)

ExpectPeerRetainsWithError registers expectations on a MockAgent return errors

Types

type AddAction

type AddAction struct {
	InputPeerID string
	ExpectedErr error
}

AddAction is an action for adding a peer to the peerlist

func (AddAction) Apply

func (a AddAction) Apply(t *testing.T, pl peer.List, deps ListActionDeps)

Apply runs "Add" on the peerList after casting it to a PeerChangeListener and validates the error

type AgentAction

type AgentAction interface {
	// Apply runs a function on the Agent and asserts the result
	Apply(*testing.T, peer.Agent, AgentDeps)
}

AgentAction defines actions that can be applied to an Agent

type AgentDeps

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

AgentDeps are passed through all the AgentActions in order to pass certain state in between Actions

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.List, deps ListActionDeps)

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

type ChooseMultiAction

type ChooseMultiAction struct {
	ExpectedPeers []string
}

ChooseMultiAction will run ChoosePeer 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.List, deps ListActionDeps)

Apply runs "ChoosePeer" 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.List, 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) StartRequest

func (p *LightMockPeer) StartRequest() func()

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 MockAgent

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

Mock of Agent interface

func NewMockAgent

func NewMockAgent(ctrl *gomock.Controller) *MockAgent

func (*MockAgent) EXPECT

func (_m *MockAgent) EXPECT() *_MockAgentRecorder

func (*MockAgent) ReleasePeer

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

func (*MockAgent) RetainPeer

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

type MockChangeListener

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

Mock of ChangeListener interface

func NewMockChangeListener

func NewMockChangeListener(ctrl *gomock.Controller) *MockChangeListener

func (*MockChangeListener) Add

func (_m *MockChangeListener) Add(_param0 peer.Identifier) error

func (*MockChangeListener) EXPECT

func (_m *MockChangeListener) EXPECT() *_MockChangeListenerRecorder

func (*MockChangeListener) Remove

func (_m *MockChangeListener) Remove(_param0 peer.Identifier) 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) ChoosePeer

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

func (*MockList) EXPECT

func (_m *MockList) EXPECT() *_MockListRecorder

func (*MockList) Start

func (_m *MockList) Start() error

func (*MockList) Stop

func (_m *MockList) Stop() 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) Identifier

func (_m *MockPeer) Identifier() string

func (*MockPeer) StartRequest

func (_m *MockPeer) StartRequest() func()

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

func (a NotifyStatusChangeAction) Apply(t *testing.T, pl peer.List, deps ListActionDeps)

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.List, 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 Agent

func (ReleaseAction) Apply

func (a ReleaseAction) Apply(t *testing.T, agent peer.Agent, deps AgentDeps)

Apply will execute the ReleasePeer method on the Agent

type RemoveAction

type RemoveAction struct {
	InputPeerID string
	ExpectedErr error
}

RemoveAction is an action for adding a peer to the peerlist

func (RemoveAction) Apply

func (a RemoveAction) Apply(t *testing.T, pl peer.List, deps ListActionDeps)

Apply runs "Remove" on the peerList after casting it to a PeerChangeListener and validates the error

type RetainAction

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

RetainAction will execute the RetainPeer method on the Agent

func (RetainAction) Apply

func (a RetainAction) Apply(t *testing.T, agent peer.Agent, deps AgentDeps)

Apply will execute the RetainPeer method on the Agent

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.List, 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.List, 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.

Jump to

Keyboard shortcuts

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