Merge lp:~rvb/gwacl/delete-404 into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 127
Merged at revision: 125
Proposed branch: lp:~rvb/gwacl/delete-404
Merge into: lp:gwacl
Diff against target: 57 lines (+19/-5)
2 files modified
storage_base.go (+7/-3)
storage_base_test.go (+12/-2)
To merge this branch: bzr merge lp:~rvb/gwacl/delete-404
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Gavin Panella Approve
Review via email: mp+170824@code.launchpad.net

Commit message

Deleting a non-existant blob does not return an error.

To post a comment you must log in.
lp:~rvb/gwacl/delete-404 updated
126. By Raphaël Badin

Tiny consistency fix.

Revision history for this message
Gavin Panella (allenap) :
review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Looks good, and of course HTTP DELETE is meant to be idempotent.

The comment in TestServerError is very welcome for review, but possibly a bit superfluous as a part of the code. If you do keep it, two general notes about the comment:

1. I'd avoid the preamble "note that" in comments. It can liven up longer texts, but is redundant in a code comment. In this case I'd say it calls undue attention to something of relatively little importance.

2. Language easily contorts around the passive voice. "X is done by Y" is usually worse than "Y does X."

review: Approve
lp:~rvb/gwacl/delete-404 updated
127. By Raphaël Badin

Improve comment.

Revision history for this message
Raphaël Badin (rvb) wrote :

 > 1. I'd avoid the preamble "note that" in comments. It can liven up longer
> texts, but is redundant in a code comment. In this case I'd say it calls
> undue attention to something of relatively little importance.

All right, this is not the first you've mentioned this.

> 2. Language easily contorts around the passive voice. "X is done by Y" is
> usually worse than "Y does X."

Well, you really seem to have something against the passive voice :).

Revision history for this message
Julian Edwards (julian-edwards) wrote :

s/existant/existent/

Surprised the other spelling police didn't notice this.

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-06-21 11:27:17 +0000
3+++ storage_base.go 2013-06-21 15:08:26 +0000
4@@ -567,7 +567,8 @@
5 return nil
6 }
7
8-// Delete the specified blob from the given container.
9+// Delete the specified blob from the given container. Deleting a non-existant
10+// blob will return without an error.
11 func (context *StorageContext) DeleteBlob(container, filename string) error {
12 _, err := context.performRequest(requestParams{
13 Method: "DELETE",
14@@ -575,9 +576,12 @@
15 APIVersion: "2012-02-12",
16 ExpectedStatus: http.StatusAccepted,
17 })
18- // TODO Handle a 404 with an <Error>BlobNotFound response body silently.
19- // Now this is easy to fix with the method IsNotFoundError().
20 if err != nil {
21+ // If the error is an Azure 404 error, return silently: the blob does
22+ // not exist.
23+ if IsNotFoundError(err) {
24+ return nil
25+ }
26 msg := fmt.Sprintf("failed to delete blob %s: ", filename)
27 return extendError(err, msg)
28 }
29
30=== modified file 'storage_base_test.go'
31--- storage_base_test.go 2013-06-21 11:27:17 +0000
32+++ storage_base_test.go 2013-06-21 15:08:26 +0000
33@@ -1010,12 +1010,22 @@
34 // Azure HTTP errors (for instance 404 responses) are propagated back to
35 // the caller as ServerError objects.
36 func (suite *TestDeleteBlob) TestServerError(c *C) {
37- response := makeHttpResponse(http.StatusNotFound, "not found")
38+ // We're not using http.StatusNotFound for the test here because
39+ // 404 errors are handled in a special way by DeleteBlob(). See the test
40+ // TestDeleteNotExistantBlobDoesNotFail.
41+ response := makeHttpResponse(http.StatusMethodNotAllowed, "not allowed")
42 context := makeStorageContext(&TestTransport{Response: response})
43 err := context.DeleteBlob("container", "blobname")
44 serverError, ok := err.(*ServerError)
45 c.Check(ok, Equals, true)
46- c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)
47+ c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusMethodNotAllowed)
48+}
49+
50+func (suite *TestDeleteBlob) TestDeleteNotExistantBlobDoesNotFail(c *C) {
51+ response := makeHttpResponse(http.StatusNotFound, "not found")
52+ context := makeStorageContext(&TestTransport{Response: response})
53+ err := context.DeleteBlob("container", "blobname")
54+ c.Assert(err, IsNil)
55 }
56
57 // Server-side errors are propagated back to the caller.

Subscribers

People subscribed via source and target branches

to all changes: