blob: 53291dde4d7681630e7b19c20a16d3dbb3035019 [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
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Jon Perritt27249f42016-02-18 10:35:59 -06009 "github.com/gophercloud/gophercloud/openstack/compute/v2/images"
Ash Wilsonfd566482014-09-23 15:47:35 -040010)
11
Joe Topjian88310112016-07-24 02:32:58 +000012func TestImagesList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060013 client, err := clients.NewComputeV2Client()
Ash Wilsonfd566482014-09-23 15:47:35 -040014 if err != nil {
15 t.Fatalf("Unable to create a compute: client: %v", err)
16 }
17
Joe Topjian88310112016-07-24 02:32:58 +000018 allPages, err := images.ListDetail(client, nil).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to retrieve images: %v", err)
21 }
Ash Wilsonfd566482014-09-23 15:47:35 -040022
Joe Topjian88310112016-07-24 02:32:58 +000023 allImages, err := images.ExtractImages(allPages)
24 if err != nil {
25 t.Fatalf("Unable to extract image results: %v", err)
26 }
Ash Wilsonfd566482014-09-23 15:47:35 -040027
Joe Topjian88310112016-07-24 02:32:58 +000028 for _, image := range allImages {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060029 PrintImage(t, image)
Joe Topjian88310112016-07-24 02:32:58 +000030 }
31}
Ash Wilsonfd566482014-09-23 15:47:35 -040032
Joe Topjian88310112016-07-24 02:32:58 +000033func TestImagesGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060034 client, err := clients.NewComputeV2Client()
Joe Topjian88310112016-07-24 02:32:58 +000035 if err != nil {
36 t.Fatalf("Unable to create a compute: client: %v", err)
37 }
Ash Wilsonfd566482014-09-23 15:47:35 -040038
Joe Topjian1c15e3f2016-08-08 10:48:38 -060039 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjian88310112016-07-24 02:32:58 +000040 if err != nil {
41 t.Fatal(err)
42 }
43
44 image, err := images.Get(client, choices.ImageID).Extract()
45 if err != nil {
46 t.Fatalf("Unable to get image information: %v", err)
47 }
48
Joe Topjian1c15e3f2016-08-08 10:48:38 -060049 PrintImage(t, *image)
Ash Wilsonfd566482014-09-23 15:47:35 -040050}