cosmos-sdk/client/cmd_test.go
Alessio Treglia 5a2e59ebb2
Exclude proto files from format (#5706)
* Don't change proto files on make format

The format target does not need to depend on tools.
Thus remove dependency.

* Run make format

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
2020-02-27 07:53:22 -03:00

51 lines
1.1 KiB
Go

package client_test
import (
"testing"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
)
func TestValidateCmd(t *testing.T) {
// setup root and subcommands
rootCmd := &cobra.Command{
Use: "root",
}
queryCmd := &cobra.Command{
Use: "query",
}
rootCmd.AddCommand(queryCmd)
// command being tested
distCmd := &cobra.Command{
Use: "distr",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
queryCmd.AddCommand(distCmd)
commissionCmd := &cobra.Command{
Use: "commission",
}
distCmd.AddCommand(commissionCmd)
tests := []struct {
reason string
args []string
wantErr bool
}{
{"misspelled command", []string{"commission"}, true}, // nolint: misspell
{"no command provided", []string{}, false},
{"help flag", []string{"commission", "--help"}, false}, // nolint: misspell
{"shorthand help flag", []string{"commission", "-h"}, false}, // nolint: misspell
}
for _, tt := range tests {
err := client.ValidateCmd(distCmd, tt.args)
require.Equal(t, tt.wantErr, err != nil, tt.reason)
}
}