Block Storage Acceptance Test Cleanup (#43)
diff --git a/acceptance/openstack/blockstorage/v2/volumes_test.go b/acceptance/openstack/blockstorage/v2/volumes_test.go
index 9edf31a..3508bc5 100644
--- a/acceptance/openstack/blockstorage/v2/volumes_test.go
+++ b/acceptance/openstack/blockstorage/v2/volumes_test.go
@@ -3,61 +3,49 @@
package v2
import (
- "os"
"testing"
- "github.com/gophercloud/gophercloud"
- "github.com/gophercloud/gophercloud/openstack"
+ "github.com/gophercloud/gophercloud/acceptance/clients"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
- "github.com/gophercloud/gophercloud/pagination"
- th "github.com/gophercloud/gophercloud/testhelper"
)
-func newClient(t *testing.T) (*gophercloud.ServiceClient, error) {
- ao, err := openstack.AuthOptionsFromEnv()
- th.AssertNoErr(t, err)
-
- client, err := openstack.AuthenticatedClient(ao)
- th.AssertNoErr(t, err)
-
- return openstack.NewBlockStorageV2(client, gophercloud.EndpointOpts{
- Region: os.Getenv("OS_REGION_NAME"),
- })
-}
-
-func TestVolumes(t *testing.T) {
- client, err := newClient(t)
- th.AssertNoErr(t, err)
-
- cv, err := volumes.Create(client, &volumes.CreateOpts{
- Size: 1,
- Name: "blockv2-volume",
- }).Extract()
- th.AssertNoErr(t, err)
- defer func() {
- err = volumes.WaitForStatus(client, cv.ID, "available", 60)
- th.AssertNoErr(t, err)
- err = volumes.Delete(client, cv.ID).ExtractErr()
- th.AssertNoErr(t, err)
- }()
-
- _, err = volumes.Update(client, cv.ID, &volumes.UpdateOpts{
- Name: "blockv2-updated-volume",
- }).Extract()
- th.AssertNoErr(t, err)
-
- v, err := volumes.Get(client, cv.ID).Extract()
- th.AssertNoErr(t, err)
- t.Logf("Got volume: %+v\n", v)
-
- if v.Name != "blockv2-updated-volume" {
- t.Errorf("Unable to update volume: Expected name: blockv2-updated-volume\nActual name: %s", v.Name)
+func TestVolumesList(t *testing.T) {
+ client, err := clients.NewBlockStorageV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create a blockstorage client: %v", err)
}
- err = volumes.List(client, &volumes.ListOpts{Name: "blockv2-updated-volume"}).EachPage(func(page pagination.Page) (bool, error) {
- vols, err := volumes.ExtractVolumes(page)
- th.CheckEquals(t, 1, len(vols))
- return true, err
- })
- th.AssertNoErr(t, err)
+ allPages, err := volumes.List(client, volumes.ListOpts{}).AllPages()
+ if err != nil {
+ t.Fatalf("Unable to retrieve volumes: %v", err)
+ }
+
+ allVolumes, err := volumes.ExtractVolumes(allPages)
+ if err != nil {
+ t.Fatalf("Unable to extract volumes: %v", err)
+ }
+
+ for _, volume := range allVolumes {
+ PrintVolume(t, &volume)
+ }
+}
+
+func TestVolumesCreateDestroy(t *testing.T) {
+ client, err := clients.NewBlockStorageV2Client()
+ if err != nil {
+ t.Fatalf("Unable to create blockstorage client: %v", err)
+ }
+
+ volume, err := CreateVolume(t, client)
+ if err != nil {
+ t.Fatalf("Unable to create volume: %v", err)
+ }
+ defer DeleteVolume(t, client, volume)
+
+ newVolume, err := volumes.Get(client, volume.ID).Extract()
+ if err != nil {
+ t.Errorf("Unable to retrieve volume: %v", err)
+ }
+
+ PrintVolume(t, newVolume)
}