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 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/compute/v2/images" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 9 | ) |
| 10 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 11 | func TestImagesList(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 12 | client, err := newClient() |
| 13 | if err != nil { |
| 14 | t.Fatalf("Unable to create a compute: client: %v", err) |
| 15 | } |
| 16 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 17 | allPages, err := images.ListDetail(client, nil).AllPages() |
| 18 | if err != nil { |
| 19 | t.Fatalf("Unable to retrieve images: %v", err) |
| 20 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 21 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 22 | allImages, err := images.ExtractImages(allPages) |
| 23 | if err != nil { |
| 24 | t.Fatalf("Unable to extract image results: %v", err) |
| 25 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 26 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 27 | for _, image := range allImages { |
| 28 | printImage(t, image) |
| 29 | } |
| 30 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 31 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 32 | func TestImagesGet(t *testing.T) { |
| 33 | client, err := newClient() |
| 34 | if err != nil { |
| 35 | t.Fatalf("Unable to create a compute: client: %v", err) |
| 36 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 37 | |
Joe Topjian | 8831011 | 2016-07-24 02:32:58 +0000 | [diff] [blame] | 38 | choices, err := ComputeChoicesFromEnv() |
| 39 | if err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | |
| 43 | image, err := images.Get(client, choices.ImageID).Extract() |
| 44 | if err != nil { |
| 45 | t.Fatalf("Unable to get image information: %v", err) |
| 46 | } |
| 47 | |
| 48 | printImage(t, *image) |
| 49 | } |
| 50 | |
| 51 | func printImage(t *testing.T, image images.Image) { |
| 52 | t.Logf("ID: %s", image.ID) |
| 53 | t.Logf("Name: %s", image.Name) |
| 54 | t.Logf("MinDisk: %d", image.MinDisk) |
| 55 | t.Logf("MinRAM: %d", image.MinRAM) |
| 56 | t.Logf("Status: %s", image.Status) |
| 57 | t.Logf("Progress: %d", image.Progress) |
| 58 | t.Logf("Metadata: %#v", image.Metadata) |
| 59 | t.Logf("Created: %s", image.Created) |
| 60 | t.Logf("Updated: %s", image.Updated) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 61 | } |