mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-23 11:27:42 +08:00
commands; Fixed tests for Reader output
This commit is contained in:
parent
0419ce1d20
commit
97a3688429
@ -1,6 +1,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -27,21 +28,25 @@ func TestMarshalling(t *testing.T) {
|
||||
|
||||
req.SetOption(EncShort, JSON)
|
||||
|
||||
bytes, err := res.Marshal()
|
||||
reader, err := res.Marshal()
|
||||
if err != nil {
|
||||
t.Error(err, "Should have passed")
|
||||
}
|
||||
output := string(bytes)
|
||||
var buf bytes.Buffer
|
||||
buf.ReadFrom(reader)
|
||||
output := buf.String()
|
||||
if removeWhitespace(output) != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
|
||||
t.Error("Incorrect JSON output")
|
||||
}
|
||||
|
||||
res.SetError(fmt.Errorf("Oops!"), ErrClient)
|
||||
bytes, err = res.Marshal()
|
||||
reader, err = res.Marshal()
|
||||
if err != nil {
|
||||
t.Error("Should have passed")
|
||||
}
|
||||
output = string(bytes)
|
||||
buf.Reset()
|
||||
buf.ReadFrom(reader)
|
||||
output = buf.String()
|
||||
fmt.Println(removeWhitespace(output))
|
||||
if removeWhitespace(output) != "{\"Message\":\"Oops!\",\"Code\":1}" {
|
||||
t.Error("Incorrect JSON output")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user