github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/peer/channel/list_test.go (about) 1 package channel 2 3 import ( 4 "testing" 5 6 "github.com/golang/protobuf/proto" 7 "github.com/hyperledger/fabric/peer/common" 8 pb "github.com/hyperledger/fabric/protos/peer" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestListChannels(t *testing.T) { 13 InitMSP() 14 15 mockChannelResponse := &pb.ChannelQueryResponse{ 16 Channels: []*pb.ChannelInfo{{ 17 ChannelId: "TEST_LIST_CHANNELS", 18 }}, 19 } 20 21 mockPayload, err := proto.Marshal(mockChannelResponse) 22 23 assert.NoError(t, err) 24 25 mockResponse := &pb.ProposalResponse{ 26 Response: &pb.Response{ 27 Status: 200, 28 Payload: mockPayload, 29 }, 30 Endorsement: &pb.Endorsement{}, 31 } 32 33 signer, err := common.GetDefaultSigner() 34 assert.NoError(t, err) 35 36 mockCF := &ChannelCmdFactory{ 37 EndorserClient: common.GetMockEndorserClient(mockResponse, nil), 38 BroadcastFactory: mockBroadcastClientFactory, 39 Signer: signer, 40 } 41 42 cmd := listCmd(mockCF) 43 44 AddFlags(cmd) 45 46 if err := cmd.Execute(); err != nil { 47 t.Fail() 48 t.Error(err) 49 } 50 }