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