mocks

package
v1.0.0-alpha4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExpectOneBlock expects one block
	ExpectOneBlock NumBlock = 1
	// ExpectTwoBlocks expects two block
	ExpectTwoBlocks NumBlock = 2
	// ExpectThreeBlocks expects three block
	ExpectThreeBlocks NumBlock = 3
	// ExpectFourBlocks expects four block
	ExpectFourBlocks NumBlock = 4
	// ExpectFiveBlocks expects five block
	ExpectFiveBlocks NumBlock = 5
	// ExpectSixBlocks expects six block
	ExpectSixBlocks NumBlock = 6
	// ExpectSevenBlocks expects seven block
	ExpectSevenBlocks NumBlock = 7

	// ExpectOneCC expects one chaincode event
	ExpectOneCC NumChaincode = 1
	// ExpectTwoCC expects two chaincode event
	ExpectTwoCC NumChaincode = 2
	// ExpectThreeCC expects three chaincode event
	ExpectThreeCC NumChaincode = 3
	// ExpectFourCC expects four chaincode event
	ExpectFourCC NumChaincode = 4
)

Variables

This section is empty.

Functions

func NewDiscoveryService

func NewDiscoveryService(peers ...fab.Peer) fab.DiscoveryService

NewDiscoveryService returns a new MockDiscoveryService

Types

type Attempt

type Attempt uint

Attempt specifies the number of connection attempts

const (
	// FirstAttempt is the first attempt
	FirstAttempt Attempt = 1
	// SecondAttempt is the second attempt
	SecondAttempt Attempt = 2
	// ThirdAttempt is the third attempt
	ThirdAttempt Attempt = 3
	// FourthAttempt is the fourth attempt
	FourthAttempt Attempt = 4
)

type ConnectAttemptResults

type ConnectAttemptResults map[Attempt]ConnectResult

ConnectAttemptResults maps a connection attempt to a connection result

func NewConnectResults

func NewConnectResults(results ...ConnectResult) ConnectAttemptResults

NewConnectResults returns a new ConnectAttemptResults

type ConnectResult

type ConnectResult struct {
	Attempt Attempt
	Result  Result
}

ConnectResult contains the data to use for the N'th connection attempt

func NewConnectResult

func NewConnectResult(attempt Attempt, result Result) ConnectResult

NewConnectResult returns a new ConnectResult

type Connection

type Connection interface {
	api.Connection

	// ProduceEvent send the given event to the event channel
	ProduceEvent(event interface{})
	// Result returns the result for the given operation
	Result(operation Operation) (ResultDesc, bool)
	// Ledger returns the mock ledger
	Ledger() servicemocks.Ledger
}

Connection extends Connection and adds functions to allow simulating certain situations

type ConnectionFactory

type ConnectionFactory func(opts ...Opt) Connection

ConnectionFactory creates a new mock connection

type MockConnection

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

MockConnection is a mock connection used for unit testing

func NewMockConnection

func NewMockConnection(opts ...Opt) *MockConnection

NewMockConnection returns a new MockConnection using the given options

func (*MockConnection) Close

func (c *MockConnection) Close()

Close implements the MockConnection interface

func (*MockConnection) Closed

func (c *MockConnection) Closed() bool

Closed return true if the connection is closed

func (*MockConnection) Ledger

func (c *MockConnection) Ledger() servicemocks.Ledger

Ledger returns the mock ledger

func (*MockConnection) ProduceEvent

func (c *MockConnection) ProduceEvent(event interface{})

ProduceEvent send the given event to the event channel

func (*MockConnection) Receive

func (c *MockConnection) Receive(eventch chan<- interface{})

Receive implements the MockConnection interface

func (*MockConnection) Result

func (c *MockConnection) Result(operation Operation) (ResultDesc, bool)

Result returns the result for the given operation

func (*MockConnection) SourceURL

func (c *MockConnection) SourceURL() string

SourceURL returns the event source

