-
Notifications
You must be signed in to change notification settings - Fork 8
/
expectations_test.go
58 lines (50 loc) · 1.29 KB
/
expectations_test.go
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
55
56
57
58
package forest
import "testing"
func TestExpectStatus404(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/status/404"))
ExpectStatus(t, r, 404)
}
func TestExpectResponseHeader(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/jsondoc"))
ExpectHeader(t, r, "Content-Type", "application/json")
}
func TestExpectJSONHash(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/jsondoc"))
ExpectJSONHash(t, r, func(hash map[string]interface{}) {
if hash["Value"] != float64(42) {
t.Error(serrorf("expected 42 but got %v (%T)", hash["Value"], hash["Value"]))
}
})
}
func TestExpectJSONArray(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/jsonarray"))
ExpectJSONArray(t, r, func(a []interface{}) {
if len(a) != 1 && a[0] != 42 {
t.Errorf("expected 42 but got %v (%T)", a, a)
}
})
}
type Root struct {
Child struct {
Name string `xml:"name,attr"`
Value int
}
}
func TestExpectXMLDoc(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/xmldoc"))
var root Root
ExpectXMLDocument(t, r, &root)
if root.Child.Name != "answer" {
t.Error("expected attribute was the answer")
}
}
func TestExpectJSONDoc(t *testing.T) {
r := tsAPI.GET(t, NewConfig("/jsondoc"))
root := struct {
Value int
}{}
ExpectJSONDocument(t, r, &root)
if root.Value != 42 {
t.Errorf("expected 42 was the answer, got %v", root.Value)
}
}