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