Finalizing most acceptance tests
diff --git a/acceptance/rackspace/db/v1/backup_test.go b/acceptance/rackspace/db/v1/backup_test.go
index 677b3b3..7c50e19 100644
--- a/acceptance/rackspace/db/v1/backup_test.go
+++ b/acceptance/rackspace/db/v1/backup_test.go
@@ -2,18 +2,24 @@
package v1
-import "github.com/rackspace/gophercloud/pagination"
+import (
+ "github.com/rackspace/gophercloud/acceptance/tools"
+ "github.com/rackspace/gophercloud/pagination"
+
+ "github.com/rackspace/gophercloud/rackspace/db/v1/backups"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
+)
func (c context) createBackup() {
opts := backups.CreateOpts{
- Name: tools.PrefixString("backup_", 5),
+ Name: tools.RandomString("backup_", 5),
InstanceID: c.instanceID,
}
- backup, err := backups.Create(c.client, opts)
+ backup, err := backups.Create(c.client, opts).Extract()
c.Logf("Created backup %#v", backup)
- c.AssertNoErr(t, err)
+ c.AssertNoErr(err)
c.backupID = backup.ID
}
@@ -27,7 +33,7 @@
func (c context) listAllBackups() {
c.Logf("Listing backups")
- err := backups.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
+ err := backups.List(c.client, nil).EachPage(func(page pagination.Page) (bool, error) {
backupList, err := backups.ExtractBackups(page)
c.AssertNoErr(err)
@@ -38,13 +44,13 @@
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) listInstanceBackups() {
c.Logf("Listing backups for instance %s", c.instanceID)
- err := instances.ListBackups(c.client).EachPage(func(page pagination.Page) (bool, error) {
+ err := instances.ListBackups(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
backupList, err := backups.ExtractBackups(page)
c.AssertNoErr(err)
@@ -55,7 +61,7 @@
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) deleteBackup() {
diff --git a/acceptance/rackspace/db/v1/common.go b/acceptance/rackspace/db/v1/common.go
index 2fa977f..3d10904 100644
--- a/acceptance/rackspace/db/v1/common.go
+++ b/acceptance/rackspace/db/v1/common.go
@@ -9,6 +9,7 @@
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack"
"github.com/rackspace/gophercloud/rackspace"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
th "github.com/rackspace/gophercloud/testhelper"
)
@@ -35,6 +36,7 @@
replicaID string
backupID string
configGroupID string
+ users []string
}
func newContext(t *testing.T) context {
@@ -63,4 +65,5 @@
}
return false, nil
})
+ c.AssertNoErr(err)
}
diff --git a/acceptance/rackspace/db/v1/config_group_test.go b/acceptance/rackspace/db/v1/config_group_test.go
index 3d269c4..fba46a9 100644
--- a/acceptance/rackspace/db/v1/config_group_test.go
+++ b/acceptance/rackspace/db/v1/config_group_test.go
@@ -3,20 +3,22 @@
package v1
import (
- config "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
+ "github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/pagination"
+ config "github.com/rackspace/gophercloud/rackspace/db/v1/configurations"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
)
func (c context) createConfigGrp() {
opts := config.CreateOpts{
- Name: tools.PrefixString("config_", 5),
+ Name: tools.RandomString("config_", 5),
Values: map[string]interface{}{
"connect_timeout": 300,
"join_buffer_size": 900000,
},
}
- cg, err := config.Create(c.client, opts)
+ cg, err := config.Create(c.client, opts).Extract()
c.AssertNoErr(err)
c.Logf("Created config group %#v", cg)
@@ -25,14 +27,14 @@
}
func (c context) getConfigGrp() {
- cg, err := config.Get(c.client, c.configGroupID)
+ cg, err := config.Get(c.client, c.configGroupID).Extract()
c.Logf("Getting config group: %#v", cg)
c.AssertNoErr(err)
}
func (c context) updateConfigGrp() {
opts := config.UpdateOpts{
- Name: tools.PrefixString("new_name_", 5),
+ Name: tools.RandomString("new_name_", 5),
Values: map[string]interface{}{
"connect_timeout": 250,
},
@@ -55,7 +57,7 @@
}
func (c context) associateInstanceWithConfigGrp() {
- err := config.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
+ err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID)
c.AssertNoErr(err)
}
@@ -67,14 +69,14 @@
instanceList, err := instances.ExtractInstances(page)
c.AssertNoErr(err)
- for _, n := range networkList {
+ for _, instance := range instanceList {
c.Logf("Instance: %#v", instance)
}
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) deleteConfigGrp() {
diff --git a/acceptance/rackspace/db/v1/database_test.go b/acceptance/rackspace/db/v1/database_test.go
index e2d41cf..faaa7ca 100644
--- a/acceptance/rackspace/db/v1/database_test.go
+++ b/acceptance/rackspace/db/v1/database_test.go
@@ -10,9 +10,9 @@
func (c context) createDBs() {
dbs := []string{
- tools.RandomString("db_"),
- tools.RandomString("db_"),
- tools.RandomString("db_"),
+ tools.RandomString("db_", 5),
+ tools.RandomString("db_", 5),
+ tools.RandomString("db_", 5),
}
opts := db.BatchCreateOpts{
@@ -21,15 +21,17 @@
db.CreateOpts{Name: dbs[2]},
}
- res := db.Create(c.client, c.instanceID, opts)
+ err := db.Create(c.client, c.instanceID, opts).ExtractErr()
c.Logf("Created three databases on instance %s: %s, %s, %s", c.instanceID, dbs[0], dbs[1], dbs[2])
+ c.AssertNoErr(err)
+
c.DBIDs = dbs
}
func (c context) listDBs() {
c.Logf("Listing databases on instance %s", c.instanceID)
- err := dbs.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
+ err := db.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
dbList, err := db.ExtractDBs(page)
c.AssertNoErr(err)
@@ -40,13 +42,13 @@
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) deleteDBs() {
for _, id := range c.DBIDs {
err := db.Delete(c.client, c.instanceID, id).ExtractErr()
- c.CheckNoErr(err)
- t.Logf("Deleted DB %s", id)
+ c.AssertNoErr(err)
+ c.Logf("Deleted DB %s", id)
}
}
diff --git a/acceptance/rackspace/db/v1/flavor_test.go b/acceptance/rackspace/db/v1/flavor_test.go
index e121f68..e5131c7 100644
--- a/acceptance/rackspace/db/v1/flavor_test.go
+++ b/acceptance/rackspace/db/v1/flavor_test.go
@@ -3,6 +3,7 @@
package v1
import (
+ os "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/rackspace/db/v1/flavors"
)
@@ -10,8 +11,8 @@
func (c context) listFlavors() {
c.Logf("Listing flavors")
- err := flavors.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
- flavorList, err := db.ExtractFlavors(page)
+ err := flavors.List(c.client).EachPage(func(page pagination.Page) (bool, error) {
+ flavorList, err := os.ExtractFlavors(page)
c.AssertNoErr(err)
for _, f := range flavorList {
@@ -21,11 +22,11 @@
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) getFlavor() {
- flavor, err := flavors.Get(c.client, "1").Extract()
+ flavor, err := flavors.Get(c.client, 1).Extract()
c.Logf("Getting flavor %s", flavor.ID)
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
diff --git a/acceptance/rackspace/db/v1/instance_test.go b/acceptance/rackspace/db/v1/instance_test.go
index eb745e2..4bc44ab 100644
--- a/acceptance/rackspace/db/v1/instance_test.go
+++ b/acceptance/rackspace/db/v1/instance_test.go
@@ -3,13 +3,15 @@
package v1
import (
+ "testing"
+
"github.com/rackspace/gophercloud/acceptance/tools"
"github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/rackspace/db/v1/instances"
th "github.com/rackspace/gophercloud/testhelper"
)
-func TestRunner(t *testingT) {
+func TestRunner(t *testing.T) {
c := newContext(t)
// FLAVOR tests
@@ -49,7 +51,7 @@
c.deleteConfigGrp()
// DATABASE tests
- c.createDB()
+ c.createDBs()
c.listDBs()
// USER tests
@@ -65,7 +67,7 @@
// TEARDOWN
c.deleteUsers()
c.deleteDBs()
- c.deleteInstance(id)
+ c.deleteInstance()
}
func (c context) createInstance() {
@@ -78,9 +80,9 @@
instance, err := instances.Create(c.client, opts).Extract()
th.AssertNoErr(c.test, err)
- c.Logf("Restarting %s. Waiting...", id)
- c.WaitUntilActive(id)
- c.Logf("Created DB %#v", instance)
+ c.Logf("Restarting %s. Waiting...", instance.ID)
+ c.WaitUntilActive(instance.ID)
+ c.Logf("Created DB %#v", instance.ID)
c.instanceID = instance.ID
}
@@ -92,14 +94,14 @@
instanceList, err := instances.ExtractInstances(page)
c.AssertNoErr(err)
- for _, n := range networkList {
+ for _, instance := range instanceList {
c.Logf("Instance: %#v", instance)
}
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) getInstance() {
@@ -115,7 +117,7 @@
}
func (c context) enableRootUser() {
- err := instances.EnableRootUser(c.client, c.instanceID).ExtractErr()
+ _, err := instances.EnableRootUser(c.client, c.instanceID).Extract()
c.AssertNoErr(err)
c.Logf("Enabled root user on %s", c.instanceID)
}
@@ -128,7 +130,7 @@
func (c context) restartInstance() {
id := c.instanceID
- err := instances.Restart(c.client, id).ExtractErr()
+ err := instances.RestartService(c.client, id).ExtractErr()
c.AssertNoErr(err)
c.Logf("Restarting %s. Waiting...", id)
c.WaitUntilActive(id)
@@ -137,7 +139,7 @@
func (c context) resizeInstance() {
id := c.instanceID
- err := instances.Resize(c.client, id, "2").ExtractErr()
+ err := instances.ResizeInstance(c.client, id, "2").ExtractErr()
c.AssertNoErr(err)
c.Logf("Resizing %s. Waiting...", id)
c.WaitUntilActive(id)
@@ -146,7 +148,7 @@
func (c context) resizeVol() {
id := c.instanceID
- err := instances.ResizeVol(c.client, id, 2).ExtractErr()
+ err := instances.ResizeVolume(c.client, id, 2).ExtractErr()
c.AssertNoErr(err)
c.Logf("Resizing volume of %s. Waiting...", id)
c.WaitUntilActive(id)
diff --git a/acceptance/rackspace/db/v1/replica_test.go b/acceptance/rackspace/db/v1/replica_test.go
index 96eaf19..3da2881 100644
--- a/acceptance/rackspace/db/v1/replica_test.go
+++ b/acceptance/rackspace/db/v1/replica_test.go
@@ -9,8 +9,6 @@
)
func (c context) createReplica() {
- repl, err := instances.Create(c.client, opts).Extract()
-
opts := instances.CreateOpts{
FlavorRef: "1",
Size: 1,
@@ -18,11 +16,11 @@
ReplicaOf: c.instanceID,
}
- instance, err := instances.Create(c.client, opts).Extract()
+ repl, err := instances.Create(c.client, opts).Extract()
th.AssertNoErr(c.test, err)
c.Logf("Creating replica of %s. Waiting...", c.instanceID)
- c.WaitUntilActive(id)
+ c.WaitUntilActive(repl.ID)
c.Logf("Created replica %#v", repl)
c.replicaID = repl.ID
@@ -31,4 +29,5 @@
func (c context) detachReplica() {
err := instances.DetachReplica(c.client, c.replicaID).ExtractErr()
c.Logf("Detached replica %s", c.replicaID)
+ c.AssertNoErr(err)
}
diff --git a/acceptance/rackspace/db/v1/user_test.go b/acceptance/rackspace/db/v1/user_test.go
index 9bf00dd..53cebc1 100644
--- a/acceptance/rackspace/db/v1/user_test.go
+++ b/acceptance/rackspace/db/v1/user_test.go
@@ -4,51 +4,51 @@
import (
"github.com/rackspace/gophercloud/acceptance/tools"
- "github.com/rackspace/gophercloud/openstack/identity/v2/users"
+ db "github.com/rackspace/gophercloud/openstack/db/v1/databases"
+ os "github.com/rackspace/gophercloud/openstack/db/v1/users"
"github.com/rackspace/gophercloud/pagination"
- db "github.com/rackspace/gophercloud/rackspace/db/v1/databases"
- u "github.com/rackspace/gophercloud/rackspace/db/v1/users"
+ "github.com/rackspace/gophercloud/rackspace/db/v1/users"
)
func (c context) createUsers() {
- users := []string{
- tools.RandomString("user_"),
- tools.RandomString("user_"),
- tools.RandomString("user_"),
+ c.users = []string{
+ tools.RandomString("user_", 5),
+ tools.RandomString("user_", 5),
+ tools.RandomString("user_", 5),
}
- db1 := db.CreateOpt{Name: c.DBIDs[0]}
- db2 := db.CreateOpt{Name: c.DBIDs[1]}
- db3 := db.CreateOpt{Name: c.DBIDs[2]}
+ db1 := db.CreateOpts{Name: c.DBIDs[0]}
+ db2 := db.CreateOpts{Name: c.DBIDs[1]}
+ db3 := db.CreateOpts{Name: c.DBIDs[2]}
- opts := u.BatchCreateOpts{
- u.CreateOpts{
- Name: users[0],
- Password: tools.RandomString(),
- databases: db.BatchCreateOpts{db1, db2, db3},
+ opts := os.BatchCreateOpts{
+ os.CreateOpts{
+ Name: c.users[0],
+ Password: tools.RandomString("db_", 5),
+ Databases: db.BatchCreateOpts{db1, db2, db3},
},
- u.CreateOpts{
- Name: users[1],
- Password: tools.RandomString(),
- databases: db.BatchCreateOpts{db1, db2},
+ os.CreateOpts{
+ Name: c.users[1],
+ Password: tools.RandomString("db_", 5),
+ Databases: db.BatchCreateOpts{db1, db2},
},
- u.CreateOpts{
- Name: users[2],
- Password: tools.RandomString(),
- databases: db.BatchCreateOpts{db3},
+ os.CreateOpts{
+ Name: c.users[2],
+ Password: tools.RandomString("db_", 5),
+ Databases: db.BatchCreateOpts{db3},
},
}
- err := u.Create(c.client, c.instanceID, opts).ExtractErr()
- c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, users[0], users[1], users[2])
- c.users = users
+ err := users.Create(c.client, c.instanceID, opts).ExtractErr()
+ c.Logf("Created three users on instance %s: %s, %s, %s", c.instanceID, c.users[0], c.users[1], c.users[2])
+ c.AssertNoErr(err)
}
func (c context) listUsers() {
c.Logf("Listing users on instance %s", c.instanceID)
- err := users.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
- uList, err := u.ExtractUsers(page)
+ err := os.List(c.client, c.instanceID).EachPage(func(page pagination.Page) (bool, error) {
+ uList, err := os.ExtractUsers(page)
c.AssertNoErr(err)
for _, u := range uList {
@@ -58,44 +58,44 @@
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) deleteUsers() {
for _, id := range c.users {
- err := u.Delete(c.client, c.instanceID, id).ExtractErr()
- c.CheckNoErr(err)
- t.Logf("Deleted user %s", id)
+ err := users.Delete(c.client, c.instanceID, id).ExtractErr()
+ c.AssertNoErr(err)
+ c.Logf("Deleted user %s", id)
}
}
func (c context) changeUserPwd() {
- opts := u.BatchCreateOpts{}
+ opts := os.BatchCreateOpts{}
- for _, id := range c.users[:1] {
- opts = append(opts, u.CreateOpts{Password: tools.PrefixString("", 5)})
+ for _, name := range c.users[:1] {
+ opts = append(opts, os.CreateOpts{Name: name, Password: tools.RandomString("", 5)})
}
- err := u.UpdatePassword(c.client, c.instanceID, opts).ExtractErr()
+ err := users.ChangePassword(c.client, c.instanceID, opts).ExtractErr()
c.Logf("Updated 2 users' passwords")
c.AssertNoErr(err)
}
func (c context) getUser() {
- user, err := u.Get(c.client, c.instanceID, c.users[0]).Extract()
+ user, err := users.Get(c.client, c.instanceID, c.users[0]).Extract()
c.Logf("Getting user %s", user)
c.AssertNoErr(err)
}
func (c context) updateUser() {
- opts := u.CreateOpts{Name: tools.PrefixString("new_name_", 5)}
- user, err := u.Update(c.client, c.instanceID, c.users[0], opts).Extract()
- c.Logf("Updated user %s", user)
+ opts := os.CreateOpts{Name: tools.RandomString("new_name_", 5)}
+ err := users.Update(c.client, c.instanceID, c.users[0], opts).ExtractErr()
+ c.Logf("Updated user %s", c.users[0])
c.AssertNoErr(err)
}
func (c context) listUserAccess() {
- err := u.ListAccess(c.client, c.instanceId, c.users[0]).EachPage(func(page pagination.Page) (bool, error) {
+ err := users.ListAccess(c.client, c.instanceID, c.users[0]).EachPage(func(page pagination.Page) (bool, error) {
dbList, err := db.ExtractDBs(page)
c.AssertNoErr(err)
@@ -106,17 +106,19 @@
return true, nil
})
- c.CheckNoErr(err)
+ c.AssertNoErr(err)
}
func (c context) grantUserAccess() {
- userID, dbID := c.users[0], c.DBIDS[0]
- err := u.GrantUserAccess(c.client, c.instanceID, userID, dbID)
- c.Logf("Granted access for user %s to DB %s", userID, dbID)
+ opts := db.BatchCreateOpts{db.CreateOpts{Name: c.DBIDs[0]}}
+ err := users.GrantAccess(c.client, c.instanceID, c.users[0], opts).ExtractErr()
+ c.Logf("Granted access for user %s to DB %s", c.users[0], c.DBIDs[0])
+ c.AssertNoErr(err)
}
func (c context) revokeUserAccess() {
- userID, dbID := c.users[0], c.DBIDS[0]
- err := u.RevokeUserAccess(c.client, c.instanceID, userID, dbID)
- c.Logf("Revoked access for user %s to DB %s", userID, dbID)
+ dbName, userName := c.DBIDs[0], c.users[0]
+ err := users.RevokeAccess(c.client, c.instanceID, userName, dbName).ExtractErr()
+ c.Logf("Revoked access for user %s to DB %s", userName, dbName)
+ c.AssertNoErr(err)
}