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