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 | |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame^] | 8 | "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 Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 11 | ) |
| 12 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 13 | func TestFlavorsList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 14 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 15 | if err != nil { |
| 16 | t.Fatalf("Unable to create a compute client: %v", err) |
| 17 | } |
| 18 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 19 | allPages, err := flavors.ListDetail(client, nil).AllPages() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to retrieve flavors: %v", err) |
| 22 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 23 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 24 | allFlavors, err := flavors.ExtractFlavors(allPages) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Unable to extract flavor results: %v", err) |
| 27 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 28 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 29 | for _, flavor := range allFlavors { |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 30 | tools.PrintResource(t, flavor) |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 31 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 34 | func TestFlavorsGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 35 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 36 | if err != nil { |
| 37 | t.Fatalf("Unable to create a compute client: %v", err) |
| 38 | } |
| 39 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 40 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 41 | if err != nil { |
| 42 | t.Fatal(err) |
| 43 | } |
| 44 | |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 45 | flavor, err := flavors.Get(client, choices.FlavorID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 46 | if err != nil { |
| 47 | t.Fatalf("Unable to get flavor information: %v", err) |
| 48 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 49 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 50 | tools.PrintResource(t, flavor) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 51 | } |