@cryptotaxi247 / kubo / commits / dd81bf630

commands: Fixed tests

Matt Bell committed Oct 21, 2014 at 18:06 UTC dd81bf630fe616d7068aae82d9150d1db31b40e3
2 files changed +40 -52
commands/cli/parse_test.go
+3 -1
@@ -12,8 +12,10 @@ func TestOptionParsing(t *testing.T) {
12 Options: []commands.Option{
13 commands.Option{Names: []string{"b"}, Type: commands.String},
14 },
15 + Subcommands: map[string]*commands.Command{
16 + "test": &commands.Command{},
17 + },
18 }
16 - cmd.Register("test", &commands.Command{})
19
20 opts, input, err := parseOptions([]string{"--beep", "-boop=lol", "test2", "-c", "beep", "--foo=5"})
21 /*for k, v := range opts {
commands/command_test.go
+37 -51
@@ -80,75 +80,61 @@ func TestOptionValidation(t *testing.T) {
80
81 func TestRegistration(t *testing.T) {
82 noop := func(req Request, res Response) {}
83 - cmds := []*Command{
84 - &Command{
85 - Options: []Option{
86 - Option{[]string{"beep"}, Int},
87 - },
88 - Run: noop,
89 - },
90 -
91 - &Command{
92 - Options: []Option{
93 - Option{[]string{"boop"}, Int},
94 - },
95 - Run: noop,
96 - },
83
98 - &Command{
99 - Options: []Option{
100 - Option{[]string{"boop"}, String},
101 - },
102 - Run: noop,
84 + cmdA := &Command{
85 + Options: []Option{
86 + Option{[]string{"beep"}, Int},
87 },
88 + Run: noop,
89 + }
90
105 - &Command{
106 - Options: []Option{
107 - Option{[]string{"bop"}, String},
108 - },
109 - Run: noop,
91 + cmdB := &Command{
92 + Options: []Option{
93 + Option{[]string{"beep"}, Int},
94 },
111 -
112 - &Command{
113 - Options: []Option{
114 - Option{[]string{EncShort}, String},
115 - },
116 - Run: noop,
95 + Run: noop,
96 + Subcommands: map[string]*Command{
97 + "a": cmdA,
98 },
99 }
100
120 - err := cmds[0].Register("foo", cmds[1])
121 - if err != nil {
122 - t.Error("Should have passed")
101 + cmdC := &Command{
102 + Options: []Option{
103 + Option{[]string{"encoding"}, String},
104 + },
105 + Run: noop,
106 }
107
125 - err = cmds[0].Register("bar", cmds[2])
126 - if err == nil {
108 + res := cmdB.Call(NewRequest([]string{"a"}, nil, nil, nil))
109 + if res.Error() == nil {
110 t.Error("Should have failed (option name collision)")
111 }
112
130 - err = cmds[0].Register("foo", cmds[3])
131 - if err == nil {
132 - t.Error("Should have failed (subcommand name collision)")
133 - }
134 -
135 - err = cmds[0].Register("baz", cmds[4])
136 - if err == nil {
113 + res = cmdC.Call(NewEmptyRequest())
114 + if res.Error() == nil {
115 t.Error("Should have failed (option name collision with global options)")
116 }
117 }
118
119 func TestResolving(t *testing.T) {
142 - cmd := &Command{}
143 - cmdA := &Command{}
144 - cmdB := &Command{}
145 - cmdB2 := &Command{}
120 cmdC := &Command{}
147 -
148 - cmd.Register("a", cmdA)
149 - cmdA.Register("B", cmdB2)
150 - cmdA.Register("b", cmdB)
151 - cmdB.Register("c", cmdC)
121 + cmdB := &Command{
122 + Subcommands: map[string]*Command{
123 + "c": cmdC,
124 + },
125 + }
126 + cmdB2 := &Command{}
127 + cmdA := &Command{
128 + Subcommands: map[string]*Command{
129 + "b": cmdB,
130 + "B": cmdB2,
131 + },
132 + }
133 + cmd := &Command{
134 + Subcommands: map[string]*Command{
135 + "a": cmdA,
136 + },
137 + }
138
139 cmds, err := cmd.Resolve([]string{"a", "b", "c"})
140 if err != nil {