blob: 3508bc5f60bc9247e7b5e3af86a57ebe0a45771c [file] [log] [blame]
feiskycf0c7fe2015-11-05 22:06:17 +08001// +build acceptance blockstorage
2
3package v2
4
5import (
feiskycf0c7fe2015-11-05 22:06:17 +08006 "testing"
7
Joe Topjian68bed5f2016-08-10 15:30:57 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
jrperritt9b7b9e62016-07-11 22:30:50 -05009 "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
feiskycf0c7fe2015-11-05 22:06:17 +080010)
11
Joe Topjian68bed5f2016-08-10 15:30:57 -060012func TestVolumesList(t *testing.T) {
13 client, err := clients.NewBlockStorageV2Client()
14 if err != nil {
15 t.Fatalf("Unable to create a blockstorage client: %v", err)
feiskycf0c7fe2015-11-05 22:06:17 +080016 }
17
Joe Topjian68bed5f2016-08-10 15:30:57 -060018 allPages, err := volumes.List(client, volumes.ListOpts{}).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to retrieve volumes: %v", err)
21 }
22
23 allVolumes, err := volumes.ExtractVolumes(allPages)
24 if err != nil {
25 t.Fatalf("Unable to extract volumes: %v", err)
26 }
27
28 for _, volume := range allVolumes {
29 PrintVolume(t, &volume)
30 }
31}
32
33func TestVolumesCreateDestroy(t *testing.T) {
34 client, err := clients.NewBlockStorageV2Client()
35 if err != nil {
36 t.Fatalf("Unable to create blockstorage client: %v", err)
37 }
38
39 volume, err := CreateVolume(t, client)
40 if err != nil {
41 t.Fatalf("Unable to create volume: %v", err)
42 }
43 defer DeleteVolume(t, client, volume)
44
45 newVolume, err := volumes.Get(client, volume.ID).Extract()
46 if err != nil {
47 t.Errorf("Unable to retrieve volume: %v", err)
48 }
49
50 PrintVolume(t, newVolume)
feiskycf0c7fe2015-11-05 22:06:17 +080051}