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