forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockfabricprovider.go
77 lines (60 loc) · 2.21 KB
/
mockfabricprovider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"fmt"
"github.com/hyperledger/fabric-sdk-go/pkg/common/options"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
)
// MockInfraProvider represents the default implementation of Fabric objects.
type MockInfraProvider struct {
customOrderer fab.Orderer
}
// CreateEventService creates the event service.
func (f *MockInfraProvider) CreateEventService(ic fab.ClientContext, channelID string, opts ...options.Opt) (fab.EventService, error) {
panic("not implemented")
}
// CreateChannelCfg creates the channel configuration
func (f *MockInfraProvider) CreateChannelCfg(ctx fab.ClientContext, name string) (fab.ChannelCfg, error) {
return nil, nil
}
// CreateChannelMembership returns a channel member identifier
func (f *MockInfraProvider) CreateChannelMembership(ctx fab.ClientContext, channel string) (fab.ChannelMembership, error) {
return nil, fmt.Errorf("Not implemented")
}
// CreateChannelConfig initializes the channel config
func (f *MockInfraProvider) CreateChannelConfig(channelID string) (fab.ChannelConfig, error) {
return nil, nil
}
// CreatePeerFromConfig returns a new default implementation of Peer based configuration
func (f *MockInfraProvider) CreatePeerFromConfig(peerCfg *fab.NetworkPeer) (fab.Peer, error) {
if peerCfg != nil {
p := NewMockPeer(peerCfg.MSPID, peerCfg.URL)
p.SetMSPID(peerCfg.MSPID)
return p, nil
}
return &MockPeer{}, nil
}
// CreateOrdererFromConfig creates a default implementation of Orderer based on configuration.
func (f *MockInfraProvider) CreateOrdererFromConfig(cfg *fab.OrdererConfig) (fab.Orderer, error) {
if f.customOrderer != nil {
return f.customOrderer, nil
}
if cfg.URL != "" {
return &MockOrderer{OrdererURL: cfg.URL}, nil
}
return &MockOrderer{}, nil
}
//CommManager returns comm provider
func (f *MockInfraProvider) CommManager() fab.CommManager {
return nil
}
// SetCustomOrderer creates a default implementation of Orderer based on configuration.
func (f *MockInfraProvider) SetCustomOrderer(customOrderer fab.Orderer) {
f.customOrderer = customOrderer
}
//Close mock close function
func (f *MockInfraProvider) Close() {
}