@@ -8,7 +8,6 @@ package resmgmt
88
99import (
1010 "fmt"
11- "net"
1211 "net/http"
1312 "os"
1413 "strings"
@@ -18,10 +17,6 @@ import (
1817 "github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
1918
2019 "github.com/golang/protobuf/proto"
21- "github.com/pkg/errors"
22- "github.com/stretchr/testify/assert"
23- "google.golang.org/grpc"
24-
2520 "github.com/hyperledger/fabric-sdk-go/pkg/common/errors/status"
2621 "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/context"
2722 "github.com/hyperledger/fabric-sdk-go/pkg/common/providers/core"
@@ -40,12 +35,15 @@ import (
4035 "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/cauthdsl"
4136 "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
4237 pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
38+ "github.com/pkg/errors"
39+ "github.com/stretchr/testify/assert"
4340)
4441
4542const (
4643 channelConfig = "../../../test/fixtures/fabric/v1.0/channel/mychannel.tx"
4744 networkCfg = "../../../test/fixtures/config/config_test.yaml"
4845 configPath = "../../core/config/testdata/config_test.yaml"
46+ testAddress = "127.0.0.1:0"
4947)
5048
5149func withLocalContextProvider (provider context.LocalProvider ) ClientOption {
@@ -57,10 +55,10 @@ func withLocalContextProvider(provider context.LocalProvider) ClientOption {
5755
5856func TestJoinChannelFail (t * testing.T ) {
5957
60- grpcServer := grpc .NewServer ()
61- defer grpcServer .Stop ()
58+ srv := & fcmocks.MockEndorserServer {}
59+ addr := srv .Start (testAddress )
60+ defer srv .Stop ()
6261
63- endorserServer , addr := startEndorserServer (t , grpcServer )
6462 ctx := setupTestContext ("test" , "Org1MSP" )
6563
6664 // Create mock orderer with simple mock block
@@ -83,7 +81,7 @@ func TestJoinChannelFail(t *testing.T) {
8381 peer1 , _ := peer .New (fcmocks .NewMockEndpointConfig (), peer .WithURL ("grpc://" + addr ))
8482
8583 // Test fail with send proposal error
86- endorserServer .ProposalError = errors .New ("Test Error" )
84+ srv .ProposalError = errors .New ("Test Error" )
8785 err = rc .JoinChannel ("mychannel" , WithTargets (peer1 ))
8886
8987 if err == nil || ! strings .Contains (err .Error (), "Test Error" ) {
@@ -93,10 +91,10 @@ func TestJoinChannelFail(t *testing.T) {
9391}
9492
9593func TestJoinChannelSuccess (t * testing.T ) {
96- grpcServer := grpc .NewServer ()
97- defer grpcServer .Stop ()
94+ srv := & fcmocks.MockEndorserServer {}
95+ addr := srv .Start (testAddress )
96+ defer srv .Stop ()
9897
99- _ , addr := startEndorserServer (t , grpcServer )
10098 ctx := setupTestContext ("test" , "Org1MSP" )
10199
102100 // Create mock orderer with simple mock block
@@ -129,10 +127,10 @@ func TestWithFilterOption(t *testing.T) {
129127}
130128
131129func TestJoinChannelWithFilter (t * testing.T ) {
132- grpcServer := grpc .NewServer ()
133- defer grpcServer .Stop ()
130+ srv := & fcmocks.MockEndorserServer {}
131+ addr := srv .Start (testAddress )
132+ defer srv .Stop ()
134133
135- _ , addr := startEndorserServer (t , grpcServer )
136134 ctx := setupTestContext ("test" , "Org1MSP" )
137135
138136 // Create mock orderer with simple mock block
@@ -216,10 +214,9 @@ func TestJoinChannelRequiredParameters(t *testing.T) {
216214
217215func TestJoinChannelWithOptsRequiredParameters (t * testing.T ) {
218216
219- grpcServer := grpc .NewServer ()
220- defer grpcServer .Stop ()
221-
222- _ , addr := startEndorserServer (t , grpcServer )
217+ srv := & fcmocks.MockEndorserServer {}
218+ addr := srv .Start (testAddress )
219+ defer srv .Stop ()
223220
224221 ctx := setupTestContext ("test" , "Org1MSP" )
225222 network := getNetworkConfig (t )
@@ -1003,21 +1000,6 @@ func setupCustomOrderer(ctx *fcmocks.MockContext, mockOrderer fab.Orderer) *fcmo
10031000 return ctx
10041001}
10051002
1006- func startEndorserServer (t * testing.T , grpcServer * grpc.Server ) (* fcmocks.MockEndorserServer , string ) {
1007- lis , err := net .Listen ("tcp" , "127.0.0.1:0" )
1008- addr := lis .Addr ().String ()
1009-
1010- endorserServer := & fcmocks.MockEndorserServer {}
1011- pb .RegisterEndorserServer (grpcServer , endorserServer )
1012- if err != nil {
1013- t .Logf ("Error starting test server %s" , err )
1014- t .FailNow ()
1015- }
1016- t .Logf ("Starting test server on %s\n " , addr )
1017- go grpcServer .Serve (lis )
1018- return endorserServer , addr
1019- }
1020-
10211003func getNetworkConfig (t * testing.T ) fab.EndpointConfig {
10221004 configBackend , err := configImpl .FromFile (networkCfg )()
10231005 if err != nil {
@@ -1034,9 +1016,9 @@ func getNetworkConfig(t *testing.T) fab.EndpointConfig {
10341016
10351017func TestSaveChannelSuccess (t * testing.T ) {
10361018
1037- grpcServer := grpc . NewServer ()
1038- defer grpcServer . Stop ( )
1039- _ , addr := fcmocks . StartMockBroadcastServer ( "127.0.0.1:0" , grpcServer )
1019+ mb := fcmocks. MockBroadcastServer {}
1020+ addr := mb . Start ( "127.0.0.1:0" )
1021+ defer mb . Stop ( )
10401022
10411023 ctx := setupTestContext ("test" , "Org1MSP" )
10421024
@@ -1137,9 +1119,9 @@ func TestSaveChannelFailure(t *testing.T) {
11371119
11381120func TestSaveChannelWithOpts (t * testing.T ) {
11391121
1140- grpcServer := grpc . NewServer ()
1141- defer grpcServer . Stop ( )
1142- _ , addr := fcmocks . StartMockBroadcastServer ( "127.0.0.1:0" , grpcServer )
1122+ mb := fcmocks. MockBroadcastServer {}
1123+ addr := mb . Start ( "127.0.0.1:0" )
1124+ defer mb . Stop ( )
11431125
11441126 ctx := setupTestContext ("test" , "Org1MSP" )
11451127
@@ -1210,9 +1192,10 @@ func TestJoinChannelWithInvalidOpts(t *testing.T) {
12101192}
12111193
12121194func TestSaveChannelWithMultipleSigningIdenities (t * testing.T ) {
1213- grpcServer := grpc .NewServer ()
1214- defer grpcServer .Stop ()
1215- _ , addr := fcmocks .StartMockBroadcastServer ("127.0.0.1:0" , grpcServer )
1195+ mb := fcmocks.MockBroadcastServer {}
1196+ addr := mb .Start ("127.0.0.1:0" )
1197+ defer mb .Stop ()
1198+
12161199 ctx := setupTestContext ("test" , "Org1MSP" )
12171200
12181201 mockConfig := & fcmocks.MockConfig {}
0 commit comments