Refactor to use new handler setup
diff --git a/openstack/db/v1/databases/fixtures.go b/openstack/db/v1/databases/fixtures.go
index d03466f..4d653ca 100644
--- a/openstack/db/v1/databases/fixtures.go
+++ b/openstack/db/v1/databases/fixtures.go
@@ -1,47 +1,21 @@
package databases
-import (
- "fmt"
- "net/http"
- "testing"
-
- th "github.com/rackspace/gophercloud/testhelper"
- fake "github.com/rackspace/gophercloud/testhelper/client"
-)
-
-func HandleCreateDBSuccessfully(t *testing.T, instanceID string) {
- th.Mux.HandleFunc("/instances/"+instanceID+"/databases", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "POST")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
- th.TestJSONRequest(t, r, `
+var createDBsReq = `
{
- "databases": [
- {
- "character_set": "utf8",
- "collate": "utf8_general_ci",
- "name": "testingdb"
- },
- {
- "name": "sampledb"
- }
- ]
+ "databases": [
+ {
+ "character_set": "utf8",
+ "collate": "utf8_general_ci",
+ "name": "testingdb"
+ },
+ {
+ "name": "sampledb"
+ }
+ ]
}
-`)
+`
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusAccepted)
- })
-}
-
-func HandleListDBsSuccessfully(t *testing.T, instanceID string) {
- th.Mux.HandleFunc("/instances/"+instanceID+"/databases", func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "GET")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
-
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
-
- fmt.Fprintf(w, `
+var listDBsResp = `
{
"databases": [
{
@@ -61,16 +35,4 @@
}
]
}
-`)
- })
-}
-
-func HandleDeleteDBSuccessfully(t *testing.T, instanceID, dbName string) {
- th.Mux.HandleFunc("/instances/"+instanceID+"/databases/"+dbName, func(w http.ResponseWriter, r *http.Request) {
- th.TestMethod(t, r, "DELETE")
- th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
-
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusAccepted)
- })
-}
+`
diff --git a/openstack/db/v1/databases/requests_test.go b/openstack/db/v1/databases/requests_test.go
index 6f5edb6..11bf9c8 100644
--- a/openstack/db/v1/databases/requests_test.go
+++ b/openstack/db/v1/databases/requests_test.go
@@ -6,15 +6,20 @@
"github.com/rackspace/gophercloud/pagination"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
+ "github.com/rackspace/gophercloud/testhelper/fixture"
)
const instanceID = "{instanceID}"
+var (
+ resURL = "/instances/" + instanceID + "/databases"
+)
+
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- HandleCreateDBSuccessfully(t, instanceID)
+ fixture.SetupHandler(t, resURL, "POST", createDBsReq, "", 202)
opts := BatchCreateOpts{
CreateOpts{Name: "testingdb", CharSet: "utf8", Collate: "utf8_general_ci"},
@@ -29,7 +34,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- HandleListDBsSuccessfully(t, instanceID)
+ fixture.SetupHandler(t, resURL, "GET", "", listDBsResp, 200)
expectedDBs := []Database{
Database{Name: "anotherexampledb"},
@@ -64,7 +69,7 @@
th.SetupHTTP()
defer th.TeardownHTTP()
- HandleDeleteDBSuccessfully(t, instanceID, "{dbName}")
+ fixture.SetupHandler(t, resURL+"/{dbName}", "DELETE", "", "", 202)
err := Delete(fake.ServiceClient(), instanceID, "{dbName}").ExtractErr()
th.AssertNoErr(t, err)