@cryptotaxi247 / kubo / commits / df034c9c0

commands: Updated Command tests for new Response API

Matt Bell committed Oct 10, 2014 at 12:37 UTC df034c9c0be29c4e0dc875a06b63133140c4448d
1 file changed +20 -32
commands/command_test.go
+20 -32
@@ -8,60 +8,58 @@ func TestOptionValidation(t *testing.T) {
8 Option{ []string{ "b", "beep" }, Int },
9 Option{ []string{ "B", "boop" }, String },
10 },
11 - f: func(req *Request) (interface{}, error) {
12 - return nil, nil
13 - },
11 + f: func(req *Request, res *Response) {},
12 }
13
14 req := NewRequest()
15 req.options["foo"] = 5
18 - _, err := cmd.Call(nil, req)
19 - if err == nil {
16 + res := cmd.Call(nil, req)
17 + if res.Error == nil {
18 t.Error("Should have failed (unrecognized command)")
19 }
20
21 req = NewRequest()
22 req.options["beep"] = 5
23 req.options["b"] = 10
26 - _, err = cmd.Call(nil, req)
27 - if err == nil {
24 + res = cmd.Call(nil, req)
25 + if res.Error == nil {
26 t.Error("Should have failed (duplicate options)")
27 }
28
29 req = NewRequest()
30 req.options["beep"] = "foo"
33 - _, err = cmd.Call(nil, req)
34 - if err == nil {
31 + res = cmd.Call(nil, req)
32 + if res.Error == nil {
33 t.Error("Should have failed (incorrect type)")
34 }
35
36 req = NewRequest()
37 req.options["beep"] = 5
40 - _, err = cmd.Call(nil, req)
41 - if err != nil {
38 + res = cmd.Call(nil, req)
39 + if res.Error != nil {
40 t.Error("Should have passed")
41 }
42
43 req = NewRequest()
44 req.options["beep"] = 5
45 req.options["boop"] = "test"
48 - _, err = cmd.Call(nil, req)
49 - if err != nil {
46 + res = cmd.Call(nil, req)
47 + if res.Error != nil {
48 t.Error("Should have passed")
49 }
50
51 req = NewRequest()
52 req.options["b"] = 5
53 req.options["B"] = "test"
56 - _, err = cmd.Call(nil, req)
57 - if err != nil {
54 + res = cmd.Call(nil, req)
55 + if res.Error != nil {
56 t.Error("Should have passed")
57 }
58
59 req = NewRequest()
60 req.options["enc"] = "json"
63 - _, err = cmd.Call(nil, req)
64 - if err != nil {
61 + res = cmd.Call(nil, req)
62 + if res.Error != nil {
63 t.Error("Should have passed")
64 }
65 }
@@ -72,45 +70,35 @@ func TestRegistration(t *testing.T) {
70 Options: []Option{
71 Option{ []string{ "beep" }, Int },
72 },
75 - f: func(req *Request) (interface{}, error) {
76 - return nil, nil
77 - },
73 + f: func(req *Request, res *Response) {},
74 },
75
76 &Command{
77 Options: []Option{
78 Option{ []string{ "boop" }, Int },
79 },
84 - f: func(req *Request) (interface{}, error) {
85 - return nil, nil
86 - },
80 + f: func(req *Request, res *Response) {},
81 },
82
83 &Command{
84 Options: []Option{
85 Option{ []string{ "boop" }, String },
86 },
93 - f: func(req *Request) (interface{}, error) {
94 - return nil, nil
95 - },
87 + f: func(req *Request, res *Response) {},
88 },
89
90 &Command{
91 Options: []Option{
92 Option{ []string{ "bop" }, String },
93 },
102 - f: func(req *Request) (interface{}, error) {
103 - return nil, nil
104 - },
94 + f: func(req *Request, res *Response) {},
95 },
96
97 &Command{
98 Options: []Option{
99 Option{ []string{ "enc" }, String },
100 },
111 - f: func(req *Request) (interface{}, error) {
112 - return nil, nil
113 - },
101 + f: func(req *Request, res *Response) {},
102 },
103 }
104