Merge lp:~julian-edwards/gwacl/delete-container into lp:gwacl

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: 204
Merged at revision: 204
Proposed branch: lp:~julian-edwards/gwacl/delete-container
Merge into: lp:gwacl
Diff against target: 95 lines (+74/-0)
2 files modified
storage_base.go (+19/-0)
storage_base_test.go (+55/-0)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/delete-container
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+177104@code.launchpad.net

Commit message

Add the DeleteContainer storage call.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Looks good, given the difficulties with unit-testing in Go. Maybe in addition to testing that deliberately induced errors come out as non-nil, you could also cursorily check their contents.

Use the ErrorMatches checker to verify that an error matches a given regex:

    // Don't care what else is in the error, but the original error message
    // must be in there somewhere.
    c.Check(err, ErrorMatches, ".*canned error.*")

review: Approve
204. By Julian Edwards

improve test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storage_base.go'
2--- storage_base.go 2013-07-26 08:49:56 +0000
3+++ storage_base.go 2013-07-29 00:23:26 +0000
4@@ -439,6 +439,25 @@
5 return nil
6 }
7
8+// Send a request to the storage service to delete a container. It will also
9+// delete all the blobs inside it.
10+func (context *StorageContext) DeleteContainer(container string) error {
11+ uri := addURLQueryParams(
12+ context.getContainerURL(container),
13+ "restype", "container")
14+ _, err := context.performRequest(requestParams{
15+ Method: "DELETE",
16+ URL: uri,
17+ APIVersion: "2012-02-12",
18+ ExpectedStatus: http.StatusAccepted,
19+ })
20+ if err != nil {
21+ msg := fmt.Sprintf("failed to delete container %s: ", container)
22+ return extendError(err, msg)
23+ }
24+ return nil
25+}
26+
27 type PutBlobRequest struct {
28 Container string // Container name in the storage account
29 BlobType string // Pass "page" or "block"
30
31=== modified file 'storage_base_test.go'
32--- storage_base_test.go 2013-07-26 08:49:56 +0000
33+++ storage_base_test.go 2013-07-29 00:23:26 +0000
34@@ -688,6 +688,61 @@
35 c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)
36 }
37
38+type TestDeleteContainer struct{}
39+
40+var _ = Suite(&TestDeleteContainer{})
41+
42+// The DeleteContainer Storage API call returns without error when the
43+// container has been created successfully.
44+func (suite *TestDeleteContainer) Test(c *C) {
45+ response := makeHttpResponse(http.StatusAccepted, "")
46+ transport := &TestTransport{Response: response}
47+ context := makeStorageContext(transport)
48+ containerName := MakeRandomString(10)
49+ err := context.DeleteContainer(containerName)
50+ c.Assert(err, IsNil)
51+ c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
52+ "http://%s.blob.core.windows.net/%s?restype=container",
53+ context.Account, containerName))
54+ c.Check(transport.Request.Method, Equals, "DELETE")
55+ c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
56+}
57+
58+// Client-side errors from the HTTP client are propagated back to the caller.
59+func (suite *TestDeleteContainer) TestError(c *C) {
60+ error := fmt.Errorf("canned-error")
61+ context := makeStorageContext(&TestTransport{Error: error})
62+ err := context.DeleteContainer("container")
63+ c.Assert(err, ErrorMatches, ".*canned-error.*")
64+}
65+
66+// Server-side errors are propagated back to the caller.
67+func (suite *TestDeleteContainer) TestErrorResponse(c *C) {
68+ response := makeHttpResponse(http.StatusNotFound, "not found")
69+ context := makeStorageContext(&TestTransport{Response: response})
70+ err := context.DeleteContainer("container")
71+ c.Assert(err, ErrorMatches, ".*Not Found.*")
72+}
73+
74+// Server-side errors are propagated back to the caller.
75+func (suite *TestDeleteContainer) TestNotCreatedResponse(c *C) {
76+ response := makeHttpResponse(http.StatusOK, "")
77+ context := makeStorageContext(&TestTransport{Response: response})
78+ err := context.DeleteContainer("container")
79+ c.Assert(err, ErrorMatches, ".*Azure request failed.*")
80+}
81+
82+// Azure HTTP errors (for instance 404 responses) are propagated back to
83+// the caller as ServerError objects.
84+func (suite *TestDeleteContainer) TestServerError(c *C) {
85+ response := makeHttpResponse(http.StatusNotFound, "not found")
86+ context := makeStorageContext(&TestTransport{Response: response})
87+ err := context.DeleteContainer("container")
88+ serverError, ok := err.(*ServerError)
89+ c.Check(ok, Equals, true)
90+ c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)
91+}
92+
93 type TestPutPage struct{}
94
95 var _ = Suite(&TestPutPage{})

Subscribers

People subscribed via source and target branches

to all changes: