github.com/kaituanwang/hyperledger@v2.0.1+incompatible/discovery/cmd/cmd_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package discovery_test 8 9 import ( 10 "testing" 11 12 discovery "github.com/hyperledger/fabric/discovery/cmd" 13 "github.com/hyperledger/fabric/discovery/cmd/mocks" 14 "github.com/stretchr/testify/assert" 15 "github.com/stretchr/testify/mock" 16 "gopkg.in/alecthomas/kingpin.v2" 17 ) 18 19 func TestAddCommands(t *testing.T) { 20 app := kingpin.New("foo", "bar") 21 cli := &mocks.CommandRegistrar{} 22 configFunc := mock.AnythingOfType("common.CLICommand") 23 cli.On("Command", discovery.PeersCommand, mock.Anything, configFunc).Return(app.Command(discovery.PeersCommand, "")) 24 cli.On("Command", discovery.ConfigCommand, mock.Anything, configFunc).Return(app.Command(discovery.ConfigCommand, "")) 25 cli.On("Command", discovery.EndorsersCommand, mock.Anything, configFunc).Return(app.Command(discovery.EndorsersCommand, "")) 26 discovery.AddCommands(cli) 27 // Ensure that serve and channel flags are were configured for the sub-commands 28 for _, cmd := range []string{discovery.PeersCommand, discovery.ConfigCommand, discovery.EndorsersCommand} { 29 assert.NotNil(t, app.GetCommand(cmd).GetFlag("server")) 30 assert.NotNil(t, app.GetCommand(cmd).GetFlag("channel")) 31 } 32 // Ensure that chaincode and collection flags were called for the endorsers 33 assert.NotNil(t, app.GetCommand(discovery.EndorsersCommand).GetFlag("chaincode")) 34 assert.NotNil(t, app.GetCommand(discovery.EndorsersCommand).GetFlag("collection")) 35 }