blob: 4f51776113377a25a1842c6480210f53d2379ec4 [file] [log] [blame]
Jamie Hannaford81954462015-02-13 09:45:27 +01001package flavors
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud"
7 os "github.com/rackspace/gophercloud/openstack/db/v1/flavors"
8 "github.com/rackspace/gophercloud/pagination"
9 th "github.com/rackspace/gophercloud/testhelper"
10 fake "github.com/rackspace/gophercloud/testhelper/client"
11)
12
13func TestListFlavors(t *testing.T) {
14 th.SetupHTTP()
15 defer th.TeardownHTTP()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010016 os.HandleList(t)
Jamie Hannaford81954462015-02-13 09:45:27 +010017
18 pages := 0
19 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
20 pages++
21
22 actual, err := os.ExtractFlavors(page)
23 if err != nil {
24 return false, err
25 }
26
27 expected := []os.Flavor{
28 os.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 os.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 os.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 os.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()
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010080 os.HandleGet(t)
Jamie Hannaford81954462015-02-13 09:45:27 +010081
Jamie Hannaforde635b7d2015-02-18 14:11:46 +010082 actual, err := Get(fake.ServiceClient(), "{flavorID}").Extract()
Jamie Hannaford81954462015-02-13 09:45:27 +010083 th.AssertNoErr(t, err)
84
85 expected := &os.Flavor{
86 ID: 1,
87 Name: "m1.tiny",
88 RAM: 512,
89 Links: []gophercloud.Link{
90 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
91 },
92 }
93
94 th.AssertDeepEquals(t, expected, actual)
95}