提交 5a18554f 作者: Matt Bell 提交者: Juan Batiz-Benet

commands: Fixed tests

上级 652e3d05
...@@ -2,6 +2,7 @@ package commands ...@@ -2,6 +2,7 @@ package commands
import ( import (
"fmt" "fmt"
"strings"
"testing" "testing"
) )
...@@ -36,17 +37,25 @@ func TestMarshalling(t *testing.T) { ...@@ -36,17 +37,25 @@ func TestMarshalling(t *testing.T) {
t.Error(err, "Should have passed") t.Error(err, "Should have passed")
} }
output := string(bytes) output := string(bytes)
if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" { if removeWhitespace(output) != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
t.Error("Incorrect JSON output") t.Error("Incorrect JSON output")
} }
res.SetError(fmt.Errorf("You broke something!"), ErrClient) res.SetError(fmt.Errorf("Oops!"), ErrClient)
bytes, err = res.Marshal() bytes, err = res.Marshal()
if err != nil { if err != nil {
t.Error("Should have passed") t.Error("Should have passed")
} }
output = string(bytes) output = string(bytes)
if output != "{\"Message\":\"You broke something!\",\"Code\":1}" { fmt.Println(removeWhitespace(output))
if removeWhitespace(output) != "{\"Message\":\"Oops!\",\"Code\":1}" {
t.Error("Incorrect JSON output") t.Error("Incorrect JSON output")
} }
} }
func removeWhitespace(input string) string {
input = strings.Replace(input, " ", "", -1)
input = strings.Replace(input, "\t", "", -1)
input = strings.Replace(input, "\n", "", -1)
return strings.Replace(input, "\r", "", -1)
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论