Brad Ison | 53e997c | 2016-03-26 18:02:05 -0400 | [diff] [blame^] | 1 | package policies |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/pagination" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | "github.com/rackspace/gophercloud/testhelper/client" |
| 9 | ) |
| 10 | |
| 11 | func TestList(t *testing.T) { |
| 12 | th.SetupHTTP() |
| 13 | defer th.TeardownHTTP() |
| 14 | HandlePolicyListSuccessfully(t) |
| 15 | |
| 16 | pages := 0 |
| 17 | pager := List(client.ServiceClient(), "10eb3219-1b12-4b34-b1e4-e10ee4f24c65") |
| 18 | |
| 19 | err := pager.EachPage(func(page pagination.Page) (bool, error) { |
| 20 | pages++ |
| 21 | |
| 22 | policies, err := ExtractPolicies(page) |
| 23 | |
| 24 | if err != nil { |
| 25 | return false, err |
| 26 | } |
| 27 | |
| 28 | if len(policies) != 3 { |
| 29 | t.Fatalf("Expected 3 policies, got %d", len(policies)) |
| 30 | } |
| 31 | |
| 32 | th.CheckDeepEquals(t, WebhookPolicy, policies[0]) |
| 33 | th.CheckDeepEquals(t, OneTimePolicy, policies[1]) |
| 34 | th.CheckDeepEquals(t, SundayAfternoonPolicy, policies[2]) |
| 35 | |
| 36 | return true, nil |
| 37 | }) |
| 38 | |
| 39 | th.AssertNoErr(t, err) |
| 40 | |
| 41 | if pages != 1 { |
| 42 | t.Errorf("Expected 1 page, saw %d", pages) |
| 43 | } |
| 44 | } |