update unit and acceptance tests
diff --git a/acceptance/openstack/blockstorage/v1/snapshots_test.go b/acceptance/openstack/blockstorage/v1/snapshots_test.go
index 0d9d5c7..5835048 100644
--- a/acceptance/openstack/blockstorage/v1/snapshots_test.go
+++ b/acceptance/openstack/blockstorage/v1/snapshots_test.go
@@ -3,65 +3,85 @@
package v1
import (
- "fmt"
- "os"
"testing"
- "time"
"github.com/rackspace/gophercloud"
- "github.com/rackspace/gophercloud/openstack/blockStorage/v1/snapshots"
+ "github.com/rackspace/gophercloud/openstack/blockstorage/v1/snapshots"
+ "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
)
-func waitForSnapshot(client *gophercloud.ServiceClient, id string) error {
- for secondsSlept := 0; secondsSlept < 240; secondsSlept++ {
- fmt.Printf("Seconds slept waiting for snapshot: %d\n", secondsSlept)
- gss, err := snapshots.Get(client, id).ExtractSnapshot()
- if err != nil {
- return err
- }
- if gss.Status == "available" {
- return nil
- }
- if gss.Status == "error" {
- return fmt.Errorf("Error waiting for snapshot to create. Snapshot status is 'error'.")
- }
- time.Sleep(1 * time.Second)
- }
- gss, err := snapshots.Get(client, id).ExtractSnapshot()
- if err != nil {
- return err
- }
- return fmt.Errorf("Time out waiting for snapshot to become available: %+v", gss)
-}
-
func TestSnapshots(t *testing.T) {
- volumeID := os.Getenv("OS_VOLUME_ID")
- if volumeID == "" {
- t.Errorf("Expect OS_VOLUME_ID environment variable. Skipping create and delete snapshot functions.")
- return
- }
-
client, err := newClient()
if err != nil {
t.Fatalf("Failed to create Block Storage v1 client: %v", err)
}
- css, err := snapshots.Create(client, snapshots.CreateOpts{
+ v, err := volumes.Create(client, &volumes.CreateOpts{
+ Name: "gophercloud-test-volume",
+ Size: 1,
+ }).Extract()
+ if err != nil {
+ t.Fatalf("Failed to create volume: %v\n", err)
+ }
+
+ err = volumes.WaitForStatus(client, v.ID, "available", 120)
+ if err != nil {
+ t.Fatalf("Failed to create volume: %v\n", err)
+ }
+
+ t.Logf("Created volume: %v\n", v)
+
+ ss, err := snapshots.Create(client, &snapshots.CreateOpts{
Name: "gophercloud-test-snapshot",
- VolumeID: volumeID,
+ VolumeID: v.ID,
+ }).Extract()
+ if err != nil {
+ t.Fatalf("Failed to create snapshot: %v\n", err)
+ }
+
+ err = snapshots.WaitForStatus(client, ss.ID, "available", 120)
+ if err != nil {
+ t.Fatalf("Failed to create snapshot: %v\n", err)
+ }
+
+ t.Logf("Created snapshot: %+v\n", ss)
+
+ err = snapshots.Delete(client, ss.ID)
+ if err != nil {
+ t.Fatalf("Failed to delete snapshot: %v", err)
+ }
+
+ err = gophercloud.WaitFor(120, func() (bool, error) {
+ _, err := snapshots.Get(client, ss.ID).Extract()
+ if err != nil {
+ return true, nil
+ }
+
+ return false, nil
})
if err != nil {
- t.Errorf("Failed to create snapshot: %v\n", err)
+ t.Fatalf("Failed to delete snapshot: %v", err)
}
- err = waitForSnapshot(client, css.ID)
+ t.Log("Deleted snapshot\n")
+
+ err = volumes.Delete(client, v.ID)
if err != nil {
- t.Errorf("Failed to create snapshot: %v\n", err)
+ t.Errorf("Failed to delete volume: %v", err)
}
- err = waitForSnapshot(client, css.ID)
+ err = gophercloud.WaitFor(120, func() (bool, error) {
+ _, err := volumes.Get(client, v.ID).Extract()
+ if err != nil {
+ return true, nil
+ }
- t.Logf("Created snapshots: %+v\n", *css)
+ return false, nil
+ })
+ if err != nil {
+ t.Errorf("Failed to delete volume: %v", err)
+ }
+ t.Log("Deleted volume\n")
}
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)
+ }
}
diff --git a/acceptance/openstack/blockstorage/v1/volumetypes_test.go b/acceptance/openstack/blockstorage/v1/volumetypes_test.go
index be0d2d8..416e341 100644
--- a/acceptance/openstack/blockstorage/v1/volumetypes_test.go
+++ b/acceptance/openstack/blockstorage/v1/volumetypes_test.go
@@ -16,20 +16,20 @@
t.Fatalf("Failed to create Block Storage v1 client: %v", err)
}
- vt, err := volumeTypes.Create(client, volumeTypes.CreateOpts{
+ vt, err := volumetypes.Create(client, &volumetypes.CreateOpts{
ExtraSpecs: map[string]interface{}{
"capabilities": "gpu",
"priority": 3,
},
Name: "gophercloud-test-volumeType",
- })
+ }).Extract()
if err != nil {
t.Error(err)
return
}
defer func() {
time.Sleep(10000 * time.Millisecond)
- err = volumeTypes.Delete(client, vt.ID)
+ err = volumetypes.Delete(client, vt.ID)
if err != nil {
t.Error(err)
return
@@ -37,15 +37,15 @@
}()
t.Logf("Created volume type: %+v\n", vt)
- vt, err = volumeTypes.Get(client, vt.ID).ExtractVolumeType()
+ vt, err = volumetypes.Get(client, vt.ID).Extract()
if err != nil {
t.Error(err)
return
}
t.Logf("Got volume type: %+v\n", vt)
- err = volumeTypes.List(client, volumeTypes.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
- volTypes, err := volumeTypes.ExtractVolumeTypes(page)
+ err = volumetypes.List(client).EachPage(func(page pagination.Page) (bool, error) {
+ volTypes, err := volumetypes.ExtractVolumeTypes(page)
if len(volTypes) != 1 {
t.Errorf("Expected 1 volume type, got %d", len(volTypes))
}
diff --git a/openstack/blockstorage/v1/snapshots/requests.go b/openstack/blockstorage/v1/snapshots/requests.go
index f823b3d..7dcbc46 100644
--- a/openstack/blockstorage/v1/snapshots/requests.go
+++ b/openstack/blockstorage/v1/snapshots/requests.go
@@ -49,13 +49,12 @@
return res
}
-func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
- var res DeleteResult
- _, res.Err = perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
+func Delete(client *gophercloud.ServiceClient, id string) error {
+ _, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
- OkCodes: []int{204},
+ OkCodes: []int{202, 204},
})
- return res
+ return err
}
func Get(client *gophercloud.ServiceClient, id string) GetResult {
@@ -116,7 +115,7 @@
_, res.Err = perigee.Request("PUT", updateURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
- OkCodes: []int{200},
+ OkCodes: []int{202, 204},
ReqBody: &reqBody,
Results: &res.Resp,
})
diff --git a/openstack/blockstorage/v1/snapshots/requests_test.go b/openstack/blockstorage/v1/snapshots/requests_test.go
index dae53fd..4050990 100644
--- a/openstack/blockstorage/v1/snapshots/requests_test.go
+++ b/openstack/blockstorage/v1/snapshots/requests_test.go
@@ -155,6 +155,6 @@
w.WriteHeader(http.StatusNoContent)
})
- res := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
- th.AssertNoErr(t, res.Err)
+ err := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ th.AssertNoErr(t, err)
}
diff --git a/openstack/blockstorage/v1/snapshots/results.go b/openstack/blockstorage/v1/snapshots/results.go
index cc3a419..363d6e2 100644
--- a/openstack/blockstorage/v1/snapshots/results.go
+++ b/openstack/blockstorage/v1/snapshots/results.go
@@ -80,5 +80,3 @@
type UpdateResult struct {
commonResult
}
-
-type DeleteResult commonResult
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index 2a4ce91..7704012 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -60,7 +60,7 @@
// ListOpts holds options for listing volumes. It is passed to the volumes.List function.
type ListOpts struct {
- // AllTenants is an admin-only option. Set it to true to see a tenant volumes.
+ // AllTenants is an admin-only option. Set it to true to see all tenant volumes.
AllTenants bool
// List only volumes that contain Metadata.
Metadata map[string]string
@@ -123,11 +123,10 @@
}
-func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
- var res DeleteResult
- _, res.Err = perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
+func Delete(client *gophercloud.ServiceClient, id string) error {
+ _, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
- OkCodes: []int{204},
+ OkCodes: []int{202, 204},
})
- return res
+ return err
}
diff --git a/openstack/blockstorage/v1/volumes/requests_test.go b/openstack/blockstorage/v1/volumes/requests_test.go
index 2ae8dd3..54ff91d 100644
--- a/openstack/blockstorage/v1/volumes/requests_test.go
+++ b/openstack/blockstorage/v1/volumes/requests_test.go
@@ -155,6 +155,6 @@
w.WriteHeader(http.StatusNoContent)
})
- res := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
- th.AssertNoErr(t, res.Err)
+ err := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ th.AssertNoErr(t, err)
}
diff --git a/openstack/blockstorage/v1/volumes/results.go b/openstack/blockstorage/v1/volumes/results.go
index 961582d..7bf83a5 100644
--- a/openstack/blockstorage/v1/volumes/results.go
+++ b/openstack/blockstorage/v1/volumes/results.go
@@ -80,5 +80,3 @@
type UpdateResult struct {
commonResult
}
-
-type DeleteResult commonResult
diff --git a/openstack/blockstorage/v1/volumetypes/requests.go b/openstack/blockstorage/v1/volumetypes/requests.go
index 678d331..466d043 100644
--- a/openstack/blockstorage/v1/volumetypes/requests.go
+++ b/openstack/blockstorage/v1/volumetypes/requests.go
@@ -12,7 +12,7 @@
Name string
}
-func Create(client *gophercloud.ServiceClient, opts CreateOpts) CreateResult {
+func Create(client *gophercloud.ServiceClient, opts *CreateOpts) CreateResult {
type volumeType struct {
ExtraSpecs map[string]interface{} `json:"extra_specs,omitempty"`
Name *string `json:"name,omitempty"`
@@ -39,19 +39,17 @@
return res
}
-func Delete(client *gophercloud.ServiceClient, id string) DeleteResult {
- var res DeleteResult
+func Delete(client *gophercloud.ServiceClient, id string) error {
_, err := perigee.Request("DELETE", deleteURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{202},
})
- res.Err = err
- return res
+ return err
}
func Get(client *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
- resp, err := perigee.Request("GET", getURL(client, id), perigee.Options{
+ _, err := perigee.Request("GET", getURL(client, id), perigee.Options{
MoreHeaders: client.Provider.AuthenticatedHeaders(),
OkCodes: []int{200},
Results: &res.Resp,
diff --git a/openstack/blockstorage/v1/volumetypes/requests_test.go b/openstack/blockstorage/v1/volumetypes/requests_test.go
index 79f919a..a9c6512 100644
--- a/openstack/blockstorage/v1/volumetypes/requests_test.go
+++ b/openstack/blockstorage/v1/volumetypes/requests_test.go
@@ -149,7 +149,7 @@
`)
})
- options := CreateOpts{Name: "vol-type-001"}
+ options := &CreateOpts{Name: "vol-type-001"}
n, err := Create(ServiceClient(), options).Extract()
th.AssertNoErr(t, err)
@@ -167,6 +167,6 @@
w.WriteHeader(http.StatusAccepted)
})
- res := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
- th.AssertNoErr(t, res.Err)
+ err := Delete(ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
+ th.AssertNoErr(t, err)
}
diff --git a/openstack/blockstorage/v1/volumetypes/results.go b/openstack/blockstorage/v1/volumetypes/results.go
index 54847be..fa10ae7 100644
--- a/openstack/blockstorage/v1/volumetypes/results.go
+++ b/openstack/blockstorage/v1/volumetypes/results.go
@@ -66,5 +66,3 @@
type CreateResult struct {
commonResult
}
-
-type DeleteResult commonResult