@cryptotaxi247 / kubo / commits / 1e8719e7f

commands: Fixed tests

Matt Bell committed Oct 14, 2014 at 17:37 UTC 1e8719e7f4acb0342f62bc3fee478a2136622a37
2 files changed +14 -5
commands/command_test.go
+2 -2
@@ -15,7 +15,7 @@ func TestOptionValidation(t *testing.T) {
15 req.options["foo"] = 5
16 res := cmd.Call(req)
17 if res.Error == nil {
18 - t.Error("Should have failed (unrecognized command)")
18 + t.Error("Should have failed (unrecognized option)")
19 }
20
21 req = NewRequest()
@@ -37,7 +37,7 @@ func TestOptionValidation(t *testing.T) {
37 req.options["beep"] = 5
38 res = cmd.Call(req)
39 if res.Error != nil {
40 - t.Error("Should have passed")
40 + t.Error(res.Error, "Should have passed")
41 }
42
43 req = NewRequest()
commands/response_test.go
+12 -3
@@ -18,15 +18,24 @@ func TestMarshalling(t *testing.T) {
18 Value: TestOutput{"beep", "boop", 1337},
19 }
20
21 - _, err := res.Marshal()
21 + // get command global options so we can set the encoding option
22 + cmd := Command{}
23 + options, err := cmd.GetOptions(nil)
24 + if err != nil {
25 + t.Error(err)
26 + }
27 +
28 + _, err = res.Marshal()
29 if err == nil {
30 t.Error("Should have failed (no encoding type specified in request)")
31 }
32
26 - req.SetOption(globalOptions[0], Json)
33 + req.SetOption("enc", Json)
34 + req.convertOptions(options)
35 +
36 bytes, err := res.Marshal()
37 if err != nil {
29 - t.Error("Should have passed")
38 + t.Error(err, "Should have passed")
39 }
40 output := string(bytes)
41 if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {