move unit tests into 'testing' directories
diff --git a/openstack/db/v1/instances/testing/doc.go b/openstack/db/v1/instances/testing/doc.go
new file mode 100644
index 0000000..7603f83
--- /dev/null
+++ b/openstack/db/v1/instances/testing/doc.go
@@ -0,0 +1 @@
+package testing
diff --git a/openstack/db/v1/instances/testing/fixtures.go b/openstack/db/v1/instances/testing/fixtures.go
new file mode 100644
index 0000000..e0a0d28
--- /dev/null
+++ b/openstack/db/v1/instances/testing/fixtures.go
@@ -0,0 +1,170 @@
+package testing
+
+import (
+ "fmt"
+ "testing"
+ "time"
+
+ "github.com/gophercloud/gophercloud"
+ "github.com/gophercloud/gophercloud/openstack/db/v1/datastores"
+ "github.com/gophercloud/gophercloud/openstack/db/v1/flavors"
+ "github.com/gophercloud/gophercloud/openstack/db/v1/instances"
+ "github.com/gophercloud/gophercloud/testhelper/fixture"
+)
+
+var (
+ timestamp = "2015-11-12T14:22:42Z"
+ timeVal, _ = time.Parse(time.RFC3339, timestamp)
+)
+
+var instance = `
+{
+ "created": "` + timestamp + `",
+ "datastore": {
+ "type": "mysql",
+ "version": "5.6"
+ },
+ "flavor": {
+ "id": 1,
+ "links": [
+ {
+ "href": "https://my-openstack.com/v1.0/1234/flavors/1",
+ "rel": "self"
+ },
+ {
+ "href": "https://my-openstack.com/v1.0/1234/flavors/1",
+ "rel": "bookmark"
+ }
+ ]
+ },
+ "links": [
+ {
+ "href": "https://my-openstack.com/v1.0/1234/instances/1",
+ "rel": "self"
+ }
+ ],
+ "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
+ "id": "{instanceID}",
+ "name": "json_rack_instance",
+ "status": "BUILD",
+ "updated": "` + timestamp + `",
+ "volume": {
+ "size": 2
+ }
+}
+`
+
+var createReq = `
+{
+ "instance": {
+ "databases": [
+ {
+ "character_set": "utf8",
+ "collate": "utf8_general_ci",
+ "name": "sampledb"
+ },
+ {
+ "name": "nextround"
+ }
+ ],
+ "flavorRef": "1",
+ "name": "json_rack_instance",
+ "users": [
+ {
+ "databases": [
+ {
+ "name": "sampledb"
+ }
+ ],
+ "name": "demouser",
+ "password": "demopassword"
+ }
+ ],
+ "volume": {
+ "size": 2
+ }
+ }
+}
+`
+
+var (
+ instanceID = "{instanceID}"
+ rootURL = "/instances"
+ resURL = rootURL + "/" + instanceID
+ uRootURL = resURL + "/root"
+ aURL = resURL + "/action"
+)
+
+var (
+ restartReq = `{"restart": {}}`
+ resizeReq = `{"resize": {"flavorRef": "2"}}`
+ resizeVolReq = `{"resize": {"volume": {"size": 4}}}`
+)
+
+var (
+ createResp = fmt.Sprintf(`{"instance": %s}`, instance)
+ listInstancesResp = fmt.Sprintf(`{"instances":[%s]}`, instance)
+ getInstanceResp = createResp
+ enableUserResp = `{"user":{"name":"root","password":"secretsecret"}}`
+ isUserEnabledResp = `{"rootEnabled":true}`
+)
+
+var expectedInstance = instances.Instance{
+ Created: timeVal,
+ Updated: timeVal,
+ Flavor: flavors.Flavor{
+ ID: 1,
+ Links: []gophercloud.Link{
+ {Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "self"},
+ {Href: "https://my-openstack.com/v1.0/1234/flavors/1", Rel: "bookmark"},
+ },
+ },
+ Hostname: "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
+ ID: instanceID,
+ Links: []gophercloud.Link{
+ {Href: "https://my-openstack.com/v1.0/1234/instances/1", Rel: "self"},
+ },
+ Name: "json_rack_instance",
+ Status: "BUILD",
+ Volume: instances.Volume{Size: 2},
+ Datastore: datastores.DatastorePartial{
+ Type: "mysql",
+ Version: "5.6",
+ },
+}
+
+func HandleCreate(t *testing.T) {
+ fixture.SetupHandler(t, rootURL, "POST", createReq, createResp, 200)
+}
+
+func HandleList(t *testing.T) {
+ fixture.SetupHandler(t, rootURL, "GET", "", listInstancesResp, 200)
+}
+
+func HandleGet(t *testing.T) {
+ fixture.SetupHandler(t, resURL, "GET", "", getInstanceResp, 200)
+}
+
+func HandleDelete(t *testing.T) {
+ fixture.SetupHandler(t, resURL, "DELETE", "", "", 202)
+}
+
+func HandleEnableRoot(t *testing.T) {
+ fixture.SetupHandler(t, uRootURL, "POST", "", enableUserResp, 200)
+}
+
+func HandleIsRootEnabled(t *testing.T) {
+ fixture.SetupHandler(t, uRootURL, "GET", "", isUserEnabledResp, 200)
+}
+
+func HandleRestart(t *testing.T) {
+ fixture.SetupHandler(t, aURL, "POST", restartReq, "", 202)
+}
+
+func HandleResize(t *testing.T) {
+ fixture.SetupHandler(t, aURL, "POST", resizeReq, "", 202)
+}
+
+func HandleResizeVol(t *testing.T) {
+ fixture.SetupHandler(t, aURL, "POST", resizeVolReq, "", 202)
+}
diff --git a/openstack/db/v1/instances/testing/requests_test.go b/openstack/db/v1/instances/testing/requests_test.go
new file mode 100644
index 0000000..e3c81e3
--- /dev/null
+++ b/openstack/db/v1/instances/testing/requests_test.go
@@ -0,0 +1,134 @@
+package testing
+
+import (
+ "testing"
+
+ db "github.com/gophercloud/gophercloud/openstack/db/v1/databases"
+ "github.com/gophercloud/gophercloud/openstack/db/v1/instances"
+ "github.com/gophercloud/gophercloud/openstack/db/v1/users"
+ "github.com/gophercloud/gophercloud/pagination"
+ th "github.com/gophercloud/gophercloud/testhelper"
+ fake "github.com/gophercloud/gophercloud/testhelper/client"
+)
+
+func TestCreate(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleCreate(t)
+
+ opts := instances.CreateOpts{
+ Name: "json_rack_instance",
+ FlavorRef: "1",
+ Databases: db.BatchCreateOpts{
+ {CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
+ {Name: "nextround"},
+ },
+ Users: users.BatchCreateOpts{
+ {
+ Name: "demouser",
+ Password: "demopassword",
+ Databases: db.BatchCreateOpts{
+ {Name: "sampledb"},
+ },
+ },
+ },
+ Size: 2,
+ }
+
+ instance, err := instances.Create(fake.ServiceClient(), opts).Extract()
+
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, &expectedInstance, instance)
+}
+
+func TestInstanceList(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleList(t)
+
+ pages := 0
+ err := instances.List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
+ pages++
+
+ actual, err := instances.ExtractInstances(page)
+ if err != nil {
+ return false, err
+ }
+
+ th.CheckDeepEquals(t, []instances.Instance{expectedInstance}, actual)
+ return true, nil
+ })
+
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, 1, pages)
+}
+
+func TestGetInstance(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleGet(t)
+
+ instance, err := instances.Get(fake.ServiceClient(), instanceID).Extract()
+
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, &expectedInstance, instance)
+}
+
+func TestDeleteInstance(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleDelete(t)
+
+ res := instances.Delete(fake.ServiceClient(), instanceID)
+ th.AssertNoErr(t, res.Err)
+}
+
+func TestEnableRootUser(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleEnableRoot(t)
+
+ expected := &users.User{Name: "root", Password: "secretsecret"}
+ user, err := instances.EnableRootUser(fake.ServiceClient(), instanceID).Extract()
+
+ th.AssertNoErr(t, err)
+ th.AssertDeepEquals(t, expected, user)
+}
+
+func TestIsRootEnabled(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleIsRootEnabled(t)
+
+ isEnabled, err := instances.IsRootEnabled(fake.ServiceClient(), instanceID).Extract()
+
+ th.AssertNoErr(t, err)
+ th.AssertEquals(t, true, isEnabled)
+}
+
+func TestRestart(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleRestart(t)
+
+ res := instances.Restart(fake.ServiceClient(), instanceID)
+ th.AssertNoErr(t, res.Err)
+}
+
+func TestResize(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleResize(t)
+
+ res := instances.Resize(fake.ServiceClient(), instanceID, "2")
+ th.AssertNoErr(t, res.Err)
+}
+
+func TestResizeVolume(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+ HandleResizeVol(t)
+
+ res := instances.ResizeVolume(fake.ServiceClient(), instanceID, 4)
+ th.AssertNoErr(t, res.Err)
+}