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 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 9 | ) |
| 10 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 11 | func TestFlavorsList(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 12 | client, err := newClient() |
| 13 | if err != nil { |
| 14 | t.Fatalf("Unable to create a compute client: %v", err) |
| 15 | } |
| 16 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 17 | allPages, err := flavors.ListDetail(client, nil).AllPages() |
| 18 | if err != nil { |
| 19 | t.Fatalf("Unable to retrieve flavors: %v", err) |
| 20 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 21 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 22 | allFlavors, err := flavors.ExtractFlavors(allPages) |
| 23 | if err != nil { |
| 24 | t.Fatalf("Unable to extract flavor results: %v", err) |
| 25 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 26 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 27 | for _, flavor := range allFlavors { |
| 28 | printFlavor(t, &flavor) |
| 29 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 30 | } |
| 31 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 32 | func TestFlavorsGet(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 33 | client, err := newClient() |
| 34 | if err != nil { |
| 35 | t.Fatalf("Unable to create a compute client: %v", err) |
| 36 | } |
| 37 | |
| 38 | choices, err := ComputeChoicesFromEnv() |
| 39 | if err != nil { |
| 40 | t.Fatal(err) |
| 41 | } |
| 42 | |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 43 | flavor, err := flavors.Get(client, choices.FlavorID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 44 | if err != nil { |
| 45 | t.Fatalf("Unable to get flavor information: %v", err) |
| 46 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 47 | |
Joe Topjian | 8349dfa | 2016-07-24 02:11:27 +0000 | [diff] [blame] | 48 | printFlavor(t, flavor) |
| 49 | } |
| 50 | |
| 51 | func printFlavor(t *testing.T, flavor *flavors.Flavor) { |
| 52 | t.Logf("ID: %s", flavor.ID) |
| 53 | t.Logf("Name: %s", flavor.Name) |
| 54 | t.Logf("RAM: %d", flavor.RAM) |
| 55 | t.Logf("Disk: %d", flavor.Disk) |
| 56 | t.Logf("Swap: %d", flavor.Swap) |
| 57 | t.Logf("RxTxFactor: %f", flavor.RxTxFactor) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 58 | } |