blob: 9ed9e59db9c53857e881f3c7805f91daeb39284c [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"
10)
11
12func TestListFlavors(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15
16 HandleListFlavorsSuccessfully(t)
17
18 pages := 0
19 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
20 pages++
21
22 actual, err := ExtractFlavors(page)
23 if err != nil {
24 return false, err
25 }
26
27 expected := []Flavor{
28 Flavor{
29 ID: 1,
30 Name: "m1.tiny",
31 RAM: 512,
32 Links: []gophercloud.Link{
33 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
34 gophercloud.Link{Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"},
35 },
36 },
37 Flavor{
38 ID: 2,
39 Name: "m1.small",
40 RAM: 1024,
41 Links: []gophercloud.Link{
42 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"},
43 gophercloud.Link{Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"},
44 },
45 },
46 Flavor{
47 ID: 3,
48 Name: "m1.medium",
49 RAM: 2048,
50 Links: []gophercloud.Link{
51 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"},
52 gophercloud.Link{Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"},
53 },
54 },
55 Flavor{
56 ID: 4,
57 Name: "m1.large",
58 RAM: 4096,
59 Links: []gophercloud.Link{
60 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"},
61 gophercloud.Link{Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"},
62 },
63 },
64 }
65
66 th.AssertDeepEquals(t, expected, actual)
67
68 return true, nil
69 })
70
71 th.AssertNoErr(t, err)
72 if pages != 1 {
73 t.Errorf("Expected one page, got %d", pages)
74 }
75}
76
77func TestGetFlavor(t *testing.T) {
78 th.SetupHTTP()
79 defer th.TeardownHTTP()
80
81 HandleGetFlavorSuccessfully(t, "12345")
82
83 actual, err := Get(fake.ServiceClient(), "12345").Extract()
84 th.AssertNoErr(t, err)
85
86 expected := &Flavor{
87 ID: 1,
88 Name: "m1.tiny",
89 RAM: 512,
90 Links: []gophercloud.Link{
91 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
92 },
93 }
94
95 th.AssertDeepEquals(t, expected, actual)
96}