github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/client/cmd_test.go (about) 1 package client_test 2 3 import ( 4 "testing" 5 6 "github.com/spf13/cobra" 7 "github.com/stretchr/testify/require" 8 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client" 10 ) 11 12 func TestValidateCmd(t *testing.T) { 13 // setup root and subcommands 14 rootCmd := &cobra.Command{ 15 Use: "root", 16 } 17 queryCmd := &cobra.Command{ 18 Use: "query", 19 } 20 rootCmd.AddCommand(queryCmd) 21 22 // command being tested 23 distCmd := &cobra.Command{ 24 Use: "distr", 25 DisableFlagParsing: true, 26 SuggestionsMinimumDistance: 2, 27 } 28 queryCmd.AddCommand(distCmd) 29 30 commissionCmd := &cobra.Command{ 31 Use: "commission", 32 } 33 distCmd.AddCommand(commissionCmd) 34 35 tests := []struct { 36 reason string 37 args []string 38 wantErr bool 39 }{ 40 {"misspelled command", []string{"comission"}, true}, // nolint: misspell 41 {"no command provided", []string{}, false}, 42 {"help flag", []string{"comission", "--help"}, false}, // nolint: misspell 43 {"shorthand help flag", []string{"comission", "-h"}, false}, // nolint: misspell 44 } 45 46 for _, tt := range tests { 47 err := client.ValidateCmd(distCmd, tt.args) 48 require.Equal(t, tt.wantErr, err != nil, tt.reason) 49 } 50 }