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" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 10 | ) |
| 11 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame^] | 12 | func TestVolumesList(t *testing.T) { |
| 13 | client, err := clients.NewBlockStorageV1Client() |
| 14 | if err != nil { |
| 15 | t.Fatalf("Unable to create a blockstorage client: %v", err) |
Jon Perritt | 97347a0 | 2014-09-21 13:34:48 -0500 | [diff] [blame] | 16 | } |
| 17 | |
Joe Topjian | 68bed5f | 2016-08-10 15:30:57 -0600 | [diff] [blame^] | 18 | 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 | |
| 33 | func TestVolumesCreateDestroy(t *testing.T) { |
| 34 | client, err := clients.NewBlockStorageV1Client() |
| 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) |
Jon Perritt | b71a28a | 2014-09-17 18:16:32 -0500 | [diff] [blame] | 51 | } |