Documentation ¶
Index ¶
- Constants
- Variables
- func NewDiscoveryService(peers ...fab.Peer) fab.DiscoveryService
- func NewMockConfig(channelID string, policy fab.EventServicePolicy) *fabmocks.MockConfig
- type Attempt
- type ConnectAttemptResults
- type ConnectResult
- type Connection
- type ConnectionFactory
- type MockConnection
- func (c *MockConnection) Close()
- func (c *MockConnection) Closed() bool
- func (c *MockConnection) Ledger() servicemocks.Ledger
- func (c *MockConnection) ProduceEvent(event interface{})
- func (c *MockConnection) Receive(eventch chan<- interface{})
- func (c *MockConnection) Result(operation Operation) (ResultDesc, bool)
- func (c *MockConnection) SourceURL() string
- type MockDiscoveryService
- type MockDispatcher
- type MockPeer
- type MockPeerOpt
- type NumBlock
- type NumChaincode
- type Operation
- type OperationMap
- type OperationResult
- type Opt
- type Opts
- type Outcome
- type ProviderFactory
- type Received
- type Result
- type ResultDesc
Constants ¶
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 ¶
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 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
type MockDispatcher ¶
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 ¶
MockPeer contains mock PeerState
func NewMockPeer ¶
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 ¶
BlockHeight returns the block height
func (*MockPeer) SetBlockHeight ¶
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
type OperationMap ¶
type OperationMap map[Operation]ResultDesc
OperationMap maps an Operation to a ResultDesc
type OperationResult ¶
OperationResult contains the result of an operation
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 WithResults ¶
func WithResults(funcResults ...*OperationResult) Opt
WithResults specifies the results for one or more operations
func WithSourceURL ¶
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 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 ¶
ResultDesc describes the result of an operation and optional error string