-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_test.go
58 lines (48 loc) · 1.13 KB
/
item_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 suzuri
import (
"context"
"net/http"
"testing"
)
func TestListItems(t *testing.T) {
setup()
defer teardown()
stub.HandleFunc("/items", func(w http.ResponseWriter, r *http.Request) {
expected := "GET"
actual := r.Method
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
http.ServeFile(w, r, "testdata/items.json")
})
list, err := client.ListItems(ctx)
if err != nil {
t.Fatalf("failed to get items: %v", err)
}
expected := 4
actual := len(list.Items)
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
expected = 6
actual = len(list.Items[2].Angles)
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
expected = 0
actual = len(list.Items[3].Angles)
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
expected = 4
actual = len(list.Items[0].Variants)
if actual != expected {
t.Errorf("expected %v, got %v", expected, actual)
}
cancelCtx, cancel := context.WithCancel(ctx)
cancel()
list, err = client.ListItems(cancelCtx)
if err == nil {
t.Errorf("should return error, got %v", err)
}
}