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:

committed by
Juan Batiz-Benet

parent
aa592cec80
commit
94ca2642a1
@ -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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user