github.com/yimialmonte/fabric@v2.1.1+incompatible/discovery/cmd/stub_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package discovery 8 9 import ( 10 "fmt" 11 "net" 12 "path/filepath" 13 "testing" 14 15 "github.com/hyperledger/fabric/cmd/common" 16 "github.com/hyperledger/fabric/cmd/common/comm" 17 "github.com/hyperledger/fabric/cmd/common/signer" 18 discovery "github.com/hyperledger/fabric/discovery/client" 19 corecomm "github.com/hyperledger/fabric/internal/pkg/comm" 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestClientStub(t *testing.T) { 24 srv, err := corecomm.NewGRPCServer("127.0.0.1:", corecomm.ServerConfig{ 25 SecOpts: corecomm.SecureOptions{}, 26 }) 27 assert.NoError(t, err) 28 go srv.Start() 29 defer srv.Stop() 30 31 _, portStr, _ := net.SplitHostPort(srv.Address()) 32 endpoint := fmt.Sprintf("localhost:%s", portStr) 33 stub := &ClientStub{} 34 35 req := discovery.NewRequest() 36 37 _, err = stub.Send(endpoint, common.Config{ 38 SignerConfig: signer.Config{ 39 MSPID: "Org1MSP", 40 KeyPath: filepath.Join("testdata", "8150cb2d09628ccc89727611ebb736189f6482747eff9b8aaaa27e9a382d2e93_sk"), 41 IdentityPath: filepath.Join("testdata", "cert.pem"), 42 }, 43 TLSConfig: comm.Config{}, 44 }, req) 45 assert.Contains(t, err.Error(), "Unimplemented desc = unknown service discovery.Discovery") 46 } 47 48 func TestRawStub(t *testing.T) { 49 srv, err := corecomm.NewGRPCServer("127.0.0.1:", corecomm.ServerConfig{ 50 SecOpts: corecomm.SecureOptions{}, 51 }) 52 assert.NoError(t, err) 53 go srv.Start() 54 defer srv.Stop() 55 56 _, portStr, _ := net.SplitHostPort(srv.Address()) 57 endpoint := fmt.Sprintf("localhost:%s", portStr) 58 stub := &RawStub{} 59 60 req := discovery.NewRequest() 61 62 _, err = stub.Send(endpoint, common.Config{ 63 SignerConfig: signer.Config{ 64 MSPID: "Org1MSP", 65 KeyPath: filepath.Join("testdata", "8150cb2d09628ccc89727611ebb736189f6482747eff9b8aaaa27e9a382d2e93_sk"), 66 IdentityPath: filepath.Join("testdata", "cert.pem"), 67 }, 68 TLSConfig: comm.Config{}, 69 }, req) 70 assert.Contains(t, err.Error(), "Unimplemented desc = unknown service discovery.Discovery") 71 }