Debian Codegraph @

fastly/acl_entry_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package fastly
2
3 import "testing"
4
5 func TestClient_ACLEntries(t *testing.T) {
6
7 fixtureBase := "acl_entries/"
8 nameSuffix := "ACLEntries"
9
10 testService := createTestService(t, fixtureBase+"create_service", nameSuffix)
11 defer deleteTestService(t, fixtureBase+"delete_service", testService.ID)
12
13 testVersion := createTestVersion(t, fixtureBase+"version", testService.ID)
14
15 testACL := createTestACL(t, fixtureBase+"acl", testService.ID, testVersion.Number, nameSuffix)
16 defer deleteTestACL(t, testACL, fixtureBase+"delete_acl")
17
18 // Create
19 var err error
20 var e *ACLEntry
21 record(t, fixtureBase+"create", func(c *Client) {
22 e, err = c.CreateACLEntry(&CreateACLEntryInput{
23 Service: testService.ID,
24 ACL: testACL.ID,
25 IP: "10.0.0.3",
26 Subnet: "8",
27 Negated: false,
28 Comment: "test entry",
29 })
30 })
31 if err != nil {
32 t.Fatal(err)
33 }
34
35 if e.IP != "10.0.0.3" {
36 t.Errorf("bad IP: %q", e.IP)
37 }
38
39 if e.Subnet != "8" {
40 t.Errorf("Bad subnet: %q", e.Subnet)
41 }
42
43 if e.Negated != false {
44 t.Errorf("Bad negated flag: %t", e.Negated)
45 }
46
47 if e.Comment != "test entry" {
48 t.Errorf("Bad comment: %q", e.Comment)
49 }
50
51 // List
52 var es []*ACLEntry
53 record(t, fixtureBase+"list", func(c *Client) {
54 es, err = c.ListACLEntries(&ListACLEntriesInput{
55 Service: testService.ID,
56 ACL: testACL.ID,
57 })
58 })
59 if err != nil {
60 t.Fatal(err)
61 }
62
63 if len(es) != 1 {
64 t.Errorf("Bad entries: %v", es)
65 }
66
67 // Get
68 var ne *ACLEntry
69 record(t, fixtureBase+"get", func(c *Client) {
70 ne, err = c.GetACLEntry(&GetACLEntryInput{
71 Service: testService.ID,
72 ACL: testACL.ID,
73 ID: e.ID,
74 })
75 })
76
77 if e.IP != ne.IP {
78 t.Errorf("bad IP: %v", ne.IP)
79 }
80
81 if e.Subnet != ne.Subnet {
82 t.Errorf("bad subnet: %v", ne.Subnet)
83 }
84
85 if e.Negated != ne.Negated {
86 t.Errorf("bad Negated flag: %v", ne.Negated)
87 }
88
89 if e.Comment != ne.Comment {
90 t.Errorf("bad comment: %v", ne.Comment)
91 }
92
93 // Update
94 var ue *ACLEntry
95 record(t, fixtureBase+"update", func(c *Client) {
96 ue, err = c.UpdateACLEntry(&UpdateACLEntryInput{
97 Service: testService.ID,
98 ACL: testACL.ID,
99 ID: e.ID,
100 IP: "10.0.0.4",
101 Negated: true,
102 })
103 })
104 if err != nil {
105 t.Fatal(err)
106 }
107
108 if ue.IP != "10.0.0.4" {
109 t.Errorf("bad IP: %q", ue.IP)
110 }
111 if e.Subnet != ue.Subnet {
112 t.Errorf("bad subnet: %v", ne.Subnet)
113 }
114
115 if ue.Negated != true {
116 t.Errorf("bad Negated flag: %v", ne.Negated)
117 }
118
119 if e.Comment != ue.Comment {
120 t.Errorf("bad comment: %v", ne.Comment)
121 }
122
123 // Delete
124 record(t, fixtureBase+"delete", func(c *Client) {
125 err = c.DeleteACLEntry(&DeleteACLEntryInput{
126 Service: testService.ID,
127 ACL: testACL.ID,
128 ID: e.ID,
129 })
130 })
131 if err != nil {
132 t.Fatal(err)
133 }
134
135 }
136
137 func TestClient_ListACLEntries_validation(t *testing.T) {
138 var err error
139 _, err = testClient.ListACLEntries(&ListACLEntriesInput{
140 Service: "",
141 })
142 if err != ErrMissingService {
143 t.Errorf("bad error: %s", err)
144 }
145
146 _, err = testClient.ListACLEntries(&ListACLEntriesInput{
147 Service: "foo",
148 ACL: "",
149 })
150 if err != ErrMissingACL {
151 t.Errorf("bad error: %s", err)
152 }
153 }
154
155 func TestClient_CreateACLEntry_validation(t *testing.T) {
156 var err error
157 _, err = testClient.CreateACLEntry(&CreateACLEntryInput{
158 Service: "",
159 })
160 if err != ErrMissingService {
161 t.Errorf("bad error: %s", err)
162 }
163
164 _, err = testClient.CreateACLEntry(&CreateACLEntryInput{
165 Service: "foo",
166 ACL: "",
167 })
168 if err != ErrMissingACL {
169 t.Errorf("bad error: %s", err)
170 }
171 }
172
173 func TestClient_GetACLEntry_validation(t *testing.T) {
174 var err error
175 _, err = testClient.GetACLEntry(&GetACLEntryInput{
176 Service: "",
177 })
178 if err != ErrMissingService {
179 t.Errorf("bad error: %s", err)
180 }
181
182 _, err = testClient.GetACLEntry(&GetACLEntryInput{
183 Service: "foo",
184 ACL: "",
185 })
186 if err != ErrMissingACL {
187 t.Errorf("bad error: %s", err)
188 }
189
190 _, err = testClient.GetACLEntry(&GetACLEntryInput{
191 Service: "foo",
192 ACL: "acl",
193 ID: "",
194 })
195 if err != ErrMissingID {
196 t.Errorf("bad error: %s", err)
197 }
198 }
199
200 func TestClient_UpdateACLEntry_validation(t *testing.T) {
201 var err error
202 _, err = testClient.UpdateACLEntry(&UpdateACLEntryInput{
203 Service: "",
204 })
205 if err != ErrMissingService {
206 t.Errorf("bad error: %s", err)
207 }
208
209 _, err = testClient.UpdateACLEntry(&UpdateACLEntryInput{
210 Service: "foo",
211 ACL: "",
212 })
213 if err != ErrMissingACL {
214 t.Errorf("bad error: %s", err)
215 }
216
217 _, err = testClient.UpdateACLEntry(&UpdateACLEntryInput{
218 Service: "foo",
219 ACL: "acl",
220 ID: "",
221 })
222 if err != ErrMissingID {
223 t.Errorf("bad error: %s", err)
224 }
225 }
226
227 func TestClient_DeleteACLEntry_validation(t *testing.T) {
228 var err error
229 err = testClient.DeleteACLEntry(&DeleteACLEntryInput{
230 Service: "",
231 })
232 if err != ErrMissingService {
233 t.Errorf("bad error: %s", err)
234 }
235
236 err = testClient.DeleteACLEntry(&DeleteACLEntryInput{
237 Service: "foo",
238 ACL: "",
239 })
240 if err != ErrMissingACL {
241 t.Errorf("bad error: %s", err)
242 }
243
244 err = testClient.DeleteACLEntry(&DeleteACLEntryInput{
245 Service: "foo",
246 ACL: "acl",
247 ID: "",
248 })
249 if err != ErrMissingID {
250 t.Errorf("bad error: %s", err)
251 }
252 }
253
254 func TestClient_BatchModifyACLEntries_validation(t *testing.T) {
255 var err error
256 err = testClient.BatchModifyACLEntries(&BatchModifyACLEntriesInput{
257 Service: "",
258 })
259 if err != ErrMissingService {
260 t.Errorf("bad error: %s", err)
261 }
262 err = testClient.BatchModifyACLEntries(&BatchModifyACLEntriesInput{
263 Service: "foo",
264 ACL: "",
265 })
266 if err != ErrMissingACL {
267 t.Errorf("bad error: %s", err)
268 }
269
270 oversizedACLEntries := make([]*BatchACLEntry, BatchModifyMaximumOperations+1)
271 err = testClient.BatchModifyACLEntries(&BatchModifyACLEntriesInput{
272 Service: "foo",
273 ACL: "bar",
274 Entries: oversizedACLEntries,
275 })
276 if err != ErrBatchUpdateMaximumOperationsExceeded {
277 t.Errorf("bad error: %s", err)
278 }
279
280 }