Shifting volume fixtures into their own file
diff --git a/openstack/blockstorage/v1/volumes/requests_test.go b/openstack/blockstorage/v1/volumes/requests_test.go
index 473a4e7..8e7e33d 100644
--- a/openstack/blockstorage/v1/volumes/requests_test.go
+++ b/openstack/blockstorage/v1/volumes/requests_test.go
@@ -1,8 +1,6 @@
package volumes
import (
- "fmt"
- "net/http"
"testing"
"github.com/rackspace/gophercloud/pagination"
@@ -14,30 +12,10 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
-
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
-
- fmt.Fprintf(w, `
- {
- "volumes": [
- {
- "id": "289da7f8-6440-407c-9fb4-7db01ec49164",
- "display_name": "vol-001"
- },
- {
- "id": "96c3bda7-c82a-4f50-be73-ca7621794835",
- "display_name": "vol-002"
- }
- ]
- }
- `)
- })
+ MockListResponse(t)
count := 0
+
List(client.ServiceClient(), &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractVolumes(page)
@@ -71,21 +49,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
-
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `
-{
- "volume": {
- "display_name": "vol-001",
- "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
- }
-}
- `)
- })
+ MockGetResponse(t)
v, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
@@ -98,31 +62,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "POST")
- th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
- th.TestHeader(t, r, "Content-Type", "application/json")
- th.TestHeader(t, r, "Accept", "application/json")
- th.TestJSONRequest(t, r, `
-{
- "volume": {
- "size": 4
- }
-}
- `)
-
- w.Header().Add("Content-Type", "application/json")
- w.WriteHeader(http.StatusCreated)
-
- fmt.Fprintf(w, `
-{
- "volume": {
- "size": 4,
- "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
- }
-}
- `)
- })
+ MockCreateResponse(t)
options := &CreateOpts{Size: 4}
n, err := Create(client.ServiceClient(), options).Extract()
@@ -136,11 +76,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "DELETE")
- th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
- w.WriteHeader(http.StatusNoContent)
- })
+ MockDeleteResponse(t)
err := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, err)
@@ -150,21 +86,9 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- th.Mux.HandleFunc("/volumes/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "PUT")
- th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
- w.WriteHeader(http.StatusOK)
- fmt.Fprintf(w, `
- {
- "volume": {
- "display_name": "vol-002",
- "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22"
- }
- }
- `)
- })
+ MockUpdateResponse(t)
- options := &UpdateOpts{Name: "vol-002"}
+ options := UpdateOpts{Name: "vol-002"}
v, err := Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
th.AssertNoErr(t, err)
th.CheckEquals(t, "vol-002", v.Name)