1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-30 18:13:54 +08:00

commands: Fixed tests

This commit is contained in:
Matt Bell
2014-11-08 20:45:07 -08:00
committed by Juan Batiz-Benet
parent 652e3d0523
commit 5a18554f6e

View File

@ -2,6 +2,7 @@ package commands
import ( import (
"fmt" "fmt"
"strings"
"testing" "testing"
) )
@ -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)
}