-
Notifications
You must be signed in to change notification settings - Fork 1
/
yeast_test.go
72 lines (61 loc) · 1.24 KB
/
yeast_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package brewerydb
import (
"io"
"net/http"
"strconv"
"testing"
)
func TestYeastGet(t *testing.T) {
setup()
defer teardown()
data := loadTestData("yeast.get.json", t)
defer data.Close()
const id = 1835
mux.HandleFunc("/yeast/", func(w http.ResponseWriter, r *http.Request) {
checkMethod(t, r, "GET")
checkURLSuffix(t, r, strconv.Itoa(id))
io.Copy(w, data)
})
y, err := client.Yeast.Get(id)
if err != nil {
t.Fatal(err)
}
if y.ID != id {
t.Fatalf("Yeast ID = %v, want %v", y.ID, id)
}
testBadURL(t, func() error {
_, err := client.Yeast.Get(id)
return err
})
}
func TestYeastList(t *testing.T) {
setup()
defer teardown()
data := loadTestData("yeast.list.json", t)
defer data.Close()
const page = 1
mux.HandleFunc("/yeasts", func(w http.ResponseWriter, r *http.Request) {
checkMethod(t, r, "GET")
checkPage(t, r, page)
io.Copy(w, data)
})
yl, err := client.Yeast.List(page)
if err != nil {
t.Error(err)
}
if len(yl.Yeasts) <= 0 {
t.Error("Expected >0 yeasts")
}
for _, y := range yl.Yeasts {
if y.ID <= 0 {
t.Fatal("Expected non-zero yeast ID")
}
if y.Name == "" {
t.Fatal("Expected non-empty yeast name")
}
}
testBadURL(t, func() error {
_, err := client.Yeast.List(page)
return err
})
}