Rework locations of extracted structs
diff --git a/rackspace/db/v1/instances/delegate.go b/rackspace/db/v1/instances/delegate.go
index 981e902..d2e3c25 100644
--- a/rackspace/db/v1/instances/delegate.go
+++ b/rackspace/db/v1/instances/delegate.go
@@ -2,7 +2,9 @@
import (
"github.com/rackspace/gophercloud"
+ osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
+ osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
"github.com/rackspace/gophercloud/pagination"
)
@@ -34,10 +36,10 @@
Name string
// A slice of database information options.
- Databases os.DatabasesOpts
+ Databases osDBs.BatchCreateOpts
// A slice of user information options.
- Users os.UsersOpts
+ Users osUsers.BatchCreateOpts
// ID of the configuration group to associate with the instance. Optional.
ConfigID string
diff --git a/rackspace/db/v1/instances/delegate_test.go b/rackspace/db/v1/instances/delegate_test.go
index cc72227..3ba7a5e 100644
--- a/rackspace/db/v1/instances/delegate_test.go
+++ b/rackspace/db/v1/instances/delegate_test.go
@@ -4,7 +4,9 @@
"testing"
"github.com/rackspace/gophercloud"
+ osDBs "github.com/rackspace/gophercloud/openstack/db/v1/databases"
os "github.com/rackspace/gophercloud/openstack/db/v1/instances"
+ osUsers "github.com/rackspace/gophercloud/openstack/db/v1/users"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
)
@@ -41,16 +43,16 @@
opts := CreateOpts{
Name: "json_rack_instance",
FlavorRef: "1",
- Databases: os.DatabasesOpts{
- os.DatabaseOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
- os.DatabaseOpts{Name: "nextround"},
+ Databases: osDBs.BatchCreateOpts{
+ osDBs.CreateOpts{CharSet: "utf8", Collate: "utf8_general_ci", Name: "sampledb"},
+ osDBs.CreateOpts{Name: "nextround"},
},
- Users: os.UsersOpts{
- os.UserOpts{
+ Users: osUsers.BatchCreateOpts{
+ osUsers.CreateOpts{
Name: "demouser",
Password: "demopassword",
- Databases: os.DatabasesOpts{
- os.DatabaseOpts{Name: "sampledb"},
+ Databases: osDBs.BatchCreateOpts{
+ osDBs.CreateOpts{Name: "sampledb"},
},
},
},
@@ -92,7 +94,7 @@
os.HandleEnableRootUserSuccessfully(t, instanceID)
- expected := &os.User{Name: "root", Password: "secretsecret"}
+ expected := &osUsers.User{Name: "root", Password: "secretsecret"}
user, err := EnableRootUser(fake.ServiceClient(), instanceID).Extract()
th.AssertNoErr(t, err)
diff --git a/rackspace/db/v1/instances/fixtures.go b/rackspace/db/v1/instances/fixtures.go
index ac5c960..55dc0a8 100644
--- a/rackspace/db/v1/instances/fixtures.go
+++ b/rackspace/db/v1/instances/fixtures.go
@@ -179,3 +179,36 @@
fmt.Fprintf(w, singleInstanceJson)
})
}
+
+func HandleListBackupsSuccessfully(t *testing.T, id string) {
+ th.Mux.HandleFunc("/instances/"+id+"/backups", func(w http.ResponseWriter, r *http.Request) {
+ th.TestMethod(t, r, "GET")
+ th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
+
+ w.Header().Add("Content-Type", "application/json")
+
+ fmt.Fprintf(w, `
+{
+ "backups": [
+ {
+ "status": "COMPLETED",
+ "updated": "2014-06-18T21:24:39",
+ "description": "Backup from Restored Instance",
+ "datastore": {
+ "version": "5.1",
+ "type": "MySQL",
+ "version_id": "20000000-0000-0000-0000-000000000002"
+ },
+ "id": "87972694-4be2-40f5-83f8-501656e0032a",
+ "size": 0.141026,
+ "name": "restored_backup",
+ "created": "2014-06-18T21:23:35",
+ "instance_id": "29af2cd9-0674-48ab-b87a-b160f00208e6",
+ "parent_id": null,
+ "locationRef": "http://localhost/path/to/backup"
+ }
+ ]
+}
+`)
+ })
+}
diff --git a/rackspace/db/v1/instances/requests.go b/rackspace/db/v1/instances/requests.go
index b4bade8..b311289 100644
--- a/rackspace/db/v1/instances/requests.go
+++ b/rackspace/db/v1/instances/requests.go
@@ -4,20 +4,18 @@
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/backups"
)
func GetDefaultConfig(client *gophercloud.ServiceClient, id string) ConfigResult {
var res ConfigResult
- resp, err := perigee.Request("GET", configURL(client, id), perigee.Options{
+ _, res.Err = perigee.Request("GET", configURL(client, id), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
Results: &res.Body,
OkCodes: []int{200},
})
- res.Header = resp.HttpResponse.Header
- res.Err = err
-
return res
}
@@ -28,18 +26,18 @@
var res UpdateResult
- resp, err := perigee.Request("PUT", resourceURL(client, instanceID), perigee.Options{
+ _, res.Err = perigee.Request("PUT", resourceURL(client, instanceID), perigee.Options{
MoreHeaders: client.AuthenticatedHeaders(),
ReqBody: map[string]map[string]string{"instance": reqBody},
OkCodes: []int{202},
})
- res.Header = resp.HttpResponse.Header
- res.Err = err
-
return res
}
func ListBackups(client *gophercloud.ServiceClient, instanceID string) pagination.Pager {
-
+ pageFn := func(r pagination.PageResult) pagination.Page {
+ return backups.BackupPage{pagination.SinglePageBase(r)}
+ }
+ return pagination.NewPager(client, backupsURL(client, instanceID), pageFn)
}
diff --git a/rackspace/db/v1/instances/requests_test.go b/rackspace/db/v1/instances/requests_test.go
index c746b6a..66d58fd 100644
--- a/rackspace/db/v1/instances/requests_test.go
+++ b/rackspace/db/v1/instances/requests_test.go
@@ -3,6 +3,8 @@
import (
"testing"
+ "github.com/rackspace/gophercloud/pagination"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/backups"
th "github.com/rackspace/gophercloud/testhelper"
fake "github.com/rackspace/gophercloud/testhelper/client"
)
@@ -74,3 +76,41 @@
res := AssociateWithConfigGroup(fake.ServiceClient(), instanceID, configGroupID)
th.AssertNoErr(t, res.Err)
}
+
+func TestListBackups(t *testing.T) {
+ th.SetupHTTP()
+ defer th.TeardownHTTP()
+
+ HandleListBackupsSuccessfully(t, instanceID)
+ count := 0
+
+ ListBackups(fake.ServiceClient(), instanceID).EachPage(func(page pagination.Page) (bool, error) {
+ count++
+ actual, err := backups.ExtractBackups(page)
+ th.AssertNoErr(t, err)
+
+ expected := []backups.Backup{
+ backups.Backup{
+ Created: "2014-06-18T21:23:35",
+ Description: "Backup from Restored Instance",
+ ID: "87972694-4be2-40f5-83f8-501656e0032a",
+ InstanceID: "29af2cd9-0674-48ab-b87a-b160f00208e6",
+ LocationRef: "http://localhost/path/to/backup",
+ Name: "restored_backup",
+ ParentID: "",
+ Size: 0.141026,
+ Status: "COMPLETED",
+ Updated: "2014-06-18T21:24:39",
+ Datastore: backups.Datastore{Version: "5.1", Type: "MySQL", VersionID: "20000000-0000-0000-0000-000000000002"},
+ },
+ }
+
+ th.AssertDeepEquals(t, expected, actual)
+
+ return true, nil
+ })
+
+ if count != 1 {
+ t.Errorf("Expected 1 page, got %d", count)
+ }
+}
diff --git a/rackspace/db/v1/instances/urls.go b/rackspace/db/v1/instances/urls.go
index 12f8d83..5955f4c 100644
--- a/rackspace/db/v1/instances/urls.go
+++ b/rackspace/db/v1/instances/urls.go
@@ -17,3 +17,7 @@
func configURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL("instances", id, "configuration")
}
+
+func backupsURL(c *gophercloud.ServiceClient, id string) string {
+ return c.ServiceURL("instances", id, "backups")
+}