1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 02:30:39 +08:00

commands: Added test for Response error marshalling

This commit is contained in:
Matt Bell
2014-10-10 14:00:02 -07:00
committed by Juan Batiz-Benet
parent aa592cec80
commit 94ca2642a1

View File

@ -1,6 +1,9 @@
package commands package commands
import "testing" import (
"testing"
"fmt"
)
type TestOutput struct { type TestOutput struct {
Foo, Bar string Foo, Bar string
@ -29,4 +32,14 @@ func TestMarshalling(t *testing.T) {
if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" { if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
t.Error("Incorrect JSON output") t.Error("Incorrect JSON output")
} }
res.SetError(fmt.Errorf("You broke something!"), Client)
bytes, err = res.Marshal()
if err != nil {
t.Error("Should have passed")
}
output = string(bytes)
if output != "{\"Message\":\"You broke something!\",\"Code\":1}" {
t.Error("Incorrect JSON output")
}
} }