type MockDiscoveryService

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

MockDiscoveryService is a mock discovery service used for event endpoint discovery

func (*MockDiscoveryService) GetPeers

func (s *MockDiscoveryService) GetPeers() ([]fab.Peer, error)

GetPeers returns a list of discovered peers

type NumBlock

type NumBlock uint

NumBlock is the number of block events received

type NumChaincode

type NumChaincode uint

NumChaincode is the number of chaincode events received

type Operation

type Operation string

Operation is the operation being performed

type OperationMap

type OperationMap map[Operation]ResultDesc

OperationMap maps an Operation to a ResultDesc

type OperationResult

type OperationResult struct {
	Operation  Operation
	Result     Result
	ErrMessage string
}

OperationResult contains the result of an operation

func NewResult

func NewResult(operation Operation, result Result, errMsg ...string) *OperationResult

NewResult returns a new OperationResult

type Opt

type Opt func(opts *Opts)

Opt applies an option

func WithFactory

func WithFactory(factory ConnectionFactory) Opt

WithFactory specifies the connection factory for creating new mock connections

func WithLedger

func WithLedger(ledger servicemocks.Ledger) Opt

WithLedger provides the mock connection with a ledger

func WithResults

func WithResults(funcResults ...*OperationResult) Opt

WithResults specifies the results for one or more operations

func WithSourceURL

func WithSourceURL(sourceURL string) Opt

WithSourceURL provides the mock connection with an event source

type Opts

type Opts struct {
	Ledger     servicemocks.Ledger
	Operations OperationMap
	Factory    ConnectionFactory
	SourceURL  string
}

Opts contains mock connection options

type Outcome

type Outcome string

Outcome is the outcome of the attempt

const (
	// ReconnectedOutcome means that the client reconnect
	ReconnectedOutcome Outcome = "reconnected"
	// ClosedOutcome means that the client was closed
	ClosedOutcome Outcome = "closed"
	// TimedOutOutcome means that the client timed out
	TimedOutOutcome Outcome = "timeout"
	// ConnectedOutcome means that the client connect
	ConnectedOutcome Outcome = "connected"
	// ErrorOutcome means that the operation resulted in an error
	ErrorOutcome Outcome = "error"
)

type ProviderFactory

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

ProviderFactory creates various mock MockConnection Providers

func NewProviderFactory

func NewProviderFactory() *ProviderFactory

NewProviderFactory returns a new ProviderFactory

func (*ProviderFactory) Connection

func (cp *ProviderFactory) Connection() Connection

Connection returns the connection

func (*ProviderFactory) FlakeyProvider

func (cp *ProviderFactory) FlakeyProvider(connAttemptResults ConnectAttemptResults, opts ...Opt) api.ConnectionProvider

FlakeyProvider creates a connection provider that returns a connection according to the given connection attempt results. The results tell the connection provider whether or not to fail, to return a connection, what authorization to give the connection, etc.

func (*ProviderFactory) Provider

func (cp *ProviderFactory) Provider(conn Connection) api.ConnectionProvider

Provider returns a connection provider that always returns the given connection

type Received

type Received struct {
	NumBlock     NumBlock
	NumChaincode NumChaincode
}

Received contains the number of block and chaincode events received

func NewReceived

func NewReceived(numBlock NumBlock, numChaincode NumChaincode) Received

NewReceived returns a new Received struct

type Result

type Result string

Result is the result to take for a given operation

const (
	// SucceedResult indicates that the operation should succeed
	SucceedResult Result = "succeed"

	// FailResult indicates that the operation should fail
	FailResult Result = "fail"

	// NoOpResult indicates that the operation should be ignored (i.e. just do nothing)
	// This should result in the client timing out waiting for a response.
	NoOpResult Result = "no-op"
)

type ResultDesc

type ResultDesc struct {
	Result Result
	ErrMsg string
}

ResultDesc describes the result of an operation and optional error string

Jump to

Keyboard shortcuts

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