Jon Perritt | 45a1d4f | 2015-01-23 10:45:10 -0700 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud" |
| 7 | os "github.com/rackspace/gophercloud/openstack/cdn/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 TestList(t *testing.T) { |
| 14 | th.SetupHTTP() |
| 15 | defer th.TeardownHTTP() |
| 16 | |
| 17 | os.HandleListCDNFlavorsSuccessfully(t) |
| 18 | |
| 19 | count := 0 |
| 20 | |
| 21 | err := List(fake.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 22 | count++ |
| 23 | actual, err := os.ExtractFlavors(page) |
| 24 | if err != nil { |
| 25 | t.Errorf("Failed to extract flavors: %v", err) |
| 26 | return false, err |
| 27 | } |
| 28 | |
| 29 | expected := []os.Flavor{ |
| 30 | os.Flavor{ |
| 31 | ID: "europe", |
| 32 | Providers: []os.Provider{ |
| 33 | os.Provider{ |
| 34 | Provider: "Fastly", |
| 35 | Links: []gophercloud.Link{ |
| 36 | gophercloud.Link{ |
Jon Perritt | b6c3e63 | 2015-01-27 11:39:33 -0700 | [diff] [blame] | 37 | Href: "http://www.fastly.com", |
Jon Perritt | 45a1d4f | 2015-01-23 10:45:10 -0700 | [diff] [blame] | 38 | Rel: "provider_url", |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | }, |
| 43 | Links: []gophercloud.Link{ |
| 44 | gophercloud.Link{ |
| 45 | Href: "https://www.poppycdn.io/v1.0/flavors/europe", |
| 46 | Rel: "self", |
| 47 | }, |
| 48 | }, |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | th.CheckDeepEquals(t, expected, actual) |
| 53 | |
| 54 | return true, nil |
| 55 | }) |
| 56 | th.AssertNoErr(t, err) |
Jon Perritt | 6f8eda9 | 2015-01-27 11:38:35 -0700 | [diff] [blame] | 57 | th.CheckEquals(t, 1, count) |
Jon Perritt | 45a1d4f | 2015-01-23 10:45:10 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | func TestGet(t *testing.T) { |
| 61 | th.SetupHTTP() |
| 62 | defer th.TeardownHTTP() |
| 63 | |
| 64 | os.HandleGetCDNFlavorSuccessfully(t) |
| 65 | |
| 66 | expected := &os.Flavor{ |
| 67 | ID: "asia", |
| 68 | Providers: []os.Provider{ |
| 69 | os.Provider{ |
| 70 | Provider: "ChinaCache", |
| 71 | Links: []gophercloud.Link{ |
| 72 | gophercloud.Link{ |
| 73 | Href: "http://www.chinacache.com", |
| 74 | Rel: "provider_url", |
| 75 | }, |
| 76 | }, |
| 77 | }, |
| 78 | }, |
| 79 | Links: []gophercloud.Link{ |
| 80 | gophercloud.Link{ |
| 81 | Href: "https://www.poppycdn.io/v1.0/flavors/asia", |
| 82 | Rel: "self", |
| 83 | }, |
| 84 | }, |
| 85 | } |
| 86 | |
| 87 | actual, err := Get(fake.ServiceClient(), "asia").Extract() |
| 88 | th.AssertNoErr(t, err) |
| 89 | th.AssertDeepEquals(t, expected, actual) |
| 90 | } |