-
Notifications
You must be signed in to change notification settings - Fork 1
/
volumes_test.go
69 lines (54 loc) · 1.71 KB
/
volumes_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
package books
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestVolumesList(t *testing.T) {
setup()
defer teardown()
volumeID := "1"
url := fmt.Sprintf("/mylibrary/bookshelves/%s/volumes", volumeID)
mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"totalItems":1,"items":[{"id":"VN2jCgAAAEAJ","volumeInfo":{"title":"Go in Action","contentVersion":"full-1.0.0"}}]}`)
})
opts := &VolumesListOptions{
Fields: "items(id,volumeInfo(contentVersion,title)),totalItems",
MaxResults: 1,
}
list, _, err := client.Volumes.List(volumeID, opts)
if err != nil {
t.Errorf("List() returned an error: %v", err)
}
expectedVolumeInfo := &VolumeInfo{Title: String("Go in Action"), ContentVersion: String("full-1.0.0")}
expected := []Volume{{ID: String("VN2jCgAAAEAJ"), Info: expectedVolumeInfo}}
if !reflect.DeepEqual(list, expected) {
t.Errorf("List() returned %+v, expected %+v", list, expected)
}
}
func TestVolumesList_badBody(t *testing.T) {
setup()
defer teardown()
opts := &VolumesListOptions{}
_, resp, err := client.Volumes.List("1", opts)
// Check that response is error on nil request body
if err == nil {
t.Error("List() Expected Request body error.")
}
// Check that response status code is http.StatusNotFound.
if got, want := resp.StatusCode, http.StatusNotFound; got != want {
t.Errorf("List() Expected Status code got %v, want %v", got, want)
}
}
func TestVolumesList_emptyVolume(t *testing.T) {
setup()
defer teardown()
opts := &VolumesListOptions{}
_, _, err := client.Volumes.List("", opts)
// Check that response is error on nil request body
if err == nil {
t.Error("List() Expected Request body error.")
}
}