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
=== modified file 'storage_base.go'
--- storage_base.go 2013-07-26 08:49:56 +0000
+++ storage_base.go 2013-07-29 00:23:26 +0000
@@ -439,6 +439,25 @@
439 return nil439 return nil
440}440}
441441
442// Send a request to the storage service to delete a container. It will also
443// delete all the blobs inside it.
444func (context *StorageContext) DeleteContainer(container string) error {
445 uri := addURLQueryParams(
446 context.getContainerURL(container),
447 "restype", "container")
448 _, err := context.performRequest(requestParams{
449 Method: "DELETE",
450 URL: uri,
451 APIVersion: "2012-02-12",
452 ExpectedStatus: http.StatusAccepted,
453 })
454 if err != nil {
455 msg := fmt.Sprintf("failed to delete container %s: ", container)
456 return extendError(err, msg)
457 }
458 return nil
459}
460
442type PutBlobRequest struct {461type PutBlobRequest struct {
443 Container string // Container name in the storage account462 Container string // Container name in the storage account
444 BlobType string // Pass "page" or "block"463 BlobType string // Pass "page" or "block"
445464
=== modified file 'storage_base_test.go'
--- storage_base_test.go 2013-07-26 08:49:56 +0000
+++ storage_base_test.go 2013-07-29 00:23:26 +0000
@@ -688,6 +688,61 @@
688 c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)688 c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)
689}689}
690690
691type TestDeleteContainer struct{}
692
693var _ = Suite(&TestDeleteContainer{})
694
695// The DeleteContainer Storage API call returns without error when the
696// container has been created successfully.
697func (suite *TestDeleteContainer) Test(c *C) {
698 response := makeHttpResponse(http.StatusAccepted, "")
699 transport := &TestTransport{Response: response}
700 context := makeStorageContext(transport)
701 containerName := MakeRandomString(10)
702 err := context.DeleteContainer(containerName)
703 c.Assert(err, IsNil)
704 c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
705 "http://%s.blob.core.windows.net/%s?restype=container",
706 context.Account, containerName))
707 c.Check(transport.Request.Method, Equals, "DELETE")
708 c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
709}
710
711// Client-side errors from the HTTP client are propagated back to the caller.
712func (suite *TestDeleteContainer) TestError(c *C) {
713 error := fmt.Errorf("canned-error")
714 context := makeStorageContext(&TestTransport{Error: error})
715 err := context.DeleteContainer("container")
716 c.Assert(err, ErrorMatches, ".*canned-error.*")
717}
718
719// Server-side errors are propagated back to the caller.
720func (suite *TestDeleteContainer) TestErrorResponse(c *C) {
721 response := makeHttpResponse(http.StatusNotFound, "not found")
722 context := makeStorageContext(&TestTransport{Response: response})
723 err := context.DeleteContainer("container")
724 c.Assert(err, ErrorMatches, ".*Not Found.*")
725}
726
727// Server-side errors are propagated back to the caller.
728func (suite *TestDeleteContainer) TestNotCreatedResponse(c *C) {
729 response := makeHttpResponse(http.StatusOK, "")
730 context := makeStorageContext(&TestTransport{Response: response})
731 err := context.DeleteContainer("container")
732 c.Assert(err, ErrorMatches, ".*Azure request failed.*")
733}
734
735// Azure HTTP errors (for instance 404 responses) are propagated back to
736// the caller as ServerError objects.
737func (suite *TestDeleteContainer) TestServerError(c *C) {
738 response := makeHttpResponse(http.StatusNotFound, "not found")
739 context := makeStorageContext(&TestTransport{Response: response})
740 err := context.DeleteContainer("container")
741 serverError, ok := err.(*ServerError)
742 c.Check(ok, Equals, true)
743 c.Check(serverError.HTTPStatus.StatusCode(), Equals, http.StatusNotFound)
744}
745
691type TestPutPage struct{}746type TestPutPage struct{}
692747
693var _ = Suite(&TestPutPage{})748var _ = Suite(&TestPutPage{})

Subscribers

People subscribed via source and target branches

to all changes: