Refactor OS fixtures
diff --git a/openstack/db/v1/flavors/fixtures.go b/openstack/db/v1/flavors/fixtures.go
index 42e2dca..f0016bc 100644
--- a/openstack/db/v1/flavors/fixtures.go
+++ b/openstack/db/v1/flavors/fixtures.go
@@ -1,6 +1,11 @@
package flavors
-import "fmt"
+import (
+ "fmt"
+ "testing"
+
+ "github.com/rackspace/gophercloud/testhelper/fixture"
+)
const flavor = `
{
@@ -21,6 +26,12 @@
`
var (
+ flavorID = "{flavorID}"
+ _baseURL = "/flavors"
+ resURL = "/flavors/" + flavorID
+)
+
+var (
flavor1 = fmt.Sprintf(flavor, 1, 1, 1, "m1.tiny", 512)
flavor2 = fmt.Sprintf(flavor, 2, 2, 2, "m1.small", 1024)
flavor3 = fmt.Sprintf(flavor, 3, 3, 3, "m1.medium", 2048)
@@ -29,3 +40,11 @@
listFlavorsResp = fmt.Sprintf(`{"flavors":[%s, %s, %s, %s]}`, flavor1, flavor2, flavor3, flavor4)
getFlavorResp = fmt.Sprintf(`{"flavor": %s}`, flavor1)
)
+
+func HandleList(t *testing.T) {
+ fixture.SetupHandler(t, _baseURL, "GET", "", listFlavorsResp, 200)
+}
+
+func HandleGet(t *testing.T) {
+ fixture.SetupHandler(t, resURL, "GET", "", getFlavorResp, 200)
+}
diff --git a/openstack/db/v1/flavors/requests_test.go b/openstack/db/v1/flavors/requests_test.go
index 62e5fec..0afe9bb 100644
--- a/openstack/db/v1/flavors/requests_test.go
+++ b/openstack/db/v1/flavors/requests_test.go
@@ -7,20 +7,12 @@
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
- "github.com/rackspace/gophercloud/testhelper/fixture"
-)
-
-var (
- flavorID = "{flavorID}"
- _baseURL = "/flavors"
- resURL = "/flavors/" + flavorID
)
func TestListFlavors(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
-
- fixture.SetupHandler(t, _baseURL, "GET", "", listFlavorsResp, 200)
+ HandleList(t)
pages := 0
err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
@@ -71,21 +63,17 @@
}
th.AssertDeepEquals(t, expected, actual)
-
return true, nil
})
th.AssertNoErr(t, err)
- if pages != 1 {
- t.Errorf("Expected one page, got %d", pages)
- }
+ th.AssertEquals(t, 1, pages)
}
func TestGetFlavor(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
-
- fixture.SetupHandler(t, resURL, "GET", "", getFlavorResp, 200)
+ HandleGet(t)
actual, err := Get(fake.ServiceClient(), flavorID).Extract()
th.AssertNoErr(t, err)