blob: 15af9af5441968afec6305e9a400431ce9f0a088 [file] [log] [blame]
Jamie Hannaford2d480372014-10-22 10:47:09 +02001// +build acceptance compute images
Ash Wilsonfd566482014-09-23 15:47:35 -04002
3package v2
4
5import (
6 "testing"
7
Jon Perritt27249f42016-02-18 10:35:59 -06008 "github.com/gophercloud/gophercloud/openstack/compute/v2/images"
Ash Wilsonfd566482014-09-23 15:47:35 -04009)
10
Joe Topjian88310112016-07-24 02:32:58 +000011func TestImagesList(t *testing.T) {
Ash Wilsonfd566482014-09-23 15:47:35 -040012 client, err := newClient()
13 if err != nil {
14 t.Fatalf("Unable to create a compute: client: %v", err)
15 }
16
Joe Topjian88310112016-07-24 02:32:58 +000017 allPages, err := images.ListDetail(client, nil).AllPages()
18 if err != nil {
19 t.Fatalf("Unable to retrieve images: %v", err)
20 }
Ash Wilsonfd566482014-09-23 15:47:35 -040021
Joe Topjian88310112016-07-24 02:32:58 +000022 allImages, err := images.ExtractImages(allPages)
23 if err != nil {
24 t.Fatalf("Unable to extract image results: %v", err)
25 }
Ash Wilsonfd566482014-09-23 15:47:35 -040026
Joe Topjian88310112016-07-24 02:32:58 +000027 for _, image := range allImages {
28 printImage(t, image)
29 }
30}
Ash Wilsonfd566482014-09-23 15:47:35 -040031
Joe Topjian88310112016-07-24 02:32:58 +000032func 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 Wilsonfd566482014-09-23 15:47:35 -040037
Joe Topjian88310112016-07-24 02:32:58 +000038 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
51func 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 Wilsonfd566482014-09-23 15:47:35 -040061}