blob: 9f51b12280b66d854e4e21e63d755a61eb2dfb33 [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
8 "github.com/rackspace/gophercloud/openstack/compute/v2/flavors"
9 "github.com/rackspace/gophercloud/pagination"
10)
11
12func 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 Wilson8a0e24b2014-10-24 14:14:36 -040020 pager := flavors.ListDetail(client, nil)
Ash Wilsonfd566482014-09-23 15:47:35 -040021 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
40func 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 Wilson89734d02014-09-25 13:50:08 -040051 flavor, err := flavors.Get(client, choices.FlavorID).Extract()
Ash Wilsonfd566482014-09-23 15:47:35 -040052 if err != nil {
53 t.Fatalf("Unable to get flavor information: %v", err)
54 }
Ash Wilsonfd566482014-09-23 15:47:35 -040055
56 t.Logf("Flavor: %#v", flavor)
57}