Refactor fixtures
diff --git a/rackspace/db/v1/backups/requests_test.go b/rackspace/db/v1/backups/requests_test.go
index e5d8f7c..a56bc35 100644
--- a/rackspace/db/v1/backups/requests_test.go
+++ b/rackspace/db/v1/backups/requests_test.go
@@ -7,15 +7,19 @@
"github.com/rackspace/gophercloud/rackspace/db/v1/datastores"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
+ "github.com/rackspace/gophercloud/testhelper/fixture"
)
-const backupID = "61f12fef-edb1-4561-8122-e7c00ef26a82"
+var (
+ backupID = "{backupID}"
+ _rootURL = "/backups"
+ resURL = _rootURL + "/" + backupID
+)
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
-
- HandleCreateSuccessfully(t)
+ fixture.SetupHandler(t, _rootURL, "POST", createReq, createResp, 202)
opts := CreateOpts{
Name: "snapshot",
@@ -50,13 +54,12 @@
func TestList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
+ fixture.SetupHandler(t, _rootURL, "GET", "", listResp, 200)
- HandleListSuccessfully(t)
+ pages := 0
- count := 0
-
- List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
- count++
+ err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
actual, err := ExtractBackups(page)
th.AssertNoErr(t, err)
@@ -85,16 +88,14 @@
return true, nil
})
- if count != 1 {
- t.Errorf("Expected 1 page, got %d", count)
- }
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, 1, pages)
}
func TestGet(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
-
- HandleGetSuccessfully(t, backupID)
+ fixture.SetupHandler(t, resURL, "GET", "", getResp, 200)
instance, err := Get(fake.ServiceClient(), backupID).Extract()
th.AssertNoErr(t, err)
@@ -123,8 +124,7 @@
func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
-
- HandleDeleteSuccessfully(t, backupID)
+ fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
err := Delete(fake.ServiceClient(), backupID).ExtractErr()
th.AssertNoErr(t, err)