mocks

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: Apache-2.0 Imports: 9 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

View Source
var ConnFactory = func(opts ...Opt) Connection {
	return NewMockConnection(opts...)
}

ConnFactory creates mock connections

Functions

func NewDiscoveryService

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

NewDiscoveryService returns a new MockDiscoveryService

func NewMockConfig

func NewMockConfig(channelID string, policy fab.EventServicePolicy) *fabmocks.MockConfig

NewMockConfig returns a mock endpoint config with the given event service policy for the given channel

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
	ConnFactory ConnectionFactory
}

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

func NewConnectResult

func NewConnectResult(attempt Attempt, connFactory ConnectionFactory) 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 MockDispatcher

type MockDispatcher struct {
	Error     error
	LastBlock uint64
}

MockDispatcher is a mock Dispatcher

func (*MockDispatcher) EventCh

func (d *MockDispatcher) EventCh() (chan<- interface{}, error)

EventCh simply returns the configured error

func (*MockDispatcher) LastBlockNum

func (d *MockDispatcher) LastBlockNum() uint64

LastBlockNum returns the last block number

func (*MockDispatcher) Start

func (d *MockDispatcher) Start() error

Start returns the configured error

type MockPeer

type MockPeer struct {
	*fabmocks.MockPeer
	// contains filtered or unexported fields
}

MockPeer contains mock PeerState

func NewMockPeer

func NewMockPeer(name, url string, blockHeight uint64) *MockPeer

NewMockPeer returns a new MockPeer Deprecated: This function will be deprecated in the future. Use NewMockStatefulPeer instead.

func NewMockStatefulPeer

func NewMockStatefulPeer(name, url string, opts ...MockPeerOpt) *MockPeer

NewMockStatefulPeer returns a new MockPeer with the given options

func (*MockPeer) BlockHeight

func (p *MockPeer) BlockHeight() uint64

BlockHeight returns the block height

func (*MockPeer) SetBlockHeight

func (p *MockPeer) SetBlockHeight(blockHeight uint64)

SetBlockHeight sets the block height

type MockPeerOpt

type MockPeerOpt func(*MockPeer)

MockPeerOpt is a mock peer option

func WithBlockHeight

func WithBlockHeight(blockHeight uint64) MockPeerOpt

WithBlockHeight sets the block height of the mock peer

func WithMSP

func WithMSP(mspID string) MockPeerOpt

WithMSP sets the MSP ID of the mock peer

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 WithLedger

func WithLedger(ledger servicemocks.Ledger) Opt

WithLedger provides the mock connection with a ledger

func WithResponseDelay

func WithResponseDelay(delay time.Duration) Opt

WithResponseDelay sets the amount of time to wait before returning a response

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
	ResponseDelay time.Duration
}

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