Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 1 | package flavors |
| 2 | |
| 3 | import ( |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 4 | "testing" |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 5 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame^] | 6 | "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 Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 10 | ) |
| 11 | |
| 12 | func TestList(t *testing.T) { |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 15 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 16 | HandleListCDNFlavorsSuccessfully(t) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 17 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 18 | count := 0 |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 19 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 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 | } |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 27 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 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 | } |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 50 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 51 | th.CheckDeepEquals(t, expected, actual) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 52 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 53 | return true, nil |
| 54 | }) |
| 55 | th.AssertNoErr(t, err) |
| 56 | th.CheckEquals(t, 1, count) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | func TestGet(t *testing.T) { |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 60 | th.SetupHTTP() |
| 61 | defer th.TeardownHTTP() |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 62 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 63 | HandleGetCDNFlavorSuccessfully(t) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 64 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 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 | } |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 85 | |
Jon Perritt | d341609 | 2015-03-27 10:36:34 -0600 | [diff] [blame] | 86 | actual, err := Get(fake.ServiceClient(), "asia").Extract() |
| 87 | th.AssertNoErr(t, err) |
| 88 | th.AssertDeepEquals(t, expected, actual) |
Jon Perritt | fbcb0ba | 2015-01-20 19:53:01 -0700 | [diff] [blame] | 89 | } |