forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocks_test.go
118 lines (97 loc) · 2.9 KB
/
mocks_test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// +build testing
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package fabsdk
import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
"github.com/hyperledger/fabric-sdk-go/pkg/core/logging/api"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
"github.com/hyperledger/fabric-sdk-go/pkg/core/logging/modlog"
fabImpl "github.com/hyperledger/fabric-sdk-go/pkg/fab"
sdkApi "github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defcore"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defmsp"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/factory/defsvc"
"github.com/pkg/errors"
)
type mockCorePkg struct {
cryptoSuite core.CryptoSuite
signingManager core.SigningManager
infraProvider fab.InfraProvider
}
func newMockCorePkg(configBackendProvider core.ConfigProvider) (*mockCorePkg, error) {
configBackend, err := configBackendProvider()
if err != nil {
return nil, err
}
endpointConfig, err := fabImpl.ConfigFromBackend(configBackend...)
if err != nil {
return nil, err
}
cryptoSuiteConfig := cryptosuite.ConfigFromBackend(configBackend...)
pkgSuite := defPkgSuite{}
sdkcore, err := pkgSuite.Core()
if err != nil {
return nil, err
}
cs, err := sdkcore.CreateCryptoSuiteProvider(cryptoSuiteConfig)
if err != nil {
return nil, err
}
sm, err := sdkcore.CreateSigningManager(cs)
if err != nil {
return nil, err
}
fp, err := sdkcore.CreateInfraProvider(endpointConfig)
if err != nil {
return nil, err
}
c := mockCorePkg{
cryptoSuite: cs,
signingManager: sm,
infraProvider: fp,
}
return &c, nil
}
func (mc *mockCorePkg) CreateCryptoSuiteProvider(config core.CryptoSuiteConfig) (core.CryptoSuite, error) {
return mc.cryptoSuite, nil
}
func (mc *mockCorePkg) CreateSigningManager(cryptoProvider core.CryptoSuite) (core.SigningManager, error) {
return mc.signingManager, nil
}
func (mc *mockCorePkg) CreateInfraProvider(config fab.EndpointConfig) (fab.InfraProvider, error) {
return mc.infraProvider, nil
}
type mockPkgSuite struct {
errOnCore bool
errOnMsp bool
errOnService bool
errOnLogger bool
}
func (ps *mockPkgSuite) Core() (sdkApi.CoreProviderFactory, error) {
if ps.errOnCore {
return nil, errors.New("Error")
}
return defcore.NewProviderFactory(), nil
}
func (ps *mockPkgSuite) MSP() (sdkApi.MSPProviderFactory, error) {
if ps.errOnMsp {
return nil, errors.New("Error")
}
return defmsp.NewProviderFactory(), nil
}
func (ps *mockPkgSuite) Service() (sdkApi.ServiceProviderFactory, error) {
if ps.errOnService {
return nil, errors.New("Error")
}
return defsvc.NewProviderFactory(), nil
}
func (ps *mockPkgSuite) Logger() (api.LoggerProvider, error) {
if ps.errOnLogger {
return nil, errors.New("Error")
}
return modlog.LoggerProvider(), nil
}