blob: b6f6335b6394a181726a887a076cd75f32c53f19 [file] [log] [blame]
Jon Perrittb71a28a2014-09-17 18:16:32 -05001// +build acceptance blockstorage
2
3package v1
4
5import (
6 "os"
7 "strconv"
8 "testing"
Jon Perritt3db65cd2014-09-17 18:32:43 -05009 "time"
Jon Perrittb71a28a2014-09-17 18:16:32 -050010
11 "github.com/rackspace/gophercloud"
12 "github.com/rackspace/gophercloud/openstack"
13 "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
14 "github.com/rackspace/gophercloud/openstack/utils"
15 "github.com/rackspace/gophercloud/pagination"
16)
17
18var numVols = 1
19
20func newClient() (*gophercloud.ServiceClient, error) {
21 ao, err := utils.AuthOptions()
22 if err != nil {
23 return nil, err
24 }
25
26 client, err := openstack.AuthenticatedClient(ao)
27 if err != nil {
28 return nil, err
29 }
30
31 return openstack.NewBlockStorageV1(client, gophercloud.EndpointOpts{
32 Region: os.Getenv("OS_REGION_NAME"),
33 })
34}
35
36func TestVolumes(t *testing.T) {
37 client, err := newClient()
38 if err != nil {
39 t.Fatalf("Failed to create Block Storage v1 client: %v", err)
40 }
41
42 for i := 0; i < numVols; i++ {
Jon Perritt3db65cd2014-09-17 18:32:43 -050043 cv, err := volumes.Create(client, volumes.VolumeOpts{
Jon Perrittb71a28a2014-09-17 18:16:32 -050044 Size: 1,
45 Name: "gophercloud-test-volume-" + strconv.Itoa(i),
46 })
47 if err != nil {
48 t.Error(err)
49 return
Jon Perritt3db65cd2014-09-17 18:32:43 -050050 }
51 defer func() {
52 time.Sleep(10000 * time.Millisecond)
53 err = volumes.Delete(client, cv.ID)
54 if err != nil {
55 t.Error(err)
56 return
57 }
58 }()
59
Jon Perrittb71a28a2014-09-17 18:16:32 -050060 }
61
62 pager := volumes.List(client, volumes.ListOpts{})
63 if err != nil {
64 t.Error(err)
65 return
66 }
67 err = pager.EachPage(func(page pagination.Page) (bool, error) {
68 vols, err := volumes.ExtractVolumes(page)
69 if len(vols) != numVols {
70 t.Errorf("Expected %d volumes, got %d", numVols, len(vols))
71 }
72 return true, err
73 })
74}