blob: 0aeda00b4db22955bec6b7913982ac4569250222 [file] [log] [blame]
Jon Perrittfbcb0ba2015-01-20 19:53:01 -07001package flavors
2
3import (
Jon Perrittd3416092015-03-27 10:36:34 -06004 "testing"
Jon Perrittfbcb0ba2015-01-20 19:53:01 -07005
Jon Perritt27249f42016-02-18 10:35:59 -06006 "github.com/gophercloud/gophercloud"
7 "github.com/gophercloud/gophercloud/pagination"
8 th "github.com/gophercloud/gophercloud/testhelper"
9 fake "github.com/gophercloud/gophercloud/testhelper/client"
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070010)
11
12func TestList(t *testing.T) {
Jon Perrittd3416092015-03-27 10:36:34 -060013 th.SetupHTTP()
14 defer th.TeardownHTTP()
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070015
Jon Perrittd3416092015-03-27 10:36:34 -060016 HandleListCDNFlavorsSuccessfully(t)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070017
Jon Perrittd3416092015-03-27 10:36:34 -060018 count := 0
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070019
Jon Perrittd3416092015-03-27 10:36:34 -060020 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 }
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070027
Jon Perrittd3416092015-03-27 10:36:34 -060028 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 }
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070050
Jon Perrittd3416092015-03-27 10:36:34 -060051 th.CheckDeepEquals(t, expected, actual)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070052
Jon Perrittd3416092015-03-27 10:36:34 -060053 return true, nil
54 })
55 th.AssertNoErr(t, err)
56 th.CheckEquals(t, 1, count)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070057}
58
59func TestGet(t *testing.T) {
Jon Perrittd3416092015-03-27 10:36:34 -060060 th.SetupHTTP()
61 defer th.TeardownHTTP()
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070062
Jon Perrittd3416092015-03-27 10:36:34 -060063 HandleGetCDNFlavorSuccessfully(t)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070064
Jon Perrittd3416092015-03-27 10:36:34 -060065 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 }
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070085
Jon Perrittd3416092015-03-27 10:36:34 -060086 actual, err := Get(fake.ServiceClient(), "asia").Extract()
87 th.AssertNoErr(t, err)
88 th.AssertDeepEquals(t, expected, actual)
Jon Perrittfbcb0ba2015-01-20 19:53:01 -070089}