Merge lp:~julian-edwards/gwacl/storage-test-helper into lp:gwacl
- storage-test-helper
- Merge into trunk
Proposed by
Julian Edwards
Status: | Merged |
---|---|
Approved by: | Julian Edwards |
Approved revision: | 116 |
Merged at revision: | 115 |
Proposed branch: | lp:~julian-edwards/gwacl/storage-test-helper |
Merge into: | lp:gwacl |
Diff against target: |
691 lines (+76/-144) 3 files modified
helpers_http_test.go (+13/-0) storage_base_test.go (+51/-116) storage_test.go (+12/-28) |
To merge this branch: | bzr merge lp:~julian-edwards/gwacl/storage-test-helper |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Julian Edwards (community) | Approve | ||
Review via email: mp+170482@code.launchpad.net |
Commit message
Refactor the makeStorageContext helper to reduce a lot of boilerplate in test code
Description of the change
Refactor the makeStorageContext helper some more which reduces a lot of boilerplate in test code:
helpers_
storage_
storage_test.go | 40 +++---------
3 files changed, 76 insertions(+), 144 deletions(-)
It also now takes http.RoundTripper as a parameter rather than TestTransport, so the TestTransport2 can also be used. We should really rename those, BTW, but not here.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'helpers_http_test.go' |
2 | --- helpers_http_test.go 2013-04-30 05:13:33 +0000 |
3 | +++ helpers_http_test.go 2013-06-20 04:26:28 +0000 |
4 | @@ -6,6 +6,7 @@ |
5 | package gwacl |
6 | |
7 | import ( |
8 | + "encoding/base64" |
9 | "fmt" |
10 | "io" |
11 | "io/ioutil" |
12 | @@ -77,3 +78,15 @@ |
13 | func makeResponseBody(content string) io.ReadCloser { |
14 | return ioutil.NopCloser(strings.NewReader(content)) |
15 | } |
16 | + |
17 | +// Convenience factory to create a StorageContext with a random name and |
18 | +// random base64-encoded key. |
19 | +func makeStorageContext(transport http.RoundTripper) *StorageContext { |
20 | + context := &StorageContext{ |
21 | + Account: MakeRandomString(10), |
22 | + Key: base64.StdEncoding.EncodeToString(MakeRandomByteSlice(10)), |
23 | + } |
24 | + context.client = &http.Client{Transport: transport} |
25 | + return context |
26 | +} |
27 | + |
28 | |
29 | === modified file 'storage_base_test.go' |
30 | --- storage_base_test.go 2013-06-19 06:41:44 +0000 |
31 | +++ storage_base_test.go 2013-06-20 04:26:28 +0000 |
32 | @@ -294,15 +294,6 @@ |
33 | c.Assert(context.getClient(), Equals, context.client) |
34 | } |
35 | |
36 | -// Convenience factory to create a StorageContext with a random name and |
37 | -// random base64-encoded key. |
38 | -func makeStorageContext() *StorageContext { |
39 | - return &StorageContext{ |
40 | - Account: MakeRandomString(10), |
41 | - Key: base64.StdEncoding.EncodeToString(MakeRandomByteSlice(10)), |
42 | - } |
43 | -} |
44 | - |
45 | type TestListContainers struct{} |
46 | |
47 | var _ = Suite(&TestListContainers{}) |
48 | @@ -334,14 +325,13 @@ |
49 | </Containers> |
50 | <NextMarker/> |
51 | </EnumerationResults>` |
52 | - context := makeStorageContext() |
53 | response := &http.Response{ |
54 | Status: fmt.Sprintf("%d", http.StatusOK), |
55 | StatusCode: http.StatusOK, |
56 | Body: makeResponseBody(response_body), |
57 | } |
58 | transport := &TestTransport{Response: response} |
59 | - context.client = &http.Client{Transport: transport} |
60 | + context := makeStorageContext(transport) |
61 | request := &ListContainersRequest{Marker: ""} |
62 | results, err := context.ListContainers(request) |
63 | c.Assert(err, IsNil) |
64 | @@ -355,9 +345,7 @@ |
65 | // Client-side errors from the HTTP client are propagated back to the caller. |
66 | func (suite *TestListContainers) TestError(c *C) { |
67 | error := fmt.Errorf("canned-error") |
68 | - transport := &TestTransport{Error: error} |
69 | - context := makeStorageContext() |
70 | - context.client = &http.Client{Transport: transport} |
71 | + context := makeStorageContext(&TestTransport{Error: error}) |
72 | request := &ListContainersRequest{Marker: ""} |
73 | _, err := context.ListContainers(request) |
74 | c.Assert(err, NotNil) |
75 | @@ -369,19 +357,16 @@ |
76 | Status: fmt.Sprintf("%d", http.StatusNotFound), |
77 | StatusCode: http.StatusNotFound, |
78 | } |
79 | - transport := &TestTransport{Response: response} |
80 | - context := makeStorageContext() |
81 | - context.client = &http.Client{Transport: transport} |
82 | + context := makeStorageContext(&TestTransport{Response: response}) |
83 | request := &ListContainersRequest{Marker: ""} |
84 | _, err := context.ListContainers(request) |
85 | c.Assert(err, NotNil) |
86 | } |
87 | |
88 | func (suite *TestListContainers) TestListContainersBatchPassesMarker(c *C) { |
89 | - transport := TestTransport2{} |
90 | + transport := &TestTransport2{} |
91 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
92 | - context := makeStorageContext() |
93 | - context.client = &http.Client{Transport: &transport} |
94 | + context := makeStorageContext(transport) |
95 | |
96 | // Call ListContainers. This will fail because of the empty |
97 | // response, but no matter. We only care about the request. |
98 | @@ -397,10 +382,9 @@ |
99 | } |
100 | |
101 | func (suite *TestListContainers) TestListContainersBatchDoesNotPassEmptyMarker(c *C) { |
102 | - transport := TestTransport2{} |
103 | + transport := &TestTransport2{} |
104 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
105 | - context := makeStorageContext() |
106 | - context.client = &http.Client{Transport: &transport} |
107 | + context := makeStorageContext(transport) |
108 | |
109 | // The error is OK. We only care about the request. |
110 | request := &ListContainersRequest{Marker: ""} |
111 | @@ -417,10 +401,9 @@ |
112 | } |
113 | |
114 | func (suite *TestListContainers) TestListContainersBatchEscapesMarker(c *C) { |
115 | - transport := TestTransport2{} |
116 | + transport := &TestTransport2{} |
117 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
118 | - context := makeStorageContext() |
119 | - context.client = &http.Client{Transport: &transport} |
120 | + context := makeStorageContext(transport) |
121 | |
122 | // The error is OK. We only care about the request. |
123 | request := &ListContainersRequest{Marker: "x&y"} |
124 | @@ -485,14 +468,14 @@ |
125 | </Blobs> |
126 | <NextMarker /> |
127 | </EnumerationResults>` |
128 | - context := makeStorageContext() |
129 | response := &http.Response{ |
130 | Status: fmt.Sprintf("%d", http.StatusOK), |
131 | StatusCode: http.StatusOK, |
132 | Body: makeResponseBody(response_body), |
133 | } |
134 | transport := &TestTransport{Response: response} |
135 | - context.client = &http.Client{Transport: transport} |
136 | + context := makeStorageContext(transport) |
137 | + |
138 | request := &ListBlobsRequest{Container: "container"} |
139 | results, err := context.ListBlobs(request) |
140 | c.Assert(err, IsNil) |
141 | @@ -508,9 +491,8 @@ |
142 | // Client-side errors from the HTTP client are propagated back to the caller. |
143 | func (suite *TestListBlobs) TestError(c *C) { |
144 | error := fmt.Errorf("canned-error") |
145 | - transport := &TestTransport{Error: error} |
146 | - context := makeStorageContext() |
147 | - context.client = &http.Client{Transport: transport} |
148 | + context := makeStorageContext(&TestTransport{Error: error}) |
149 | + |
150 | request := &ListBlobsRequest{Container: "container"} |
151 | _, err := context.ListBlobs(request) |
152 | c.Assert(err, NotNil) |
153 | @@ -522,19 +504,17 @@ |
154 | Status: fmt.Sprintf("%d", http.StatusNotFound), |
155 | StatusCode: http.StatusNotFound, |
156 | } |
157 | - transport := &TestTransport{Response: response} |
158 | - context := makeStorageContext() |
159 | - context.client = &http.Client{Transport: transport} |
160 | + context := makeStorageContext(&TestTransport{Response: response}) |
161 | + |
162 | request := &ListBlobsRequest{Container: "container"} |
163 | _, err := context.ListBlobs(request) |
164 | c.Assert(err, NotNil) |
165 | } |
166 | |
167 | func (suite *TestListBlobs) TestListBlobsPassesMarker(c *C) { |
168 | - transport := TestTransport2{} |
169 | + transport := &TestTransport2{} |
170 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
171 | - context := makeStorageContext() |
172 | - context.client = &http.Client{Transport: &transport} |
173 | + context := makeStorageContext(transport) |
174 | |
175 | // Call ListBlobs. This will fail because of the empty |
176 | // response, but no matter. We only care about the request. |
177 | @@ -550,10 +530,9 @@ |
178 | } |
179 | |
180 | func (suite *TestListBlobs) TestListBlobsDoesNotPassEmptyMarker(c *C) { |
181 | - transport := TestTransport2{} |
182 | + transport := &TestTransport2{} |
183 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
184 | - context := makeStorageContext() |
185 | - context.client = &http.Client{Transport: &transport} |
186 | + context := makeStorageContext(transport) |
187 | |
188 | // The error is OK. We only care about the request. |
189 | request := &ListBlobsRequest{Container: "mycontainer"} |
190 | @@ -570,10 +549,9 @@ |
191 | } |
192 | |
193 | func (suite *TestListBlobs) TestListBlobsPassesPrefix(c *C) { |
194 | - transport := TestTransport2{} |
195 | + transport := &TestTransport2{} |
196 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
197 | - context := makeStorageContext() |
198 | - context.client = &http.Client{Transport: &transport} |
199 | + context := makeStorageContext(transport) |
200 | |
201 | // Call ListBlobs. This will fail because of the empty |
202 | // response, but no matter. We only care about the request. |
203 | @@ -589,10 +567,9 @@ |
204 | } |
205 | |
206 | func (suite *TestListBlobs) TestListBlobsDoesNotPassEmptyPrefix(c *C) { |
207 | - transport := TestTransport2{} |
208 | + transport := &TestTransport2{} |
209 | transport.AddExchange(&http.Response{StatusCode: http.StatusOK, Body: Empty}, nil) |
210 | - context := makeStorageContext() |
211 | - context.client = &http.Client{Transport: &transport} |
212 | + context := makeStorageContext(transport) |
213 | |
214 | // The error is OK. We only care about the request. |
215 | request := &ListBlobsRequest{Container: "mycontainer"} |
216 | @@ -615,13 +592,12 @@ |
217 | // The CreateContainer Storage API call returns without error when the |
218 | // container has been created successfully. |
219 | func (suite *TestCreateContainer) Test(c *C) { |
220 | - context := makeStorageContext() |
221 | response := &http.Response{ |
222 | Status: fmt.Sprintf("%d", http.StatusCreated), |
223 | StatusCode: http.StatusCreated, |
224 | } |
225 | transport := &TestTransport{Response: response} |
226 | - context.client = &http.Client{Transport: transport} |
227 | + context := makeStorageContext(transport) |
228 | container_name := MakeRandomString(10) |
229 | err := context.CreateContainer(container_name) |
230 | c.Assert(err, IsNil) |
231 | @@ -634,9 +610,7 @@ |
232 | // Client-side errors from the HTTP client are propagated back to the caller. |
233 | func (suite *TestCreateContainer) TestError(c *C) { |
234 | error := fmt.Errorf("canned-error") |
235 | - transport := &TestTransport{Error: error} |
236 | - context := makeStorageContext() |
237 | - context.client = &http.Client{Transport: transport} |
238 | + context := makeStorageContext(&TestTransport{Error: error}) |
239 | err := context.CreateContainer("container") |
240 | c.Assert(err, NotNil) |
241 | } |
242 | @@ -647,9 +621,7 @@ |
243 | Status: fmt.Sprintf("%d", http.StatusNotFound), |
244 | StatusCode: http.StatusNotFound, |
245 | } |
246 | - transport := &TestTransport{Response: response} |
247 | - context := makeStorageContext() |
248 | - context.client = &http.Client{Transport: transport} |
249 | + context := makeStorageContext(&TestTransport{Response: response}) |
250 | err := context.CreateContainer("container") |
251 | c.Assert(err, NotNil) |
252 | } |
253 | @@ -660,9 +632,7 @@ |
254 | Status: fmt.Sprintf("%d", http.StatusOK), |
255 | StatusCode: http.StatusOK, |
256 | } |
257 | - transport := &TestTransport{Response: response} |
258 | - context := makeStorageContext() |
259 | - context.client = &http.Client{Transport: transport} |
260 | + context := makeStorageContext(&TestTransport{Response: response}) |
261 | err := context.CreateContainer("container") |
262 | c.Assert(err, NotNil) |
263 | } |
264 | @@ -673,13 +643,12 @@ |
265 | |
266 | // Basic happy path testing. |
267 | func (suite *TestPutPage) TestHappyPath(c *C) { |
268 | - context := makeStorageContext() |
269 | response := &http.Response{ |
270 | Status: fmt.Sprintf("%d", http.StatusCreated), |
271 | StatusCode: http.StatusCreated, |
272 | } |
273 | transport := &TestTransport{Response: response} |
274 | - context.client = &http.Client{Transport: transport} |
275 | + context := makeStorageContext(transport) |
276 | randomData := MakeRandomByteSlice(10) |
277 | dataReader := bytes.NewReader(randomData) |
278 | |
279 | @@ -709,9 +678,7 @@ |
280 | // Client-side errors from the HTTP client are propagated back to the caller. |
281 | func (suite *TestPutPage) TestError(c *C) { |
282 | cannedError := fmt.Errorf("canned-error") |
283 | - transport := &TestTransport{Error: cannedError} |
284 | - context := makeStorageContext() |
285 | - context.client = &http.Client{Transport: transport} |
286 | + context := makeStorageContext(&TestTransport{Error: cannedError}) |
287 | err := context.PutPage(&PutPageRequest{ |
288 | Container: "container", Filename: "filename", StartRange: 0, |
289 | EndRange: 512, Data: nil}) |
290 | @@ -725,9 +692,7 @@ |
291 | StatusCode: 102, |
292 | Body: makeResponseBody("<Error><Code>Frotzed</Code><Message>failed to put blob</Message></Error>"), |
293 | } |
294 | - transport := &TestTransport{Response: response} |
295 | - context := makeStorageContext() |
296 | - context.client = &http.Client{Transport: transport} |
297 | + context := makeStorageContext(&TestTransport{Response: response}) |
298 | err := context.PutPage(&PutPageRequest{ |
299 | Container: "container", Filename: "filename", StartRange: 0, |
300 | EndRange: 512, Data: nil}) |
301 | @@ -743,13 +708,13 @@ |
302 | |
303 | // Test basic PutBlob happy path functionality. |
304 | func (suite *TestPutBlob) TestPutBlockBlob(c *C) { |
305 | - context := makeStorageContext() |
306 | response := &http.Response{ |
307 | Status: fmt.Sprintf("%d", http.StatusCreated), |
308 | StatusCode: http.StatusCreated, |
309 | } |
310 | transport := &TestTransport{Response: response} |
311 | - context.client = &http.Client{Transport: transport} |
312 | + context := makeStorageContext(transport) |
313 | + |
314 | err := context.PutBlob(&PutBlobRequest{ |
315 | Container: "container", BlobType: "block", Filename: "blobname"}) |
316 | c.Assert(err, IsNil) |
317 | @@ -763,13 +728,12 @@ |
318 | |
319 | // PutBlob should set x-ms-blob-type to PageBlob for Page Blobs. |
320 | func (suite *TestPutBlob) TestPutPageBlob(c *C) { |
321 | - context := makeStorageContext() |
322 | response := &http.Response{ |
323 | Status: fmt.Sprintf("%d", http.StatusCreated), |
324 | StatusCode: http.StatusCreated, |
325 | } |
326 | transport := &TestTransport{Response: response} |
327 | - context.client = &http.Client{Transport: transport} |
328 | + context := makeStorageContext(transport) |
329 | err := context.PutBlob(&PutBlobRequest{ |
330 | Container: "container", BlobType: "page", Filename: "blobname"}) |
331 | c.Assert(err, IsNil) |
332 | @@ -782,7 +746,7 @@ |
333 | err := recover() |
334 | c.Assert(err, Equals, "block_type must be 'page' or 'block'") |
335 | }() |
336 | - context := makeStorageContext() |
337 | + context := makeStorageContext(&TestTransport{}) |
338 | context.PutBlob(&PutBlobRequest{ |
339 | Container: "container", BlobType: "invalid-blob-type", |
340 | Filename: "blobname"}) |
341 | @@ -792,9 +756,7 @@ |
342 | // Client-side errors from the HTTP client are propagated back to the caller. |
343 | func (suite *TestPutBlob) TestError(c *C) { |
344 | error := fmt.Errorf("canned-error") |
345 | - transport := &TestTransport{Error: error} |
346 | - context := makeStorageContext() |
347 | - context.client = &http.Client{Transport: transport} |
348 | + context := makeStorageContext(&TestTransport{Error: error}) |
349 | err := context.PutBlob(&PutBlobRequest{ |
350 | Container: "container", BlobType: "block", Filename: "blobname"}) |
351 | c.Assert(err, NotNil) |
352 | @@ -807,9 +769,7 @@ |
353 | StatusCode: 102, |
354 | Body: makeResponseBody("<Error><Code>Frotzed</Code><Message>failed to put blob</Message></Error>"), |
355 | } |
356 | - transport := &TestTransport{Response: response} |
357 | - context := makeStorageContext() |
358 | - context.client = &http.Client{Transport: transport} |
359 | + context := makeStorageContext(&TestTransport{Response: response}) |
360 | err := context.PutBlob(&PutBlobRequest{ |
361 | Container: "container", BlobType: "block", Filename: "blobname"}) |
362 | c.Assert(err, NotNil) |
363 | @@ -823,13 +783,12 @@ |
364 | var _ = Suite(&TestPutBlock{}) |
365 | |
366 | func (suite *TestPutBlock) Test(c *C) { |
367 | - context := makeStorageContext() |
368 | response := &http.Response{ |
369 | Status: fmt.Sprintf("%d", http.StatusCreated), |
370 | StatusCode: http.StatusCreated, |
371 | } |
372 | transport := &TestTransport{Response: response} |
373 | - context.client = &http.Client{Transport: transport} |
374 | + context := makeStorageContext(transport) |
375 | blockid := "\x1b\xea\xf7Mv\xb5\xddH\xebm" |
376 | random_data := MakeRandomByteSlice(10) |
377 | data_reader := bytes.NewReader(random_data) |
378 | @@ -853,9 +812,7 @@ |
379 | // Client-side errors from the HTTP client are propagated back to the caller. |
380 | func (suite *TestPutBlock) TestError(c *C) { |
381 | error := fmt.Errorf("canned-error") |
382 | - transport := &TestTransport{Error: error} |
383 | - context := makeStorageContext() |
384 | - context.client = &http.Client{Transport: transport} |
385 | + context := makeStorageContext(&TestTransport{Error: error}) |
386 | data_reader := bytes.NewReader(MakeRandomByteSlice(10)) |
387 | err := context.PutBlock("container", "blobname", "blockid", data_reader) |
388 | c.Assert(err, NotNil) |
389 | @@ -868,9 +825,7 @@ |
390 | StatusCode: 102, |
391 | Body: makeResponseBody("<Error><Code>Frotzed</Code><Message>failed to put block</Message></Error>"), |
392 | } |
393 | - transport := &TestTransport{Response: response} |
394 | - context := makeStorageContext() |
395 | - context.client = &http.Client{Transport: transport} |
396 | + context := makeStorageContext(&TestTransport{Response: response}) |
397 | data_reader := bytes.NewReader(MakeRandomByteSlice(10)) |
398 | err := context.PutBlock("container", "blobname", "blockid", data_reader) |
399 | c.Assert(err, NotNil) |
400 | @@ -884,13 +839,12 @@ |
401 | var _ = Suite(&TestPutBlockList{}) |
402 | |
403 | func (suite *TestPutBlockList) Test(c *C) { |
404 | - context := makeStorageContext() |
405 | response := &http.Response{ |
406 | Status: fmt.Sprintf("%d", http.StatusCreated), |
407 | StatusCode: http.StatusCreated, |
408 | } |
409 | transport := &TestTransport{Response: response} |
410 | - context.client = &http.Client{Transport: transport} |
411 | + context := makeStorageContext(transport) |
412 | blocklist := &BlockList{} |
413 | blocklist.Add(BlockListLatest, "b1") |
414 | blocklist.Add(BlockListLatest, "b2") |
415 | @@ -916,9 +870,7 @@ |
416 | // Client-side errors from the HTTP client are propagated back to the caller. |
417 | func (suite *TestPutBlockList) TestError(c *C) { |
418 | error := fmt.Errorf("canned-error") |
419 | - transport := &TestTransport{Error: error} |
420 | - context := makeStorageContext() |
421 | - context.client = &http.Client{Transport: transport} |
422 | + context := makeStorageContext(&TestTransport{Error: error}) |
423 | blocklist := &BlockList{} |
424 | err := context.PutBlockList("container", "blobname", blocklist) |
425 | c.Assert(err, NotNil) |
426 | @@ -931,9 +883,7 @@ |
427 | StatusCode: 102, |
428 | Body: makeResponseBody("<Error><Code>Frotzed</Code><Message>failed to put blocklist</Message></Error>"), |
429 | } |
430 | - transport := &TestTransport{Response: response} |
431 | - context := makeStorageContext() |
432 | - context.client = &http.Client{Transport: transport} |
433 | + context := makeStorageContext(&TestTransport{Response: response}) |
434 | blocklist := &BlockList{} |
435 | err := context.PutBlockList("container", "blobname", blocklist) |
436 | c.Assert(err, NotNil) |
437 | @@ -966,14 +916,13 @@ |
438 | </UncommittedBlocks> |
439 | </BlockList>` |
440 | |
441 | - context := makeStorageContext() |
442 | response := &http.Response{ |
443 | Status: fmt.Sprintf("%d", http.StatusOK), |
444 | StatusCode: http.StatusOK, |
445 | Body: makeResponseBody(response_body), |
446 | } |
447 | transport := &TestTransport{Response: response} |
448 | - context.client = &http.Client{Transport: transport} |
449 | + context := makeStorageContext(transport) |
450 | results, err := context.GetBlockList("container", "myfilename") |
451 | c.Assert(err, IsNil) |
452 | c.Check(transport.Request.URL.String(), Matches, context.getFileURL("container", "myfilename")+"?.*") |
453 | @@ -988,9 +937,7 @@ |
454 | // Client-side errors from the HTTP client are propagated back to the caller. |
455 | func (suite *TestGetBlockList) TestError(c *C) { |
456 | error := fmt.Errorf("canned-error") |
457 | - transport := &TestTransport{Error: error} |
458 | - context := makeStorageContext() |
459 | - context.client = &http.Client{Transport: transport} |
460 | + context := makeStorageContext(&TestTransport{Error: error}) |
461 | _, err := context.GetBlockList("container", "myfilename") |
462 | c.Assert(err, NotNil) |
463 | } |
464 | @@ -1001,9 +948,7 @@ |
465 | Status: fmt.Sprintf("%d", http.StatusNotFound), |
466 | StatusCode: http.StatusNotFound, |
467 | } |
468 | - transport := &TestTransport{Response: response} |
469 | - context := makeStorageContext() |
470 | - context.client = &http.Client{Transport: transport} |
471 | + context := makeStorageContext(&TestTransport{Response: response}) |
472 | _, err := context.GetBlockList("container", "myfilename") |
473 | c.Assert(err, NotNil) |
474 | } |
475 | @@ -1013,13 +958,12 @@ |
476 | var _ = Suite(&TestDeleteBlob{}) |
477 | |
478 | func (suite *TestDeleteBlob) Test(c *C) { |
479 | - context := makeStorageContext() |
480 | response := &http.Response{ |
481 | Status: fmt.Sprintf("%d", http.StatusAccepted), |
482 | StatusCode: http.StatusAccepted, |
483 | } |
484 | transport := &TestTransport{Response: response} |
485 | - context.client = &http.Client{Transport: transport} |
486 | + context := makeStorageContext(transport) |
487 | err := context.DeleteBlob("container", "blobname") |
488 | c.Assert(err, IsNil) |
489 | |
490 | @@ -1032,9 +976,7 @@ |
491 | // Client-side errors from the HTTP client are propagated back to the caller. |
492 | func (suite *TestDeleteBlob) TestError(c *C) { |
493 | error := fmt.Errorf("canned-error") |
494 | - transport := &TestTransport{Error: error} |
495 | - context := makeStorageContext() |
496 | - context.client = &http.Client{Transport: transport} |
497 | + context := makeStorageContext(&TestTransport{Error: error}) |
498 | err := context.DeleteBlob("container", "blobname") |
499 | c.Assert(err, NotNil) |
500 | } |
501 | @@ -1046,9 +988,7 @@ |
502 | StatusCode: 146, |
503 | Body: makeResponseBody("<Error><Code>Frotzed</Code><Message>failed to delete blob</Message></Error>"), |
504 | } |
505 | - transport := &TestTransport{Response: response} |
506 | - context := makeStorageContext() |
507 | - context.client = &http.Client{Transport: transport} |
508 | + context := makeStorageContext(&TestTransport{Response: response}) |
509 | err := context.DeleteBlob("container", "blobname") |
510 | c.Assert(err, NotNil) |
511 | c.Check(err, ErrorMatches, ".*146.*") |
512 | @@ -1061,7 +1001,6 @@ |
513 | var _ = Suite(&TestGetBlob{}) |
514 | |
515 | func (suite *TestGetBlob) Test(c *C) { |
516 | - context := makeStorageContext() |
517 | response_body := "blob-in-a-can" |
518 | response := &http.Response{ |
519 | Status: fmt.Sprintf("%d", http.StatusOK), |
520 | @@ -1069,7 +1008,7 @@ |
521 | Body: makeResponseBody(response_body), |
522 | } |
523 | transport := &TestTransport{Response: response} |
524 | - context.client = &http.Client{Transport: transport} |
525 | + context := makeStorageContext(transport) |
526 | reader, err := context.GetBlob("container", "blobname") |
527 | c.Assert(err, IsNil) |
528 | c.Assert(reader, NotNil) |
529 | @@ -1087,9 +1026,7 @@ |
530 | // Client-side errors from the HTTP client are propagated back to the caller. |
531 | func (suite *TestGetBlob) TestError(c *C) { |
532 | error := fmt.Errorf("canned-error") |
533 | - transport := &TestTransport{Error: error} |
534 | - context := makeStorageContext() |
535 | - context.client = &http.Client{Transport: transport} |
536 | + context := makeStorageContext(&TestTransport{Error: error}) |
537 | reader, err := context.GetBlob("container", "blobname") |
538 | c.Check(reader, IsNil) |
539 | c.Assert(err, NotNil) |
540 | @@ -1102,9 +1039,7 @@ |
541 | StatusCode: 246, |
542 | Body: makeResponseBody("<Error><Code>Frotzed</Code><Message>failed to get blob</Message></Error>"), |
543 | } |
544 | - transport := &TestTransport{Response: response} |
545 | - context := makeStorageContext() |
546 | - context.client = &http.Client{Transport: transport} |
547 | + context := makeStorageContext(&TestTransport{Response: response}) |
548 | reader, err := context.GetBlob("container", "blobname") |
549 | c.Check(reader, IsNil) |
550 | c.Assert(err, NotNil) |
551 | |
552 | === modified file 'storage_test.go' |
553 | --- storage_test.go 2013-06-11 16:31:49 +0000 |
554 | +++ storage_test.go 2013-06-20 04:26:28 +0000 |
555 | @@ -17,14 +17,12 @@ |
556 | var _ = Suite(&testUploadBlockBlob{}) |
557 | |
558 | func (suite *testUploadBlockBlob) TestSmallFile(c *C) { |
559 | - context := makeStorageContext() |
560 | transport := &TestTransport2{} |
561 | + context := makeStorageContext(transport) |
562 | // UploadBlockBlob uses PutBlock to upload the data. |
563 | transport.AddExchange(makeFakeCreatedResponse(), nil) |
564 | // UploadBlockBlob then sends the list of blocks with PutBlockList. |
565 | transport.AddExchange(makeFakeCreatedResponse(), nil) |
566 | - // Plug in the test transport. |
567 | - context.client = &http.Client{Transport: transport} |
568 | // Upload a random blob of data. |
569 | data := uploadRandomBlob(c, context, 10) |
570 | // There were two exchanges. |
571 | @@ -36,15 +34,13 @@ |
572 | } |
573 | |
574 | func (suite *testUploadBlockBlob) TestLargeFile(c *C) { |
575 | - context := makeStorageContext() |
576 | transport := &TestTransport2{} |
577 | + context := makeStorageContext(transport) |
578 | // UploadBlockBlob uses PutBlock twice to upload the data. |
579 | transport.AddExchange(makeFakeCreatedResponse(), nil) |
580 | transport.AddExchange(makeFakeCreatedResponse(), nil) |
581 | // UploadBlockBlob then sends the list of blocks with PutBlockList. |
582 | transport.AddExchange(makeFakeCreatedResponse(), nil) |
583 | - // Plug in the test transport. |
584 | - context.client = &http.Client{Transport: transport} |
585 | // Upload a large random blob of data. |
586 | data := uploadRandomBlob(c, context, 1348*1024) |
587 | // There were three exchanges. |
588 | @@ -143,14 +139,13 @@ |
589 | </Blobs> |
590 | <NextMarker /> |
591 | </EnumerationResults>` |
592 | - context := makeStorageContext() |
593 | response := &http.Response{ |
594 | Status: fmt.Sprintf("%d", http.StatusOK), |
595 | StatusCode: http.StatusOK, |
596 | Body: makeResponseBody(response_body), |
597 | } |
598 | transport := &TestTransport{Response: response} |
599 | - context.client = &http.Client{Transport: transport} |
600 | + context := makeStorageContext(transport) |
601 | request := &ListBlobsRequest{Container: "container"} |
602 | results, err := context.ListAllBlobs(request) |
603 | c.Assert(err, IsNil) |
604 | @@ -166,9 +161,7 @@ |
605 | // Client-side errors from the HTTP client are propagated back to the caller. |
606 | func (suite *testListAllBlobs) TestError(c *C) { |
607 | error := fmt.Errorf("canned-error") |
608 | - transport := &TestTransport{Error: error} |
609 | - context := makeStorageContext() |
610 | - context.client = &http.Client{Transport: transport} |
611 | + context := makeStorageContext(&TestTransport{Error: error}) |
612 | request := &ListBlobsRequest{Container: "container"} |
613 | _, err := context.ListAllBlobs(request) |
614 | c.Assert(err, NotNil) |
615 | @@ -180,9 +173,7 @@ |
616 | Status: fmt.Sprintf("%d", http.StatusNotFound), |
617 | StatusCode: http.StatusNotFound, |
618 | } |
619 | - transport := &TestTransport{Response: response} |
620 | - context := makeStorageContext() |
621 | - context.client = &http.Client{Transport: transport} |
622 | + context := makeStorageContext(&TestTransport{Response: response}) |
623 | request := &ListBlobsRequest{Container: "container"} |
624 | _, err := context.ListAllBlobs(request) |
625 | c.Assert(err, NotNil) |
626 | @@ -218,11 +209,10 @@ |
627 | </EnumerationResults> |
628 | `, lastBlob)), |
629 | } |
630 | - transport := TestTransport2{} |
631 | + transport := &TestTransport2{} |
632 | transport.AddExchange(&firstBatch, nil) |
633 | transport.AddExchange(&lastBatch, nil) |
634 | - context := makeStorageContext() |
635 | - context.client = &http.Client{Transport: &transport} |
636 | + context := makeStorageContext(transport) |
637 | |
638 | request := &ListBlobsRequest{Container: "mycontainer"} |
639 | blobs, err := context.ListAllBlobs(request) |
640 | @@ -264,14 +254,13 @@ |
641 | </Containers> |
642 | <NextMarker/> |
643 | </EnumerationResults>` |
644 | - context := makeStorageContext() |
645 | response := &http.Response{ |
646 | Status: fmt.Sprintf("%d", http.StatusOK), |
647 | StatusCode: http.StatusOK, |
648 | Body: makeResponseBody(response_body), |
649 | } |
650 | transport := &TestTransport{Response: response} |
651 | - context.client = &http.Client{Transport: transport} |
652 | + context := makeStorageContext(transport) |
653 | results, err := context.ListAllContainers() |
654 | c.Assert(err, IsNil) |
655 | c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf( |
656 | @@ -284,9 +273,7 @@ |
657 | // Client-side errors from the HTTP client are propagated back to the caller. |
658 | func (suite *testListAllContainers) TestError(c *C) { |
659 | error := fmt.Errorf("canned-error") |
660 | - transport := &TestTransport{Error: error} |
661 | - context := makeStorageContext() |
662 | - context.client = &http.Client{Transport: transport} |
663 | + context := makeStorageContext(&TestTransport{Error: error}) |
664 | _, err := context.ListAllContainers() |
665 | c.Assert(err, NotNil) |
666 | } |
667 | @@ -297,9 +284,7 @@ |
668 | Status: fmt.Sprintf("%d", http.StatusNotFound), |
669 | StatusCode: http.StatusNotFound, |
670 | } |
671 | - transport := &TestTransport{Response: response} |
672 | - context := makeStorageContext() |
673 | - context.client = &http.Client{Transport: transport} |
674 | + context := makeStorageContext(&TestTransport{Response: response}) |
675 | _, err := context.ListAllContainers() |
676 | c.Assert(err, NotNil) |
677 | } |
678 | @@ -336,11 +321,10 @@ |
679 | </EnumerationResults> |
680 | `, lastContainer)), |
681 | } |
682 | - transport := TestTransport2{} |
683 | + transport := &TestTransport2{} |
684 | transport.AddExchange(&firstBatch, nil) |
685 | transport.AddExchange(&lastBatch, nil) |
686 | - context := makeStorageContext() |
687 | - context.client = &http.Client{Transport: &transport} |
688 | + context := makeStorageContext(transport) |
689 | |
690 | containers, err := context.ListAllContainers() |
691 | c.Assert(err, IsNil) |
Self approving despite the size; most of the changes are mechanical.