Merge lp:~julian-edwards/gwacl/putblob into lp:gwacl

Proposed by Julian Edwards
Status: Merged
Approved by: Julian Edwards
Approved revision: 40
Merged at revision: 39
Proposed branch: lp:~julian-edwards/gwacl/putblob
Merge into: lp:gwacl
Diff against target: 80 lines (+65/-0)
2 files modified
storage.go (+21/-0)
storage_test.go (+44/-0)
To merge this branch: bzr merge lp:~julian-edwards/gwacl/putblob
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+154572@code.launchpad.net

Commit message

Add a PutBlob() method on StorageContext.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve
lp:~julian-edwards/gwacl/putblob updated
40. By Julian Edwards

cleanups

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'storage.go'
2--- storage.go 2013-03-21 01:19:23 +0000
3+++ storage.go 2013-03-21 02:05:24 +0000
4@@ -267,3 +267,24 @@
5 _, err = context.send(req, blob)
6 return blob, err
7 }
8+
9+// Send a request to create a space to upload a blob. Note that this does not
10+// do the uploading, it just makes an empty file.
11+func (context *StorageContext) PutBlob(container, filename string) error {
12+ uri := fmt.Sprintf(
13+ "http://%s.blob.core.windows.net/%s/%s",
14+ context.Account, container, filename)
15+ req, err := http.NewRequest("PUT", uri, nil)
16+ if err != nil {
17+ return err
18+ }
19+ addStandardHeaders(req, context.Account, context.Key, "2012-02-12")
20+ resp, err := context.send(req, nil)
21+ if err != nil {
22+ return err
23+ }
24+ if resp.StatusCode != http.StatusCreated {
25+ return fmt.Errorf("Failed to put blob: %s", resp.Status)
26+ }
27+ return nil
28+}
29
30=== modified file 'storage_test.go'
31--- storage_test.go 2013-03-21 01:13:27 +0000
32+++ storage_test.go 2013-03-21 02:05:24 +0000
33@@ -421,3 +421,47 @@
34 _, err := context.ListBlobs("container")
35 c.Assert(err, Not(IsNil))
36 }
37+
38+type TestPutBlob struct{}
39+
40+var _ = Suite(&TestPutBlob{})
41+
42+// The ListBlobs Storage API call returns 201 CREATED on success.
43+func (suite *TestPutBlob) Test(c *C) {
44+ context := makeStorageContext()
45+ response := &http.Response{
46+ Status: fmt.Sprintf("%d", http.StatusCreated),
47+ StatusCode: http.StatusCreated,
48+ }
49+ transport := &TestTransport{Response: response}
50+ context.client = &http.Client{Transport: transport}
51+ err := context.PutBlob("container", "blobname")
52+ c.Assert(err, IsNil)
53+ c.Check(transport.Request.URL.String(), Equals, fmt.Sprintf(
54+ "http://%s.blob.core.windows.net/container/blobname",
55+ context.Account))
56+ c.Check(transport.Request.Header.Get("Authorization"), Not(Equals), "")
57+}
58+
59+// Client-side errors from the HTTP client are propagated back to the caller.
60+func (suite *TestPutBlob) TestError(c *C) {
61+ error := fmt.Errorf("canned-error")
62+ transport := &TestTransport{Error: error}
63+ context := makeStorageContext()
64+ context.client = &http.Client{Transport: transport}
65+ err := context.PutBlob("container", "blobname")
66+ c.Assert(err, Not(IsNil))
67+}
68+
69+// Server-side errors are propagated back to the caller.
70+func (suite *TestPutBlob) TestErrorResponse(c *C) {
71+ response := &http.Response{
72+ Status: "202 Frotzed",
73+ StatusCode: 202,
74+ }
75+ transport := &TestTransport{Response: response}
76+ context := makeStorageContext()
77+ context.client = &http.Client{Transport: transport}
78+ err := context.PutBlob("container", "blobname")
79+ c.Assert(err.Error(), Equals, "failed to put blob: 202 Frotzed")
80+}

Subscribers

People subscribed via source and target branches

to all changes: