blob: f5f6442dd9cc9a0b10a7b9fc2269ac8e87f34315 [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{
Jamie Hannaford8803f832015-02-23 10:44:55 +010029 ID: "1",
Jamie Hannaford81954462015-02-13 09:45:27 +010030 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{
Jamie Hannaford8803f832015-02-23 10:44:55 +010038 ID: "2",
Jamie Hannaford81954462015-02-13 09:45:27 +010039 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{
Jamie Hannaford8803f832015-02-23 10:44:55 +010047 ID: "3",
Jamie Hannaford81954462015-02-13 09:45:27 +010048 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{
Jamie Hannaford8803f832015-02-23 10:44:55 +010056 ID: "4",
Jamie Hannaford81954462015-02-13 09:45:27 +010057 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{
Jamie Hannaford8803f832015-02-23 10:44:55 +010086 ID: "1",
Jamie Hannaford81954462015-02-13 09:45:27 +010087 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}