forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_test.go
More file actions
54 lines (46 loc) · 959 Bytes
/
decode_test.go
File metadata and controls
54 lines (46 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package multigraphql
import (
"bytes"
"testing"
)
func TestDecode(t *testing.T) {
buf := bytes.NewBufferString(`
{ "extensions": [],
"data": {
"multi_000": { "world": true },
"multi_001": { "machines": "are learning" }
} }
`)
hello := struct {
World bool
}{}
ai := struct {
Machines string
}{}
err := Decode(buf, []interface{}{&hello, &ai})
if err != nil {
t.Fatalf("got error: %v", err)
}
if !hello.World {
t.Errorf("expected World to be true")
}
if ai.Machines != "are learning" {
t.Errorf("expected machines to be learning, got %q", ai.Machines)
}
}
func TestDecode_errors(t *testing.T) {
buf := bytes.NewBufferString(`
{ "extensions": [],
"errors": [
{ "message": "boom" },
{ "message": "shutting down" }
] }
`)
hello := struct {
World bool
}{}
err := Decode(buf, []interface{}{&hello})
if err == nil || err.Error() != "GraphQL error: boom; shutting down" {
t.Fatalf("got error: %v", err)
}
}