forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mocks.go
48 lines (38 loc) · 1.19 KB
/
mocks.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package comm
import (
"context"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
fabmocks "github.com/hyperledger/fabric-sdk-go/pkg/fab/mocks"
"google.golang.org/grpc"
)
// MockCommManager is a non-caching comm manager used
// for unit testing
type MockCommManager struct {
}
// DialContext creates a connection
func (m *MockCommManager) DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return grpc.DialContext(ctx, target, opts...)
}
// ReleaseConn closes the connection
func (m *MockCommManager) ReleaseConn(conn *grpc.ClientConn) {
if err := conn.Close(); err != nil {
logger.Warnf("Error closing connection: %s", err)
}
}
// MockInfraProvider overrides the comm manager to return
// the MockCommManager
type MockInfraProvider struct {
fabmocks.MockInfraProvider
}
// NewMockInfraProvider return a new MockInfraProvider
func NewMockInfraProvider() *MockInfraProvider {
return &MockInfraProvider{}
}
// CommManager returns the MockCommManager
func (f *MockInfraProvider) CommManager() fab.CommManager {
return &MockCommManager{}
}