:fire: more manual ServiceClient fixtures.
diff --git a/openstack/blockstorage/v1/snapshots/requests_test.go b/openstack/blockstorage/v1/snapshots/requests_test.go
index ddfa81b..e13a348 100644
--- a/openstack/blockstorage/v1/snapshots/requests_test.go
+++ b/openstack/blockstorage/v1/snapshots/requests_test.go
@@ -5,29 +5,18 @@
"net/http"
"testing"
- "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
)
-const TokenID = "123"
-
-func ServiceClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{
- Provider: &gophercloud.ProviderClient{
- TokenID: TokenID,
- },
- Endpoint: th.Endpoint(),
- }
-}
-
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
th.Mux.HandleFunc("/snapshots", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
@@ -48,10 +37,8 @@
`)
})
- client := ServiceClient()
count := 0
-
- List(client, &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ List(client.ServiceClient(), &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractSnapshots(page)
if err != nil {
@@ -86,7 +73,7 @@
th.Mux.HandleFunc("/snapshots/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
@@ -100,7 +87,7 @@
`)
})
- v, err := Get(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ v, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, v.Name, "snapshot-001")
@@ -113,7 +100,7 @@
th.Mux.HandleFunc("/snapshots", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
+ 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, `
@@ -140,7 +127,7 @@
})
options := &CreateOpts{VolumeID: "1234", Name: "snapshot-001"}
- n, err := Create(ServiceClient(), options).Extract()
+ n, err := Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.VolumeID, "1234")
@@ -154,7 +141,7 @@
th.Mux.HandleFunc("/snapshots/123/metadata", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "PUT")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestHeader(t, r, "Content-Type", "application/json")
th.TestJSONRequest(t, r, `
{
@@ -180,7 +167,7 @@
"key": "v1",
},
}
- actual, err := UpdateMetadata(ServiceClient(), "123", options).ExtractMetadata()
+ actual, err := UpdateMetadata(client.ServiceClient(), "123", options).ExtractMetadata()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, actual, expected)
@@ -192,10 +179,10 @@
th.Mux.HandleFunc("/snapshots/d32019d3-bc6e-4319-9c1d-6722fc136a22", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "DELETE")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
- err := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ err := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, err)
}
diff --git a/openstack/blockstorage/v1/snapshots/util_test.go b/openstack/blockstorage/v1/snapshots/util_test.go
index 46b452e..a4c4c82 100644
--- a/openstack/blockstorage/v1/snapshots/util_test.go
+++ b/openstack/blockstorage/v1/snapshots/util_test.go
@@ -7,6 +7,7 @@
"time"
th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
)
func TestWaitForStatus(t *testing.T) {
@@ -27,11 +28,11 @@
}`)
})
- err := WaitForStatus(ServiceClient(), "1234", "available", 0)
+ err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
if err == nil {
t.Errorf("Expected error: 'Time Out in WaitFor'")
}
- err = WaitForStatus(ServiceClient(), "1234", "available", 3)
+ err = WaitForStatus(client.ServiceClient(), "1234", "available", 3)
th.CheckNoErr(t, err)
}
diff --git a/openstack/blockstorage/v1/volumes/requests_test.go b/openstack/blockstorage/v1/volumes/requests_test.go
index 7cd37d5..473a4e7 100644
--- a/openstack/blockstorage/v1/volumes/requests_test.go
+++ b/openstack/blockstorage/v1/volumes/requests_test.go
@@ -5,29 +5,18 @@
"net/http"
"testing"
- "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
)
-const TokenID = "123"
-
-func ServiceClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{
- Provider: &gophercloud.ProviderClient{
- TokenID: TokenID,
- },
- Endpoint: th.Endpoint(),
- }
-}
-
func TestList(t *testing.T) {
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", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
@@ -48,10 +37,8 @@
`)
})
- client := ServiceClient()
count := 0
-
- List(client, &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
+ List(client.ServiceClient(), &ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractVolumes(page)
if err != nil {
@@ -86,7 +73,7 @@
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", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
@@ -100,7 +87,7 @@
`)
})
- v, err := Get(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
+ v, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, v.Name, "vol-001")
@@ -113,7 +100,7 @@
th.Mux.HandleFunc("/volumes", func(w http.ResponseWriter, r *http.Request) {
th.TestMethod(t, r, "POST")
- th.TestHeader(t, r, "X-Auth-Token", TokenID)
+ 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, `
@@ -138,7 +125,7 @@
})
options := &CreateOpts{Size: 4}
- n, err := Create(ServiceClient(), options).Extract()
+ n, err := Create(client.ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
th.AssertEquals(t, n.Size, 4)
@@ -151,11 +138,11 @@
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", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusNoContent)
})
- err := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ err := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
th.AssertNoErr(t, err)
}
@@ -165,7 +152,7 @@
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", TokenID)
+ th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `
{
@@ -178,7 +165,7 @@
})
options := &UpdateOpts{Name: "vol-002"}
- v, err := Update(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
+ v, err := Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
th.AssertNoErr(t, err)
th.CheckEquals(t, "vol-002", v.Name)
}
diff --git a/openstack/blockstorage/v1/volumes/util_test.go b/openstack/blockstorage/v1/volumes/util_test.go
index 7de1326..a6754e2 100644
--- a/openstack/blockstorage/v1/volumes/util_test.go
+++ b/openstack/blockstorage/v1/volumes/util_test.go
@@ -7,6 +7,7 @@
"time"
th "github.com/rackspace/gophercloud/testhelper"
+ "github.com/rackspace/gophercloud/testhelper/client"
)
func TestWaitForStatus(t *testing.T) {
@@ -27,11 +28,11 @@
}`)
})
- err := WaitForStatus(ServiceClient(), "1234", "available", 0)
+ err := WaitForStatus(client.ServiceClient(), "1234", "available", 0)
if err == nil {
t.Errorf("Expected error: 'Time Out in WaitFor'")
}
- err = WaitForStatus(ServiceClient(), "1234", "available", 3)
+ err = WaitForStatus(client.ServiceClient(), "1234", "available", 3)
th.CheckNoErr(t, err)
}