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 | } |
Jamie Hannaford | a493e64 | 2014-11-19 12:40:30 +0100 | [diff] [blame^] | 45 | |
| 46 | func TestCreate(t *testing.T) { |
| 47 | th.SetupHTTP() |
| 48 | defer th.TeardownHTTP() |
| 49 | |
| 50 | mockCreateGroupResponse(t) |
| 51 | |
| 52 | opts := CreateOpts{ |
| 53 | Name: "test", |
| 54 | Description: "something", |
| 55 | } |
| 56 | |
| 57 | group, err := Create(client.ServiceClient(), opts).Extract() |
| 58 | th.AssertNoErr(t, err) |
| 59 | |
| 60 | expected := &SecurityGroup{ |
| 61 | ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5", |
| 62 | Name: "test", |
| 63 | Description: "something", |
| 64 | TenantID: "openstack", |
| 65 | Rules: []Rule{}, |
| 66 | } |
| 67 | th.AssertDeepEquals(t, expected, group) |
| 68 | } |