Jamie Hannaford | 2d48037 | 2014-10-22 10:47:09 +0200 | [diff] [blame] | 1 | // +build acceptance compute flavors |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 10 | ) |
| 11 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 12 | func TestFlavorsList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 13 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 14 | if err != nil { |
| 15 | t.Fatalf("Unable to create a compute client: %v", err) |
| 16 | } |
| 17 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 18 | allPages, err := flavors.ListDetail(client, nil).AllPages() |
| 19 | if err != nil { |
| 20 | t.Fatalf("Unable to retrieve flavors: %v", err) |
| 21 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 22 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 23 | allFlavors, err := flavors.ExtractFlavors(allPages) |
| 24 | if err != nil { |
| 25 | t.Fatalf("Unable to extract flavor results: %v", err) |
| 26 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 27 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 28 | for _, flavor := range allFlavors { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 29 | PrintFlavor(t, &flavor) |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 30 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 31 | } |
| 32 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 33 | func TestFlavorsGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 34 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 35 | if err != nil { |
| 36 | t.Fatalf("Unable to create a compute client: %v", err) |
| 37 | } |
| 38 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 39 | choices, err :=clients.AcceptanceTestChoicesFromEnv() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 40 | if err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 44 | flavor, err := flavors.Get(client, choices.FlavorID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 45 | if err != nil { |
| 46 | t.Fatalf("Unable to get flavor information: %v", err) |
| 47 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 48 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 49 | PrintFlavor(t, flavor) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 50 | } |