Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
| 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 | |
| 12 | func TestListFlavors(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 15 | HandleList(t) |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 16 | |
| 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 Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 28 | ID: "1", |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 29 | 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 Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 37 | ID: "2", |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 38 | 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 Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 46 | ID: "3", |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 47 | 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 Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 55 | ID: "4", |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 56 | 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 Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 66 | return true, nil |
| 67 | }) |
| 68 | |
| 69 | th.AssertNoErr(t, err) |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 70 | th.AssertEquals(t, 1, pages) |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | func TestGetFlavor(t *testing.T) { |
| 74 | th.SetupHTTP() |
| 75 | defer th.TeardownHTTP() |
Jamie Hannaford | 4a17028 | 2015-02-18 14:16:57 +0100 | [diff] [blame] | 76 | HandleGet(t) |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 77 | |
Jamie Hannaford | d3a78ef | 2015-02-18 12:17:16 +0100 | [diff] [blame] | 78 | actual, err := Get(fake.ServiceClient(), flavorID).Extract() |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 79 | th.AssertNoErr(t, err) |
| 80 | |
| 81 | expected := &Flavor{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 82 | ID: "1", |
Jamie Hannaford | 5b7acc1 | 2015-02-13 09:14:25 +0100 | [diff] [blame] | 83 | 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 | } |