|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "io/ioutil" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/sideninja/flow-cli/cmd/account/get" |
| 9 | + |
| 10 | + "github.com/sideninja/flow-cli/cmd" |
| 11 | + "github.com/sideninja/flow-cli/gateway" |
| 12 | + "github.com/stretchr/testify/assert" |
| 13 | +) |
| 14 | + |
| 15 | +func Test_RootCommand(t *testing.T) { |
| 16 | + var gateway gateway.IGateway = GetMockGateway() |
| 17 | + b := bytes.NewBufferString("") |
| 18 | + |
| 19 | + command := cmd.NewCmdRoot(gateway, "1.0") |
| 20 | + command.SetOut(b) |
| 21 | + command.Execute() |
| 22 | + |
| 23 | + out, err := ioutil.ReadAll(b) |
| 24 | + if err != nil { |
| 25 | + t.Fatal(err) |
| 26 | + } |
| 27 | + |
| 28 | + assert.Equal(t, string(out), "\nFlow CLI tool to interact with flow emulator.\n\nUsage:\n flow [command]\n\nAvailable Commands:\n account Get account information, create account, add account key\n config Save persistent configuration\n help Help about any command\n\nFlags:\n -h, --help help for flow\n -j, --json show output format as JSON\n -v, --version show version information\n\nUse \"flow [command] --help\" for more information about a command.\n") |
| 29 | +} |
| 30 | + |
| 31 | +func Test_AccountCommandGeneral(t *testing.T) { |
| 32 | + var gateway gateway.IGateway = GetMockGateway() |
| 33 | + b := bytes.NewBufferString("") |
| 34 | + |
| 35 | + command := get.NewCmdGet(gateway, "1.0") |
| 36 | + command.SetOut(b) |
| 37 | + command.Execute() |
| 38 | + |
| 39 | + out, err := ioutil.ReadAll(b) |
| 40 | + if err != nil { |
| 41 | + t.Fatal(err) |
| 42 | + } |
| 43 | + |
| 44 | + assert.Equal(t, string(out), "Usage:\n get <address> [flags]\n\nAliases:\n get, fetch, g\n\nFlags:\n -a, --api string set discovery api host on the fly only for this request\n -b, --block-height int gets an account at the given block height (default -1)\n -f, --filter string filter output to show only provided field (address, balance, code, keys)\n -h, --help help for get\n -j, --json show output format as JSON\n\n") |
| 45 | +} |
| 46 | + |
| 47 | +func Test_AccountTooManyArgs(t *testing.T) { |
| 48 | + var gateway gateway.IGateway = GetMockGateway() |
| 49 | + b := bytes.NewBufferString("") |
| 50 | + |
| 51 | + command := get.NewCmdGet(gateway, "1.0") |
| 52 | + |
| 53 | + command.SetArgs([]string{"123", "123"}) |
| 54 | + command.SetOut(b) |
| 55 | + command.SetErr(b) |
| 56 | + command.Execute() |
| 57 | + |
| 58 | + out, err := ioutil.ReadAll(b) |
| 59 | + if err != nil { |
| 60 | + t.Fatal(err) |
| 61 | + } |
| 62 | + |
| 63 | + assert.Equal(t, string(out), "Error: accepts 1 arg(s), received 2\nUsage:\n get <address> [flags]\n\nAliases:\n get, fetch, g\n\nFlags:\n -a, --api string set discovery api host on the fly only for this request\n -b, --block-height int gets an account at the given block height (default -1)\n -f, --filter string filter output to show only provided field (address, balance, code, keys)\n -h, --help help for get\n -j, --json show output format as JSON\n\n") |
| 64 | +} |
| 65 | + |
| 66 | +func Test_AccountWrongArgs(t *testing.T) { |
| 67 | + var gateway gateway.IGateway = GetMockGateway() |
| 68 | + b := bytes.NewBufferString("") |
| 69 | + |
| 70 | + command := get.NewCmdGet(gateway, "1.0") |
| 71 | + |
| 72 | + command.SetArgs([]string{}) |
| 73 | + command.SetOut(b) |
| 74 | + command.SetErr(b) |
| 75 | + command.Execute() |
| 76 | + |
| 77 | + out, err := ioutil.ReadAll(b) |
| 78 | + if err != nil { |
| 79 | + t.Fatal(err) |
| 80 | + } |
| 81 | + |
| 82 | + assert.Equal(t, string(out), "Error: accepts 1 arg(s), received 0\nUsage:\n get <address> [flags]\n\nAliases:\n get, fetch, g\n\nFlags:\n -a, --api string set discovery api host on the fly only for this request\n -b, --block-height int gets an account at the given block height (default -1)\n -f, --filter string filter output to show only provided field (address, balance, code, keys)\n -h, --help help for get\n -j, --json show output format as JSON\n\n") |
| 83 | +} |
0 commit comments