| 53 | } |
| 54 | |
| 55 | func TestFindAlias(t *testing.T) { |
| 56 | cmd := newCmd("root", "") |
| 57 | subcmd := newCmd("child1", "") |
| 58 | subcmd.Aliases = []string{"alias1", "alias2"} |
| 59 | cmd.AddCmd(subcmd) |
| 60 | |
| 61 | res, err := cmd.FindCmd([]string{"alias1"}) |
| 62 | if err != nil { |
| 63 | t.Fatal("finding alias should work") |
| 64 | } |
| 65 | assert.Equal(t, res.Name, "child1") |
| 66 | |
| 67 | res, err = cmd.FindCmd([]string{"alias2"}) |
| 68 | if err != nil { |
| 69 | t.Fatal("finding alias should work") |
| 70 | } |
| 71 | assert.Equal(t, res.Name, "child1") |
| 72 | |
| 73 | res, err = cmd.FindCmd([]string{"alias3"}) |
| 74 | if err == nil { |
| 75 | t.Fatal("should not find this child!") |
| 76 | } |
| 77 | assert.Nil(t, res) |
| 78 | } |
| 79 | |
| 80 | func TestHelpText(t *testing.T) { |
| 81 | cmd := newCmd("root", "help for root command") |