Jamie Hannaford | 4c2a1f2 | 2014-10-23 17:31:55 +0200 | [diff] [blame] | 1 | // +build acceptance blockstorage volumes |
| 2 | |
Jamie Hannaford | af209d1 | 2014-10-22 12:37:48 +0200 | [diff] [blame] | 3 | package v1 |
Jamie Hannaford | 48a80ce | 2014-10-23 14:49:51 +0200 | [diff] [blame] | 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" |
| 10 | "github.com/rackspace/gophercloud/pagination" |
| 11 | "github.com/rackspace/gophercloud/rackspace/blockstorage/v1/volumes" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
| 15 | func TestVolumes(t *testing.T) { |
| 16 | client := setup(t) |
| 17 | |
| 18 | t.Logf("Listing volumes") |
| 19 | testVolumeList(t, client) |
| 20 | |
| 21 | t.Logf("Creating volume") |
| 22 | volumeID := testVolumeCreate(t, client) |
| 23 | |
| 24 | t.Logf("Getting volume %s", volumeID) |
| 25 | testVolumeGet(t, client, volumeID) |
| 26 | |
| 27 | t.Logf("Updating volume %s", volumeID) |
| 28 | testVolumeUpdate(t, client, volumeID) |
| 29 | |
| 30 | t.Logf("Deleting volume %s", volumeID) |
| 31 | testVolumeDelete(t, client, volumeID) |
| 32 | } |
| 33 | |
| 34 | func testVolumeList(t *testing.T, client *gophercloud.ServiceClient) { |
| 35 | volumes.List(client).EachPage(func(page pagination.Page) (bool, error) { |
| 36 | vList, err := volumes.ExtractVolumes(page) |
| 37 | th.AssertNoErr(t, err) |
| 38 | |
| 39 | for _, v := range vList { |
| 40 | t.Logf("Volume: ID [%s] Name [%s] Type [%s] Created [%s]", v.ID, v.Name, |
| 41 | v.VolumeType, v.CreatedAt) |
| 42 | } |
| 43 | |
| 44 | return true, nil |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | func testVolumeCreate(t *testing.T, client *gophercloud.ServiceClient) string { |
| 49 | vol, err := volumes.Create(client, os.CreateOpts{Size: 75}).Extract() |
| 50 | th.AssertNoErr(t, err) |
| 51 | t.Logf("Created volume: ID [%s] Size [%s]", vol.ID, vol.Size) |
| 52 | return vol.ID |
| 53 | } |
| 54 | |
| 55 | func testVolumeGet(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 56 | vol, err := volumes.Get(client, id).Extract() |
| 57 | th.AssertNoErr(t, err) |
| 58 | t.Logf("Created volume: ID [%s] Size [%s]", vol.ID, vol.Size) |
| 59 | } |
| 60 | |
| 61 | func testVolumeUpdate(t *testing.T, client *gophercloud.ServiceClient, id string) { |
| 62 | vol, err := volumes.Update(client, id, volumes.UpdateOpts{Name: "new_name"}).Extract() |
| 63 | th.AssertNoErr(t, err) |
| 64 | t.Logf("Created volume: ID [%s] Name [%s]", vol.ID, vol.Name) |
| 65 | } |
| 66 | |
| 67 | func testVolumeDelete(t *testing.T, client *gophercloud.ServiceClient, id string) { |
Jamie Hannaford | e4e6dfe | 2014-10-27 11:50:29 +0100 | [diff] [blame] | 68 | res := volumes.Delete(client, id) |
| 69 | th.AssertNoErr(t, res.Err) |
Jamie Hannaford | 48a80ce | 2014-10-23 14:49:51 +0200 | [diff] [blame] | 70 | t.Logf("Deleted volume %s", id) |
| 71 | } |