Brad Ison | 366a7a0 | 2016-03-27 17:06:21 -0400 | [diff] [blame^] | 1 | package webhooks |
| 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 | HandleWebhookListSuccessfully(t) |
| 15 | |
| 16 | groupID := "10eb3219-1b12-4b34-b1e4-e10ee4f24c65" |
| 17 | policyID := "2b48d247-0282-4b9d-8775-5c4b67e8e649" |
| 18 | |
| 19 | pages := 0 |
| 20 | pager := List(client.ServiceClient(), groupID, policyID) |
| 21 | |
| 22 | err := pager.EachPage(func(page pagination.Page) (bool, error) { |
| 23 | pages++ |
| 24 | |
| 25 | webhooks, err := ExtractWebhooks(page) |
| 26 | |
| 27 | if err != nil { |
| 28 | return false, err |
| 29 | } |
| 30 | |
| 31 | if len(webhooks) != 2 { |
| 32 | t.Fatalf("Expected 2 policies, got %d", len(webhooks)) |
| 33 | } |
| 34 | |
| 35 | th.CheckDeepEquals(t, FirstWebhook, webhooks[0]) |
| 36 | th.CheckDeepEquals(t, SecondWebhook, webhooks[1]) |
| 37 | |
| 38 | return true, nil |
| 39 | }) |
| 40 | |
| 41 | th.AssertNoErr(t, err) |
| 42 | |
| 43 | if pages != 1 { |
| 44 | t.Errorf("Expected 1 page, saw %d", pages) |
| 45 | } |
| 46 | } |