@cryptotaxi247 / kubo / commits / 5a18554f6

commands: Fixed tests

Matt Bell committed Nov 8, 2014 at 20:45 UTC 5a18554f6e2f725b30fdca60091fa91bbc5b1569
1 file changed +12 -3
commands/response_test.go
+12 -3
@@ -2,6 +2,7 @@ package commands
2
3 import (
4 "fmt"
5 + "strings"
6 "testing"
7 )
8
@@ -36,17 +37,25 @@ func TestMarshalling(t *testing.T) {
37 t.Error(err, "Should have passed")
38 }
39 output := string(bytes)
39 - if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
40 + if removeWhitespace(output) != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
41 t.Error("Incorrect JSON output")
42 }
43
43 - res.SetError(fmt.Errorf("You broke something!"), ErrClient)
44 + res.SetError(fmt.Errorf("Oops!"), ErrClient)
45 bytes, err = res.Marshal()
46 if err != nil {
47 t.Error("Should have passed")
48 }
49 output = string(bytes)
49 - if output != "{\"Message\":\"You broke something!\",\"Code\":1}" {
50 + fmt.Println(removeWhitespace(output))
51 + if removeWhitespace(output) != "{\"Message\":\"Oops!\",\"Code\":1}" {
52 t.Error("Incorrect JSON output")
53 }
54 }
55 +
56 +func removeWhitespace(input string) string {
57 + input = strings.Replace(input, " ", "", -1)
58 + input = strings.Replace(input, "\t", "", -1)
59 + input = strings.Replace(input, "\n", "", -1)
60 + return strings.Replace(input, "\r", "", -1)
61 +}