Jamie Hannaford | 924c09d | 2014-11-19 12:05:38 +0100 | [diff] [blame^] | 1 | package secgroups |
| 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 | |
| 15 | mockListGroupsResponse(t) |
| 16 | |
| 17 | count := 0 |
| 18 | |
| 19 | err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 20 | count++ |
| 21 | actual, err := ExtractSecurityGroups(page) |
| 22 | if err != nil { |
| 23 | t.Errorf("Failed to extract users: %v", err) |
| 24 | return false, err |
| 25 | } |
| 26 | |
| 27 | expected := []SecurityGroup{ |
| 28 | SecurityGroup{ |
| 29 | ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5", |
| 30 | Description: "default", |
| 31 | Name: "default", |
| 32 | Rules: []Rule{}, |
| 33 | TenantID: "openstack", |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | th.CheckDeepEquals(t, expected, actual) |
| 38 | |
| 39 | return true, nil |
| 40 | }) |
| 41 | |
| 42 | th.AssertNoErr(t, err) |
| 43 | th.AssertEquals(t, 1, count) |
| 44 | } |