blob: 6f6490ea0a7e9f59615447729423a972c285aaef [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
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/flavors"
Ash Wilsonfd566482014-09-23 15:47:35 -040010)
11
Joe Topjian8349dfa2016-07-24 02:11:27 +000012func TestFlavorsList(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 Topjian8349dfa2016-07-24 02:11:27 +000018 allPages, err := flavors.ListDetail(client, nil).AllPages()
19 if err != nil {
20 t.Fatalf("Unable to retrieve flavors: %v", err)
21 }
Ash Wilsonfd566482014-09-23 15:47:35 -040022
Joe Topjian8349dfa2016-07-24 02:11:27 +000023 allFlavors, err := flavors.ExtractFlavors(allPages)
24 if err != nil {
25 t.Fatalf("Unable to extract flavor results: %v", err)
26 }
Ash Wilsonfd566482014-09-23 15:47:35 -040027
Joe Topjian8349dfa2016-07-24 02:11:27 +000028 for _, flavor := range allFlavors {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060029 PrintFlavor(t, &flavor)
Joe Topjian8349dfa2016-07-24 02:11:27 +000030 }
Ash Wilsonfd566482014-09-23 15:47:35 -040031}
32
Joe Topjian8349dfa2016-07-24 02:11:27 +000033func TestFlavorsGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060034 client, err := clients.NewComputeV2Client()
Ash Wilsonfd566482014-09-23 15:47:35 -040035 if err != nil {
36 t.Fatalf("Unable to create a compute client: %v", err)
37 }
38
Joe Topjian1c15e3f2016-08-08 10:48:38 -060039 choices, err :=clients.AcceptanceTestChoicesFromEnv()
Ash Wilsonfd566482014-09-23 15:47:35 -040040 if err != nil {
41 t.Fatal(err)
42 }
43
Ash Wilson89734d02014-09-25 13:50:08 -040044 flavor, err := flavors.Get(client, choices.FlavorID).Extract()
Ash Wilsonfd566482014-09-23 15:47:35 -040045 if err != nil {
46 t.Fatalf("Unable to get flavor information: %v", err)
47 }
Ash Wilsonfd566482014-09-23 15:47:35 -040048
Joe Topjian1c15e3f2016-08-08 10:48:38 -060049 PrintFlavor(t, flavor)
Ash Wilsonfd566482014-09-23 15:47:35 -040050}