Documentation ¶
Index ¶
- Constants
- func NewDiscoveryProvider(peers ...fab.Peer) fab.DiscoveryProvider
- 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)
- type MockDiscoveryProvider
- type MockDiscoveryService
- 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 ¶
This section is empty.
Functions ¶
func NewDiscoveryProvider ¶
func NewDiscoveryProvider(peers ...fab.Peer) fab.DiscoveryProvider
NewDiscoveryProvider returns a new MockDiscoveryProvider
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 ¶
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
type MockDiscoveryProvider ¶
type MockDiscoveryProvider struct {
// contains filtered or unexported fields
}
MockDiscoveryProvider mockcore out the discovery provider
func (*MockDiscoveryProvider) CreateDiscoveryService ¶
func (p *MockDiscoveryProvider) CreateDiscoveryService(channelID string) (fab.DiscoveryService, error)
CreateDiscoveryService returns a new MockDiscoveryService
type MockDiscoveryService ¶
type MockDiscoveryService struct {
// contains filtered or unexported fields
}
MockDiscoveryService is a mock discovery service used for event endpoint discovery
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 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
type Opts ¶
type Opts struct { Ledger servicemocks.Ledger Operations OperationMap Factory ConnectionFactory }
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 ¶
ResultDesc describes the result of an operation and optional error string