commands: Wrote tests for Response marshalling
Matt Bell committed
Oct 10, 2014 at 13:34 UTC
808d9c19122f0ec2708615720b43b55222e11994
1 file changed
+32
commands/response_test.go
new
+32
@@ -0,0 +1,32 @@
1
+package commands
2
+
3
+import "testing"
4
+
5
+type TestOutput struct {
6
+ Foo, Bar string
7
+ Baz int
8
+}
9
+
10
+func TestMarshalling(t *testing.T) {
11
+ req := NewRequest()
12
+
13
+ res := Response{
14
+ req: req,
15
+ Value: TestOutput{ "beep", "boop", 1337 },
16
+ }
17
+
18
+ _, err := res.Marshal()
19
+ if err == nil {
20
+ t.Error("Should have failed (no encoding type specified in request)")
21
+ }
22
+
23
+ req.options["enc"] = Json
24
+ bytes, err := res.Marshal()
25
+ if err != nil {
26
+ t.Error("Should have passed")
27
+ }
28
+ output := string(bytes)
29
+ if output != "{\"Foo\":\"beep\",\"Bar\":\"boop\",\"Baz\":1337}" {
30
+ t.Error("Incorrect JSON output")
31
+ }
32
+}