blob: ca810bc559ccf470effb15b792c8b7053454a62c [file] [log] [blame]
Ash Wilsonfd566482014-09-23 15:47:35 -04001// +build acceptance
2
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
20 pager := flavors.List(client, flavors.ListFilterOptions{})
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
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}