blob: d6d299df8ed9af746d6ab661e9f1a660e2288f59 [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{
Jon Perrittb6c3e632015-01-27 11:39:33 -070037 Href: "http://www.fastly.com",
Jon Perritt45a1d4f2015-01-23 10:45:10 -070038 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 Perritt6f8eda92015-01-27 11:38:35 -070057 th.CheckEquals(t, 1, count)
Jon Perritt45a1d4f2015-01-23 10:45:10 -070058}
59
60func 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}