blob: afa3b0f23df143f66d92e11555f6a471bf9664c7 [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
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +02008 "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 Wilsonfd566482014-09-23 15:47:35 -040011)
12
Joe Topjian88310112016-07-24 02:32:58 +000013func TestImagesList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060014 client, err := clients.NewComputeV2Client()
Ash Wilsonfd566482014-09-23 15:47:35 -040015 if err != nil {
16 t.Fatalf("Unable to create a compute: client: %v", err)
17 }
18
Joe Topjian88310112016-07-24 02:32:58 +000019 allPages, err := images.ListDetail(client, nil).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to retrieve images: %v", err)
22 }
Ash Wilsonfd566482014-09-23 15:47:35 -040023
Joe Topjian88310112016-07-24 02:32:58 +000024 allImages, err := images.ExtractImages(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract image results: %v", err)
27 }
Ash Wilsonfd566482014-09-23 15:47:35 -040028
Joe Topjian88310112016-07-24 02:32:58 +000029 for _, image := range allImages {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, image)
Joe Topjian88310112016-07-24 02:32:58 +000031 }
32}
Ash Wilsonfd566482014-09-23 15:47:35 -040033
Joe Topjian88310112016-07-24 02:32:58 +000034func TestImagesGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060035 client, err := clients.NewComputeV2Client()
Joe Topjian88310112016-07-24 02:32:58 +000036 if err != nil {
37 t.Fatalf("Unable to create a compute: client: %v", err)
38 }
Ash Wilsonfd566482014-09-23 15:47:35 -040039
Joe Topjian1c15e3f2016-08-08 10:48:38 -060040 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjian88310112016-07-24 02:32:58 +000041 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 Topjian66a046c2017-01-19 22:07:26 -070050 tools.PrintResource(t, image)
Ash Wilsonfd566482014-09-23 15:47:35 -040051}