fabric-sdk-go: github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/mocks Index | Files

package mocks

import "github.com/hyperledger/fabric-sdk-go/pkg/fab/events/client/mocks"


Package Files

mockconnection.go mockdiscovery.go mockdispatcher.go mockpeer.go numevents.go util.go


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


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

ConnFactory creates mock connections

func NewDiscoveryService Uses

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

NewDiscoveryService returns a new MockDiscoveryService

func NewMockConfig Uses

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

type Attempt Uses

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 Uses

type ConnectAttemptResults map[Attempt]ConnectResult

ConnectAttemptResults maps a connection attempt to a connection result

func NewConnectResults Uses

func NewConnectResults(results ...ConnectResult) ConnectAttemptResults

NewConnectResults returns a new ConnectAttemptResults

type ConnectResult Uses

type ConnectResult struct {
    Attempt     Attempt
    ConnFactory ConnectionFactory

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

func NewConnectResult Uses

func NewConnectResult(attempt Attempt, connFactory ConnectionFactory) ConnectResult

NewConnectResult returns a new ConnectResult

type Connection Uses

type Connection interface {

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

type ConnectionFactory func(opts ...Opt) Connection

ConnectionFactory creates a new mock connection

type MockConnection Uses

type MockConnection struct {
    // contains filtered or unexported fields

MockConnection is a mock connection used for unit testing

func NewMockConnection Uses

func NewMockConnection(opts ...Opt) *MockConnection

NewMockConnection returns a new MockConnection using the given options

func (*MockConnection) Close Uses

func (c *MockConnection) Close()

Close implements the MockConnection interface

func (*MockConnection) Closed Uses

func (c *MockConnection) Closed() bool

Closed return true if the connection is closed

func (*MockConnection) Ledger Uses

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

Ledger returns the mock ledger

func (*MockConnection) ProduceEvent Uses

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

ProduceEvent send the given event to the event channel

func (*MockConnection) Receive Uses

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

Receive implements the MockConnection interface

func (*MockConnection) Result Uses

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

Result returns the result for the given operation

func (*MockConnection) SourceURL Uses

func (c *MockConnection) SourceURL() string

SourceURL returns the event source

type MockDiscoveryService Uses

type MockDiscoveryService struct {
    // contains filtered or unexported fields

MockDiscoveryService is a mock discovery service used for event endpoint discovery

func (*MockDiscoveryService) GetPeers Uses

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

GetPeers returns a list of discovered peers

type MockDispatcher Uses

type MockDispatcher struct {
    Error     error
    LastBlock uint64

MockDispatcher is a mock Dispatcher

func (*MockDispatcher) EventCh Uses

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

EventCh simply returns the configured error

func (*MockDispatcher) LastBlockNum Uses

func (d *MockDispatcher) LastBlockNum() uint64

LastBlockNum returns the last block number

func (*MockDispatcher) Start Uses

func (d *MockDispatcher) Start() error

Start returns the configured error

type MockPeer Uses

type MockPeer struct {
    // contains filtered or unexported fields

MockPeer contains mock PeerState

func NewMockPeer Uses

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 Uses

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

NewMockStatefulPeer returns a new MockPeer with the given options

func (*MockPeer) BlockHeight Uses

func (p *MockPeer) BlockHeight() uint64

BlockHeight returns the block height

func (*MockPeer) SetBlockHeight Uses

func (p *MockPeer) SetBlockHeight(blockHeight uint64)

SetBlockHeight sets the block height

type MockPeerOpt Uses

type MockPeerOpt func(*MockPeer)

MockPeerOpt is a mock peer option

func WithBlockHeight Uses

func WithBlockHeight(blockHeight uint64) MockPeerOpt

WithBlockHeight sets the block height of the mock peer

func WithMSP Uses

func WithMSP(mspID string) MockPeerOpt

WithMSP sets the MSP ID of the mock peer

type NumBlock Uses

type NumBlock uint

NumBlock is the number of block events received

type NumChaincode Uses

type NumChaincode uint

NumChaincode is the number of chaincode events received

type Operation Uses

type Operation string

Operation is the operation being performed

type OperationMap Uses

type OperationMap map[Operation]ResultDesc

OperationMap maps an Operation to a ResultDesc

type OperationResult Uses

type OperationResult struct {
    Operation  Operation
    Result     Result
    ErrMessage string

OperationResult contains the result of an operation

func NewResult Uses

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

NewResult returns a new OperationResult

type Opt Uses

type Opt func(opts *Opts)

Opt applies an option

func WithLedger Uses

func WithLedger(ledger servicemocks.Ledger) Opt

WithLedger provides the mock connection with a ledger

func WithResponseDelay Uses

func WithResponseDelay(delay time.Duration) Opt

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

func WithResults Uses

func WithResults(funcResults ...*OperationResult) Opt

WithResults specifies the results for one or more operations

func WithSourceURL Uses

func WithSourceURL(sourceURL string) Opt

WithSourceURL provides the mock connection with an event source

type Opts Uses

type Opts struct {
    Ledger        servicemocks.Ledger
    Operations    OperationMap
    Factory       ConnectionFactory
    SourceURL     string
    ResponseDelay time.Duration

Opts contains mock connection options

type Outcome Uses

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 Uses

type ProviderFactory struct {
    // contains filtered or unexported fields

ProviderFactory creates various mock MockConnection Providers

func NewProviderFactory Uses

func NewProviderFactory() *ProviderFactory

NewProviderFactory returns a new ProviderFactory

func (*ProviderFactory) Connection Uses

func (cp *ProviderFactory) Connection() Connection

Connection returns the connection

func (*ProviderFactory) FlakeyProvider Uses

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 Uses

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

Provider returns a connection provider that always returns the given connection

type Received Uses

type Received struct {
    NumBlock     NumBlock
    NumChaincode NumChaincode

Received contains the number of block and chaincode events received

func NewReceived Uses

func NewReceived(numBlock NumBlock, numChaincode NumChaincode) Received

NewReceived returns a new Received struct

type Result Uses

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 Uses

type ResultDesc struct {
    Result Result
    ErrMsg string

ResultDesc describes the result of an operation and optional error string

Package mocks imports 9 packages (graph) and is imported by 1 packages. Updated 2020-06-06. Refresh now. Tools for package owners.