update unit and acceptance tests
diff --git a/acceptance/openstack/blockstorage/v1/volumes_test.go b/acceptance/openstack/blockstorage/v1/volumes_test.go
index 22d9653..21a47ac 100644
--- a/acceptance/openstack/blockstorage/v1/volumes_test.go
+++ b/acceptance/openstack/blockstorage/v1/volumes_test.go
@@ -5,19 +5,15 @@
import (
"fmt"
"os"
- "strconv"
"testing"
- "time"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack"
- "github.com/rackspace/gophercloud/openstack/blockStorage/v1/volumes"
+ "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/rackspace/gophercloud/openstack/utils"
"github.com/rackspace/gophercloud/pagination"
)
-var numVols = 1
-
func newClient() (*gophercloud.ServiceClient, error) {
ao, err := utils.AuthOptions()
if err != nil {
@@ -40,36 +36,35 @@
t.Fatalf("Failed to create Block Storage v1 client: %v", err)
}
- var cv *volumes.Volume
- for i := 0; i < numVols; i++ {
- cv, err = volumes.Create(client, volumes.CreateOpts{
- Size: 1,
- Name: "gophercloud-test-volume-" + strconv.Itoa(i),
- })
+ cv, err := volumes.Create(client, &volumes.CreateOpts{
+ Size: 1,
+ Name: "gophercloud-test-volume",
+ }).Extract()
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ defer func() {
+ err = volumes.WaitForStatus(client, cv.ID, "available", 60)
+ if err != nil {
+ t.Error(err)
+ }
+ err = volumes.Delete(client, cv.ID)
if err != nil {
t.Error(err)
return
}
- defer func() {
- time.Sleep(10000 * time.Millisecond)
- err = volumes.Delete(client, cv.ID)
- if err != nil {
- t.Error(err)
- return
- }
- }()
+ }()
- }
-
- _, err = volumes.Update(client, cv.ID, volumes.UpdateOpts{
+ _, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{
Name: "gophercloud-updated-volume",
- })
+ }).Extract()
if err != nil {
t.Error(err)
return
}
- v, err := volumes.Get(client, cv.ID).ExtractVolume()
+ v, err := volumes.Get(client, cv.ID).Extract()
if err != nil {
t.Error(err)
return
@@ -80,16 +75,14 @@
t.Errorf("Unable to update volume: Expected name: gophercloud-updated-volume\nActual name: %s", v.Name)
}
- pager := volumes.List(client, volumes.ListOpts{})
- if err != nil {
- t.Error(err)
- return
- }
- err = pager.EachPage(func(page pagination.Page) (bool, error) {
+ err = volumes.List(client, &volumes.ListOpts{Name: "gophercloud-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) {
vols, err := volumes.ExtractVolumes(page)
- if len(vols) != numVols {
- t.Errorf("Expected %d volumes, got %d", numVols, len(vols))
+ if len(vols) != 1 {
+ t.Errorf("Expected 1 volume, got %d", len(vols))
}
return true, err
})
+ if err != nil {
+ t.Errorf("Error listing volumes: %v", err)
+ }
}