blob: 88b5871a1a258689c7cecf173bb5542583f3b998 [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()
Jamie Hannaford4a170282015-02-18 14:16:57 +010015 HandleList(t)
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010016
17 pages := 0
18 err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
19 pages++
20
21 actual, err := ExtractFlavors(page)
22 if err != nil {
23 return false, err
24 }
25
26 expected := []Flavor{
27 Flavor{
Jamie Hannaford11108402015-02-23 10:31:41 +010028 ID: "1",
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010029 Name: "m1.tiny",
30 RAM: 512,
31 Links: []gophercloud.Link{
32 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
33 gophercloud.Link{Href: "https://openstack.example.com/flavors/1", Rel: "bookmark"},
34 },
35 },
36 Flavor{
Jamie Hannaford11108402015-02-23 10:31:41 +010037 ID: "2",
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010038 Name: "m1.small",
39 RAM: 1024,
40 Links: []gophercloud.Link{
41 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/2", Rel: "self"},
42 gophercloud.Link{Href: "https://openstack.example.com/flavors/2", Rel: "bookmark"},
43 },
44 },
45 Flavor{
Jamie Hannaford11108402015-02-23 10:31:41 +010046 ID: "3",
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010047 Name: "m1.medium",
48 RAM: 2048,
49 Links: []gophercloud.Link{
50 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/3", Rel: "self"},
51 gophercloud.Link{Href: "https://openstack.example.com/flavors/3", Rel: "bookmark"},
52 },
53 },
54 Flavor{
Jamie Hannaford11108402015-02-23 10:31:41 +010055 ID: "4",
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010056 Name: "m1.large",
57 RAM: 4096,
58 Links: []gophercloud.Link{
59 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/4", Rel: "self"},
60 gophercloud.Link{Href: "https://openstack.example.com/flavors/4", Rel: "bookmark"},
61 },
62 },
63 }
64
65 th.AssertDeepEquals(t, expected, actual)
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010066 return true, nil
67 })
68
69 th.AssertNoErr(t, err)
Jamie Hannaford4a170282015-02-18 14:16:57 +010070 th.AssertEquals(t, 1, pages)
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010071}
72
73func TestGetFlavor(t *testing.T) {
74 th.SetupHTTP()
75 defer th.TeardownHTTP()
Jamie Hannaford4a170282015-02-18 14:16:57 +010076 HandleGet(t)
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010077
Jamie Hannafordd3a78ef2015-02-18 12:17:16 +010078 actual, err := Get(fake.ServiceClient(), flavorID).Extract()
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010079 th.AssertNoErr(t, err)
80
81 expected := &Flavor{
Jamie Hannaford11108402015-02-23 10:31:41 +010082 ID: "1",
Jamie Hannaford5b7acc12015-02-13 09:14:25 +010083 Name: "m1.tiny",
84 RAM: 512,
85 Links: []gophercloud.Link{
86 gophercloud.Link{Href: "https://openstack.example.com/v1.0/1234/flavors/1", Rel: "self"},
87 },
88 }
89
90 th.AssertDeepEquals(t, expected, actual)
91}