blob: c4961a3dd8f780211307ce7033f1997dab823130 [file] [log] [blame]
Jamie Hannaford339394c2014-11-04 16:16:21 +01001package acl
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +01002
3import (
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
11const (
Jamie Hannaford43543b22014-11-04 16:47:40 +010012 lbID = 12345
13 itemID1 = 67890
14 itemID2 = 67891
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010015)
16
17func 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
46func 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
61func TestBulkDelete(t *testing.T) {
62 th.SetupHTTP()
63 defer th.TeardownHTTP()
64
Jamie Hannaford43543b22014-11-04 16:47:40 +010065 ids := []int{itemID1, itemID2}
Jamie Hannafordf84f5fc2014-11-04 16:45:28 +010066
67 mockBatchDeleteResponse(t, lbID, ids)
68
69 err := BulkDelete(client.ServiceClient(), lbID, ids).ExtractErr()
70 th.AssertNoErr(t, err)
71}
Jamie Hannaford43543b22014-11-04 16:47:40 +010072
73func 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 Hannafordef2d9e12014-11-04 16:48:52 +010082
83func 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}