blob: 8dbafe8d49e85b6dead619aed6913a554e1e3deb [file] [log] [blame]
Jamie Hannaford2d480372014-10-22 10:47:09 +02001// +build acceptance compute flavors
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/flavors"
Ash Wilsonfd566482014-09-23 15:47:35 -040011)
12
Joe Topjian8349dfa2016-07-24 02:11:27 +000013func TestFlavorsList(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 Topjian8349dfa2016-07-24 02:11:27 +000019 allPages, err := flavors.ListDetail(client, nil).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to retrieve flavors: %v", err)
22 }
Ash Wilsonfd566482014-09-23 15:47:35 -040023
Joe Topjian8349dfa2016-07-24 02:11:27 +000024 allFlavors, err := flavors.ExtractFlavors(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract flavor results: %v", err)
27 }
Ash Wilsonfd566482014-09-23 15:47:35 -040028
Joe Topjian8349dfa2016-07-24 02:11:27 +000029 for _, flavor := range allFlavors {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, flavor)
Joe Topjian8349dfa2016-07-24 02:11:27 +000031 }
Ash Wilsonfd566482014-09-23 15:47:35 -040032}
33
Joe Topjian8349dfa2016-07-24 02:11:27 +000034func TestFlavorsGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060035 client, err := clients.NewComputeV2Client()
Ash Wilsonfd566482014-09-23 15:47:35 -040036 if err != nil {
37 t.Fatalf("Unable to create a compute client: %v", err)
38 }
39
Joe Topjian66a046c2017-01-19 22:07:26 -070040 choices, err := clients.AcceptanceTestChoicesFromEnv()
Ash Wilsonfd566482014-09-23 15:47:35 -040041 if err != nil {
42 t.Fatal(err)
43 }
44
Ash Wilson89734d02014-09-25 13:50:08 -040045 flavor, err := flavors.Get(client, choices.FlavorID).Extract()
Ash Wilsonfd566482014-09-23 15:47:35 -040046 if err != nil {
47 t.Fatalf("Unable to get flavor information: %v", err)
48 }
Ash Wilsonfd566482014-09-23 15:47:35 -040049
Joe Topjian66a046c2017-01-19 22:07:26 -070050 tools.PrintResource(t, flavor)
Ash Wilsonfd566482014-09-23 15:47:35 -040051}