@cryptotaxi247 / kubo / commits / 97ce60f8a

commands: Added global options list to command tests

Matt Bell committed Oct 10, 2014 at 11:42 UTC 97ce60f8a4843eb660457747237e5ad768dc0dd0
1 file changed +21
commands/command_test.go
+21
@@ -57,6 +57,13 @@ func TestOptionValidation(t *testing.T) {
57 if err != nil {
58 t.Error("Should have passed")
59 }
60 +
61 + req = NewRequest()
62 + req.options["enc"] = "json"
63 + _, err = cmd.Call(nil, req)
64 + if err != nil {
65 + t.Error("Should have passed")
66 + }
67 }
68
69 func TestRegistration(t *testing.T) {
@@ -96,6 +103,15 @@ func TestRegistration(t *testing.T) {
103 return nil, nil
104 },
105 },
106 +
107 + &Command{
108 + Options: []Option{
109 + Option{ []string{ "enc" }, String },
110 + },
111 + f: func(req *Request) (interface{}, error) {
112 + return nil, nil
113 + },
114 + },
115 }
116
117 err := cmds[0].Register("foo", cmds[1])
@@ -112,4 +128,9 @@ func TestRegistration(t *testing.T) {
128 if err == nil {
129 t.Error("Should have failed (subcommand name collision)")
130 }
131 +
132 + err = cmds[0].Register("baz", cmds[4])
133 + if err == nil {
134 + t.Error("Should have failed (option name collision with global options)")
135 + }
136 }