blob: 9060e545c666ac4aa5b20006ab13e47b3b179835 [file] [log] [blame]
Jon Perritt45a1d4f2015-01-23 10:45:10 -07001package flavors
2
3import (
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
13func 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{
37 Href: "http: //www.fastly.com",
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)
57
58 if count != 1 {
59 t.Errorf("Expected 1 page, got %d", count)
60 }
61}
62
63func TestGet(t *testing.T) {
64 th.SetupHTTP()
65 defer th.TeardownHTTP()
66
67 os.HandleGetCDNFlavorSuccessfully(t)
68
69 expected := &os.Flavor{
70 ID: "asia",
71 Providers: []os.Provider{
72 os.Provider{
73 Provider: "ChinaCache",
74 Links: []gophercloud.Link{
75 gophercloud.Link{
76 Href: "http://www.chinacache.com",
77 Rel: "provider_url",
78 },
79 },
80 },
81 },
82 Links: []gophercloud.Link{
83 gophercloud.Link{
84 Href: "https://www.poppycdn.io/v1.0/flavors/asia",
85 Rel: "self",
86 },
87 },
88 }
89
90 actual, err := Get(fake.ServiceClient(), "asia").Extract()
91 th.AssertNoErr(t, err)
92 th.AssertDeepEquals(t, expected, actual)
93}