Refactor OS fixtures
diff --git a/openstack/db/v1/users/fixtures.go b/openstack/db/v1/users/fixtures.go
index 25b75f1..516b335 100644
--- a/openstack/db/v1/users/fixtures.go
+++ b/openstack/db/v1/users/fixtures.go
@@ -1,6 +1,11 @@
package users
-import "fmt"
+import (
+ "fmt"
+ "testing"
+
+ "github.com/rackspace/gophercloud/testhelper/fixture"
+)
const user1 = `
{"databases": [{"name": "databaseA"}],"name": "dbuser3"%s}
@@ -11,11 +16,22 @@
`
var (
- pUser1 = fmt.Sprintf(user1, `,"password":"secretsecret"`)
- pUser2 = fmt.Sprintf(user2, `,"password":"secretsecret"`)
+ instanceID = "{instanceID}"
+ _rootURL = "/instances/" + instanceID + "/users"
+ pUser1 = fmt.Sprintf(user1, `,"password":"secretsecret"`)
+ pUser2 = fmt.Sprintf(user2, `,"password":"secretsecret"`)
+ createReq = fmt.Sprintf(`{"users":[%s, %s]}`, pUser1, pUser2)
+ listResp = fmt.Sprintf(`{"users":[%s, %s]}`, fmt.Sprintf(user1, ""), fmt.Sprintf(user2, ""))
)
-var (
- createReq = fmt.Sprintf(`{"users":[%s, %s]}`, pUser1, pUser2)
- listResp = fmt.Sprintf(`{"users":[%s, %s]}`, fmt.Sprintf(user1, ""), fmt.Sprintf(user2, ""))
-)
+func HandleCreate(t *testing.T) {
+ fixture.SetupHandler(t, _rootURL, "POST", createReq, "", 202)
+}
+
+func HandleList(t *testing.T) {
+ fixture.SetupHandler(t, _rootURL, "GET", "", listResp, 200)
+}
+
+func HandleDelete(t *testing.T) {
+ fixture.SetupHandler(t, _rootURL+"/{userName}", "DELETE", "", "", 202)
+}
diff --git a/openstack/db/v1/users/requests_test.go b/openstack/db/v1/users/requests_test.go
index 47eccea..5711f63 100644
--- a/openstack/db/v1/users/requests_test.go
+++ b/openstack/db/v1/users/requests_test.go
@@ -7,18 +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 (
- instanceID = "{instanceID}"
- _rootURL = "/instances/" + instanceID + "/users"
)
func TestCreate(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, _rootURL, "POST", createReq, "", 202)
+ HandleCreate(t)
opts := BatchCreateOpts{
CreateOpts{
@@ -45,7 +39,7 @@
func TestUserList(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, _rootURL, "GET", "", listResp, 200)
+ HandleList(t)
expectedUsers := []User{
User{
@@ -80,11 +74,11 @@
th.AssertEquals(t, 1, pages)
}
-func TestDeleteInstance(t *testing.T) {
+func TestDelete(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
- fixture.SetupHandler(t, _rootURL+"/{dbName}", "DELETE", "", "", 202)
+ HandleDelete(t)
- res := Delete(fake.ServiceClient(), instanceID, "{dbName}")
+ res := Delete(fake.ServiceClient(), instanceID, "{userName}")
th.AssertNoErr(t, res.Err)
}