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 | |
| 8 | "github.com/rackspace/gophercloud/openstack/compute/v2/flavors" |
| 9 | "github.com/rackspace/gophercloud/pagination" |
| 10 | ) |
| 11 | |
| 12 | func TestListFlavors(t *testing.T) { |
| 13 | client, err := newClient() |
| 14 | if err != nil { |
| 15 | t.Fatalf("Unable to create a compute client: %v", err) |
| 16 | } |
| 17 | |
| 18 | t.Logf("ID\tRegion\tName\tStatus\tCreated") |
| 19 | |
Ash Wilson | 8a0e24b | 2014-10-24 14:14:36 -0400 | [diff] [blame] | 20 | pager := flavors.ListDetail(client, nil) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 21 | count, pages := 0, 0 |
| 22 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 23 | t.Logf("---") |
| 24 | pages++ |
| 25 | flavors, err := flavors.ExtractFlavors(page) |
| 26 | if err != nil { |
| 27 | return false, err |
| 28 | } |
| 29 | |
| 30 | for _, f := range flavors { |
| 31 | t.Logf("%s\t%s\t%d\t%d\t%d", f.ID, f.Name, f.RAM, f.Disk, f.VCPUs) |
| 32 | } |
| 33 | |
| 34 | return true, nil |
| 35 | }) |
| 36 | |
| 37 | t.Logf("--------\n%d flavors listed on %d pages.", count, pages) |
| 38 | } |
| 39 | |
| 40 | func TestGetFlavor(t *testing.T) { |
| 41 | client, err := newClient() |
| 42 | if err != nil { |
| 43 | t.Fatalf("Unable to create a compute client: %v", err) |
| 44 | } |
| 45 | |
| 46 | choices, err := ComputeChoicesFromEnv() |
| 47 | if err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 51 | flavor, err := flavors.Get(client, choices.FlavorID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 52 | if err != nil { |
| 53 | t.Fatalf("Unable to get flavor information: %v", err) |
| 54 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 55 | |
| 56 | t.Logf("Flavor: %#v", flavor) |
| 57 | } |