Skip to content

Commit

Permalink
Add support for extraHeaders in SetBlobMetadata (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchippada authored and ahmetb committed May 12, 2016
1 parent 5cf7b8a commit e63b145
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
6 changes: 5 additions & 1 deletion storage/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,18 @@ func (b BlobStorageClient) GetBlobProperties(container, name string) (*BlobPrope
// applications either.
//
// See https://msdn.microsoft.com/en-us/library/azure/dd179414.aspx
func (b BlobStorageClient) SetBlobMetadata(container, name string, metadata map[string]string) error {
func (b BlobStorageClient) SetBlobMetadata(container, name string, metadata map[string]string, extraHeaders map[string]string) error {
params := url.Values{"comp": {"metadata"}}
uri := b.client.getEndpoint(blobServiceName, pathForBlob(container, name), params)
headers := b.client.getStandardHeaders()
for k, v := range metadata {
headers[userDefinedMetadataHeaderPrefix+k] = v
}

for k, v := range extraHeaders {
headers[k] = v
}

resp, err := b.client.exec("PUT", uri, headers, nil)
if err != nil {
return err
Expand Down
41 changes: 37 additions & 4 deletions storage/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (s *StorageBlobSuite) TestDeleteBlobWithConditions(c *chk.C) {
c.Assert(err, chk.IsNil)

// Update metadata, so Etag changes
c.Assert(cli.SetBlobMetadata(cnt, blob, map[string]string{}), chk.IsNil)
c.Assert(cli.SetBlobMetadata(cnt, blob, map[string]string{}, nil), chk.IsNil)
newProps, err := cli.GetBlobProperties(cnt, blob)
c.Assert(err, chk.IsNil)

Expand Down Expand Up @@ -526,7 +526,7 @@ func (s *StorageBlobSuite) TestListBlobsWithMetadata(c *chk.C) {
c.Assert(cli.SetBlobMetadata(cnt, name, map[string]string{
"Foo": name,
"Bar_BAZ": "Waz Qux",
}), chk.IsNil)
}, nil), chk.IsNil)
expectMeta[name] = BlobMetadata{
"foo": name,
"bar_baz": "Waz Qux",
Expand Down Expand Up @@ -587,7 +587,7 @@ func (s *StorageBlobSuite) TestGetAndSetMetadata(c *chk.C) {
"bar_baz": "waz qux",
}

err = cli.SetBlobMetadata(cnt, blob, mPut)
err = cli.SetBlobMetadata(cnt, blob, mPut, nil)
c.Assert(err, chk.IsNil)

m, err = cli.GetBlobMetadata(cnt, blob)
Expand All @@ -605,14 +605,47 @@ func (s *StorageBlobSuite) TestGetAndSetMetadata(c *chk.C) {
"bar_baz": "different waz qux",
}

err = cli.SetBlobMetadata(cnt, blob, mPutUpper)
err = cli.SetBlobMetadata(cnt, blob, mPutUpper, nil)
c.Assert(err, chk.IsNil)

m, err = cli.GetBlobMetadata(cnt, blob)
c.Assert(err, chk.IsNil)
c.Check(m, chk.DeepEquals, mExpectLower)
}

func (s *StorageBlobSuite) TestSetMetadataWithExtraHeaders(c *chk.C) {
cli := getBlobClient(c)
cnt := randContainer()

c.Assert(cli.CreateContainer(cnt, ContainerAccessTypePrivate), chk.IsNil)
defer cli.deleteContainer(cnt)

blob := randString(20)
c.Assert(cli.putSingleBlockBlob(cnt, blob, []byte{}), chk.IsNil)

mPut := map[string]string{
"foo": "bar",
"bar_baz": "waz qux",
}

extraHeaders := map[string]string{
"If-Match": "incorrect-etag",
}

// Set with incorrect If-Match in extra headers should result in error
err := cli.SetBlobMetadata(cnt, blob, mPut, extraHeaders)
c.Assert(err, chk.NotNil)

props, err := cli.GetBlobProperties(cnt, blob)
extraHeaders = map[string]string{
"If-Match": props.Etag,
}

// Set with matching If-Match in extra headers should succeed
err = cli.SetBlobMetadata(cnt, blob, mPut, extraHeaders)
c.Assert(err, chk.IsNil)
}

func (s *StorageBlobSuite) TestPutEmptyBlockBlob(c *chk.C) {
cli := getBlobClient(c)
cnt := randContainer()
Expand Down

0 comments on commit e63b145

Please sign in to comment.