Jamie Hannaford | 339394c | 2014-11-04 16:16:21 +0100 | [diff] [blame] | 1 | package acl |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 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 | const ( |
Jamie Hannaford | 43543b2 | 2014-11-04 16:47:40 +0100 | [diff] [blame] | 12 | lbID = 12345 |
| 13 | itemID1 = 67890 |
| 14 | itemID2 = 67891 |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 15 | ) |
| 16 | |
| 17 | func TestList(t *testing.T) { |
| 18 | th.SetupHTTP() |
| 19 | defer th.TeardownHTTP() |
| 20 | |
| 21 | mockListResponse(t, lbID) |
| 22 | |
| 23 | count := 0 |
| 24 | |
| 25 | err := List(client.ServiceClient(), lbID).EachPage(func(page pagination.Page) (bool, error) { |
| 26 | count++ |
| 27 | actual, err := ExtractAccessList(page) |
| 28 | th.AssertNoErr(t, err) |
| 29 | |
| 30 | expected := AccessList{ |
| 31 | NetworkItem{Address: "206.160.163.21", ID: 21, Type: DENY}, |
| 32 | NetworkItem{Address: "206.160.163.22", ID: 22, Type: DENY}, |
| 33 | NetworkItem{Address: "206.160.163.23", ID: 23, Type: DENY}, |
| 34 | NetworkItem{Address: "206.160.163.24", ID: 24, Type: DENY}, |
| 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 | } |
| 45 | |
| 46 | func TestCreate(t *testing.T) { |
| 47 | th.SetupHTTP() |
| 48 | defer th.TeardownHTTP() |
| 49 | |
| 50 | mockCreateResponse(t, lbID) |
| 51 | |
| 52 | opts := CreateOpts{ |
| 53 | CreateOpt{Address: "206.160.163.21", Type: DENY}, |
| 54 | CreateOpt{Address: "206.160.165.11", Type: DENY}, |
| 55 | } |
| 56 | |
| 57 | err := Create(client.ServiceClient(), lbID, opts).ExtractErr() |
| 58 | th.AssertNoErr(t, err) |
| 59 | } |
| 60 | |
| 61 | func TestBulkDelete(t *testing.T) { |
| 62 | th.SetupHTTP() |
| 63 | defer th.TeardownHTTP() |
| 64 | |
Jamie Hannaford | 43543b2 | 2014-11-04 16:47:40 +0100 | [diff] [blame] | 65 | ids := []int{itemID1, itemID2} |
Jamie Hannaford | f84f5fc | 2014-11-04 16:45:28 +0100 | [diff] [blame] | 66 | |
| 67 | mockBatchDeleteResponse(t, lbID, ids) |
| 68 | |
| 69 | err := BulkDelete(client.ServiceClient(), lbID, ids).ExtractErr() |
| 70 | th.AssertNoErr(t, err) |
| 71 | } |
Jamie Hannaford | 43543b2 | 2014-11-04 16:47:40 +0100 | [diff] [blame] | 72 | |
| 73 | func TestDelete(t *testing.T) { |
| 74 | th.SetupHTTP() |
| 75 | defer th.TeardownHTTP() |
| 76 | |
| 77 | mockDeleteResponse(t, lbID, itemID1) |
| 78 | |
| 79 | err := Delete(client.ServiceClient(), lbID, itemID1).ExtractErr() |
| 80 | th.AssertNoErr(t, err) |
| 81 | } |
Jamie Hannaford | ef2d9e1 | 2014-11-04 16:48:52 +0100 | [diff] [blame] | 82 | |
| 83 | func TestDeleteAll(t *testing.T) { |
| 84 | th.SetupHTTP() |
| 85 | defer th.TeardownHTTP() |
| 86 | |
| 87 | mockDeleteAllResponse(t, lbID) |
| 88 | |
| 89 | err := DeleteAll(client.ServiceClient(), lbID).ExtractErr() |
| 90 | th.AssertNoErr(t, err) |
| 91 | } |