blob: 9003ca7111318830f91dbc85112ba730803bbed9 [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"
Joe Topjian66a046c2017-01-19 22:07:26 -07009 "github.com/gophercloud/gophercloud/acceptance/tools"
jrperritt9b7b9e62016-07-11 22:30:50 -050010 "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
feiskycf0c7fe2015-11-05 22:06:17 +080011)
12
Joe Topjian68bed5f2016-08-10 15:30:57 -060013func TestVolumesList(t *testing.T) {
14 client, err := clients.NewBlockStorageV2Client()
15 if err != nil {
16 t.Fatalf("Unable to create a blockstorage client: %v", err)
feiskycf0c7fe2015-11-05 22:06:17 +080017 }
18
Joe Topjian68bed5f2016-08-10 15:30:57 -060019 allPages, err := volumes.List(client, volumes.ListOpts{}).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to retrieve volumes: %v", err)
22 }
23
24 allVolumes, err := volumes.ExtractVolumes(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract volumes: %v", err)
27 }
28
29 for _, volume := range allVolumes {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, volume)
Joe Topjian68bed5f2016-08-10 15:30:57 -060031 }
32}
33
34func TestVolumesCreateDestroy(t *testing.T) {
35 client, err := clients.NewBlockStorageV2Client()
36 if err != nil {
37 t.Fatalf("Unable to create blockstorage client: %v", err)
38 }
39
40 volume, err := CreateVolume(t, client)
41 if err != nil {
42 t.Fatalf("Unable to create volume: %v", err)
43 }
44 defer DeleteVolume(t, client, volume)
45
46 newVolume, err := volumes.Get(client, volume.ID).Extract()
47 if err != nil {
48 t.Errorf("Unable to retrieve volume: %v", err)
49 }
50
Joe Topjian66a046c2017-01-19 22:07:26 -070051 tools.PrintResource(t, newVolume)
feiskycf0c7fe2015-11-05 22:06:17 +080052}