mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +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
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type TestOutput struct {
|
||||
Foo, Bar string
|
||||
@ -29,4 +32,14 @@ func TestMarshalling(t *testing.T) {
|
||||
if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
|
||||
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