commands; Fixed tests for Reader output
Matt Bell committed
Jan 6, 2015 at 12:06 UTC
97a36884293ad25f812ef7e52da7ee5ea25c72bf
1 file changed
+9
-4
commands/response_test.go
+9
-4
@@ -1,6 +1,7 @@
1
package commands
2
3
import (
4
+ "bytes"
5
"fmt"
6
"strings"
7
"testing"
@@ -27,21 +28,25 @@ func TestMarshalling(t *testing.T) {
28
29
req.SetOption(EncShort, JSON)
30
30
- bytes, err := res.Marshal()
31
+ reader, err := res.Marshal()
32
if err != nil {
33
t.Error(err, "Should have passed")
34
}
34
- output := string(bytes)
35
+ var buf bytes.Buffer
36
+ buf.ReadFrom(reader)
37
+ output := buf.String()
38
if removeWhitespace(output) != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
39
t.Error("Incorrect JSON output")
40
}
41
42
res.SetError(fmt.Errorf("Oops!"), ErrClient)
40
- bytes, err = res.Marshal()
43
+ reader, err = res.Marshal()
44
if err != nil {
45
t.Error("Should have passed")
46
}
44
- output = string(bytes)
47
+ buf.Reset()
48
+ buf.ReadFrom(reader)
49
+ output = buf.String()
50
fmt.Println(removeWhitespace(output))
51
if removeWhitespace(output) != "{\"Message\":\"Oops!\",\"Code\":1}" {
52
t.Error("Incorrect JSON output")