Jamie Hannaford | 2d48037 | 2014-10-22 10:47:09 +0200 | [diff] [blame] | 1 | // +build acceptance compute images |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 8 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/clients" |
| 9 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/acceptance/tools" |
| 10 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/compute/v2/images" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 13 | func TestImagesList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 14 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 15 | if err != nil { |
| 16 | t.Fatalf("Unable to create a compute: client: %v", err) |
| 17 | } |
| 18 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 19 | allPages, err := images.ListDetail(client, nil).AllPages() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to retrieve images: %v", err) |
| 22 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 23 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 24 | allImages, err := images.ExtractImages(allPages) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Unable to extract image results: %v", err) |
| 27 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 28 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 29 | for _, image := range allImages { |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 30 | tools.PrintResource(t, image) |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 31 | } |
| 32 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 33 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 34 | func TestImagesGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 35 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 36 | if err != nil { |
| 37 | t.Fatalf("Unable to create a compute: client: %v", err) |
| 38 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 39 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 40 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | |
| 45 | image, err := images.Get(client, choices.ImageID).Extract() |
| 46 | if err != nil { |
| 47 | t.Fatalf("Unable to get image information: %v", err) |
| 48 | } |
| 49 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 50 | tools.PrintResource(t, image) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 51 | } |