Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 1 | // +build acceptance blockstorage |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 6 | "testing" |
| 7 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 11 | ) |
| 12 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 13 | func TestVolumesList(t *testing.T) { |
| 14 | client, err := clients.NewBlockStorageV1Client() |
| 15 | if err != nil { |
| 16 | t.Fatalf("Unable to create a blockstorage client: %v", err) |
Jon Perritt | 97347a0 | 2014-09-21 13:34:48 -0500 | [diff] [blame] | 17 | } |
| 18 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 19 | 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 30 | tools.PrintResource(t, volume) |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestVolumesCreateDestroy(t *testing.T) { |
| 35 | client, err := clients.NewBlockStorageV1Client() |
| 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 Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 51 | tools.PrintResource(t, newVolume) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 52 | } |