blob: 62e5fec7059f5366866f76a16459af890325cf82 [file] [log] [blame]
Jamie Hannaford5b7acc12015-02-13 09:14:25 +01001package flavors
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 fake "github.com/rackspace/gophercloud/testhelper/client"
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010010 "github.com/rackspace/gophercloud/testhelper/fixture"
11)
12
13var (
14 flavorID = "{flavorID}"
15 _baseURL = "/flavors"
16 resURL = "/flavors/" + flavorID
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010017)
18
19func TestListFlavors(t *testing.T) {
20 th.SetupHTTP()
21 defer th.TeardownHTTP()
22
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010023 fixture.SetupHandler(t, _baseURL, "GET", "", listFlavorsResp, 200)
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010024
25 pages := 0
26 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
27 pages++
28
29 actual, err := ExtractFlavors(page)
30 if err != nil {
31 return false, err
32 }
33
34 expected := []Flavor{
35 Flavor{
36 ID: 1,
37 Name: "m1.tiny",
38 RAM: 512,
39 Links: []gophercloud.Link{
40 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
41 gophercloud.Link{Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"},
42 },
43 },
44 Flavor{
45 ID: 2,
46 Name: "m1.small",
47 RAM: 1024,
48 Links: []gophercloud.Link{
49 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"},
50 gophercloud.Link{Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"},
51 },
52 },
53 Flavor{
54 ID: 3,
55 Name: "m1.medium",
56 RAM: 2048,
57 Links: []gophercloud.Link{
58 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"},
59 gophercloud.Link{Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"},
60 },
61 },
62 Flavor{
63 ID: 4,
64 Name: "m1.large",
65 RAM: 4096,
66 Links: []gophercloud.Link{
67 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"},
68 gophercloud.Link{Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"},
69 },
70 },
71 }
72
73 th.AssertDeepEquals(t, expected, actual)
74
75 return true, nil
76 })
77
78 th.AssertNoErr(t, err)
79 if pages != 1 {
80 t.Errorf("Expected one page, got %d", pages)
81 }
82}
83
84func TestGetFlavor(t *testing.T) {
85 th.SetupHTTP()
86 defer th.TeardownHTTP()
87
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010088 fixture.SetupHandler(t, resURL, "GET", "", getFlavorResp, 200)
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010089
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010090 actual, err := Get(fake.ServiceClient(), flavorID).Extract()
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010091 th.AssertNoErr(t, err)
92
93 expected := &Flavor{
94 ID: 1,
95 Name: "m1.tiny",
96 RAM: 512,
97 Links: []gophercloud.Link{
98 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
99 },
100 }
101
102 th.AssertDeepEquals(t, expected, actual)
103}