Jamie Hannaford | 17d2f87 | 2014-11-24 12:20:33 +0100 | [diff] [blame] | 1 | package defsecrules |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups" |
| 7 | "github.com/rackspace/gophercloud/pagination" |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func TestList(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | |
| 16 | mockListRulesResponse(t) |
| 17 | |
| 18 | count := 0 |
| 19 | |
| 20 | err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { |
| 21 | count++ |
| 22 | actual, err := ExtractDefaultRules(page) |
| 23 | th.AssertNoErr(t, err) |
| 24 | |
| 25 | expected := []DefaultRule{ |
| 26 | DefaultRule{ |
| 27 | FromPort: 80, |
| 28 | ID: "f9a97fcf-3a97-47b0-b76f-919136afb7ed", |
| 29 | IPProtocol: "TCP", |
| 30 | IPRange: secgroups.IPRange{CIDR: "10.10.10.0/24"}, |
| 31 | ToPort: 80, |
| 32 | }, |
| 33 | } |
| 34 | |
| 35 | th.CheckDeepEquals(t, expected, actual) |
| 36 | |
| 37 | return true, nil |
| 38 | }) |
| 39 | |
| 40 | th.AssertNoErr(t, err) |
| 41 | th.AssertEquals(t, 1, count) |
| 42 | } |
Jamie Hannaford | 43fa4a2 | 2014-11-24 12:49:17 +0100 | [diff] [blame^] | 43 | |
| 44 | func TestCreate(t *testing.T) { |
| 45 | th.SetupHTTP() |
| 46 | defer th.TeardownHTTP() |
| 47 | |
| 48 | mockCreateRuleResponse(t) |
| 49 | |
| 50 | opts := CreateOpts{ |
| 51 | IPProtocol: "TCP", |
| 52 | FromPort: 80, |
| 53 | ToPort: 80, |
| 54 | CIDR: "10.10.12.0/24", |
| 55 | } |
| 56 | |
| 57 | group, err := Create(client.ServiceClient(), opts).Extract() |
| 58 | th.AssertNoErr(t, err) |
| 59 | |
| 60 | expected := &DefaultRule{ |
| 61 | ID: "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5", |
| 62 | FromPort: 80, |
| 63 | ToPort: 80, |
| 64 | IPProtocol: "TCP", |
| 65 | IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"}, |
| 66 | } |
| 67 | th.AssertDeepEquals(t, expected, group) |
| 68 | } |