diff --git a/sdk/storage/azblob/appendblob/client.go b/sdk/storage/azblob/appendblob/client.go index fcb2a349e45e..d027355ee407 100644 --- a/sdk/storage/azblob/appendblob/client.go +++ b/sdk/storage/azblob/appendblob/client.go @@ -8,6 +8,7 @@ package appendblob import ( "context" + "errors" "io" "os" "time" @@ -255,14 +256,10 @@ func (ab *Client) SetLegalHold(ctx context.Context, legalHold bool, options *blo return ab.BlobClient().SetLegalHold(ctx, legalHold, options) } -// SetTier operation sets the tier on a blob. The operation is allowed on a page -// blob in a premium storage account and on a block blob in a blob storage account (locally -// redundant storage only). A premium page blob's tier determines the allowed size, IOPS, and -// bandwidth of the blob. A block blob's tier determines Hot/Cool/Archive storage type. This operation -// does not update the blob's ETag. -// For detailed information about block blob level tiering see https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers. +// SetTier +// Deprecated: SetTier only works for page blob in premium storage account and block blob in blob storage account. func (ab *Client) SetTier(ctx context.Context, tier blob.AccessTier, o *blob.SetTierOptions) (blob.SetTierResponse, error) { - return ab.BlobClient().SetTier(ctx, tier, o) + return blob.SetTierResponse{}, errors.New("Operation will not work on this blob type. SetTier only works for page blob in premium storage account and block blob in blob storage account.") } // SetExpiry operation sets an expiry time on an existing blob. This operation is only allowed on Hierarchical Namespace enabled accounts. @@ -326,10 +323,10 @@ func (ab *Client) GetTags(ctx context.Context, o *blob.GetTagsOptions) (blob.Get return ab.BlobClient().GetTags(ctx, o) } -// CopyFromURL synchronously copies the data at the source URL to a block blob, with sizes up to 256 MB. -// For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url. +// CopyFromURL +// Deprecated: CopyFromURL works only with block blob func (ab *Client) CopyFromURL(ctx context.Context, copySource string, o *blob.CopyFromURLOptions) (blob.CopyFromURLResponse, error) { - return ab.BlobClient().CopyFromURL(ctx, copySource, o) + return blob.CopyFromURLResponse{}, errors.New("Operation will not work on this blob type. CopyFromURL works only with block blob.") } // Concurrent Download Functions ----------------------------------------------------------------------------------------- diff --git a/sdk/storage/azblob/appendblob/client_test.go b/sdk/storage/azblob/appendblob/client_test.go index 63dca724f609..ca6781b40e27 100644 --- a/sdk/storage/azblob/appendblob/client_test.go +++ b/sdk/storage/azblob/appendblob/client_test.go @@ -11,6 +11,7 @@ import ( "context" "crypto/md5" "encoding/binary" + "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/lease" "hash/crc64" "io" "math/rand" @@ -2381,3 +2382,575 @@ func (s *AppendBlobUnrecordedTestsSuite) TestAppendBlobSetExpiryToAbsolute() { _, err = abClient.GetProperties(context.Background(), nil) testcommon.ValidateBlobErrorCode(_require, err, bloberror.BlobNotFound) } + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataNil() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetMetadata(context.Background(), map[string]*string{"not": to.Ptr("nil")}, nil) + _require.Nil(err) + + _, err = abClient.SetMetadata(context.Background(), nil, nil) + _require.Nil(err) + + blobGetResp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + _require.Len(blobGetResp.Metadata, 0) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataEmpty() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetMetadata(context.Background(), map[string]*string{"not": to.Ptr("nil")}, nil) + _require.Nil(err) + + _, err = abClient.SetMetadata(context.Background(), map[string]*string{}, nil) + _require.Nil(err) + + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + _require.Len(resp.Metadata, 0) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataInvalidField() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetMetadata(context.Background(), map[string]*string{"Invalid field!": to.Ptr("value")}, nil) + _require.NotNil(err) + _require.Contains(err.Error(), testcommon.InvalidHeaderErrorSubstring) +} + +func validateMetadataSet(_require *require.Assertions, abClient *appendblob.Client) { + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + _require.EqualValues(resp.Metadata, testcommon.BasicMetadata) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfModifiedSinceTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, -10) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfModifiedSince: ¤tTime}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + _require.Nil(err) + + validateMetadataSet(_require, abClient) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfModifiedSinceFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, 10) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfModifiedSince: ¤tTime}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfUnmodifiedSinceTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, 10) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfUnmodifiedSince: ¤tTime}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + _require.Nil(err) + + validateMetadataSet(_require, abClient) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfUnmodifiedSinceFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, -10) + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfUnmodifiedSince: to.Ptr(currentTime)}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfMatchTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfMatch: resp.ETag}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + _require.Nil(err) + + validateMetadataSet(_require, abClient) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfMatchFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfMatch: to.Ptr(azcore.ETag("garbage"))}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfNoneMatchTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfNoneMatch: to.Ptr(azcore.ETag("garbage"))}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + _require.Nil(err) + + validateMetadataSet(_require, abClient) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetMetadataIfNoneMatchFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + + setBlobMetadataOptions := blob.SetMetadataOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfNoneMatch: resp.ETag}, + }, + } + _, err = abClient.SetMetadata(context.Background(), testcommon.BasicMetadata, &setBlobMetadataOptions) + testcommon.ValidateBlobErrorCode(_require, err, bloberror.ConditionNotMet) +} + +func validatePropertiesSet(_require *require.Assertions, abClient *appendblob.Client, disposition string) { + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + _require.Equal(*resp.ContentDisposition, disposition) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfModifiedSinceTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, -10) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfModifiedSince: ¤tTime}, + }, + }) + _require.Nil(err) + + validatePropertiesSet(_require, abClient, "my_disposition") +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfModifiedSinceFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, 10) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{ + AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfModifiedSince: ¤tTime}, + }}) + _require.NotNil(err) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfUnmodifiedSinceTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, 10) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfUnmodifiedSince: ¤tTime}, + }}) + _require.Nil(err) + + validatePropertiesSet(_require, abClient, "my_disposition") +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfUnmodifiedSinceFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + cResp, err := abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + currentTime := testcommon.GetRelativeTimeFromAnchor(cResp.Date, -10) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfUnmodifiedSince: ¤tTime}, + }}) + _require.NotNil(err) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfMatchTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfMatch: resp.ETag}, + }}) + _require.Nil(err) + + validatePropertiesSet(_require, abClient, "my_disposition") +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfMatchFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfMatch: to.Ptr(azcore.ETag("garbage"))}, + }}) + _require.NotNil(err) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfNoneMatchTrue() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfNoneMatch: to.Ptr(azcore.ETag("garbage"))}, + }}) + _require.Nil(err) + + validatePropertiesSet(_require, abClient, "my_disposition") +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetHTTPHeaderIfNoneMatchFalse() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerName := testcommon.GenerateContainerName(testName) + containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + resp, err := abClient.GetProperties(context.Background(), nil) + _require.Nil(err) + + _, err = abClient.SetHTTPHeaders(context.Background(), blob.HTTPHeaders{BlobContentDisposition: to.Ptr("my_disposition")}, + &blob.SetHTTPHeadersOptions{AccessConditions: &blob.AccessConditions{ + ModifiedAccessConditions: &blob.ModifiedAccessConditions{IfNoneMatch: resp.ETag}, + }}) + _require.NotNil(err) +} + +func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetBlobTags() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerClient := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName), svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + _, err = abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) + _require.Nil(err) + + _, err = abClient.SetTags(context.Background(), testcommon.BasicBlobTagsMap, nil) + _require.Nil(err) + time.Sleep(10 * time.Second) + + blobGetTagsResponse, err := abClient.GetTags(context.Background(), nil) + _require.Nil(err) + + blobTagsSet := blobGetTagsResponse.BlobTagSet + _require.NotNil(blobTagsSet) + _require.Len(blobTagsSet, 3) + for _, blobTag := range blobTagsSet { + _require.Equal(testcommon.BasicBlobTagsMap[*blobTag.Key], *blobTag.Value) + } +} + +func (s *AppendBlobUnrecordedTestsSuite) TestSetBlobTagsWithLeaseId() { + _require := require.New(s.T()) + testName := s.T().Name() + svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil) + _require.NoError(err) + + containerClient := testcommon.CreateNewContainer(context.Background(), _require, testcommon.GenerateContainerName(testName), svcClient) + defer testcommon.DeleteContainer(context.Background(), _require, containerClient) + + abClient := getAppendBlobClient(testcommon.GenerateBlobName(testName), containerClient) + _, err = abClient.Create(context.Background(), nil) + _require.Nil(err) + + blobLeaseClient, err := lease.NewBlobClient(abClient, &lease.BlobClientOptions{ + LeaseID: to.Ptr("c820a799-76d7-4ee2-6e15-546f19325c2c"), + }) + _require.NoError(err) + ctx := context.Background() + acquireLeaseResponse, err := blobLeaseClient.AcquireLease(ctx, int32(60), nil) + _require.Nil(err) + _require.NotNil(acquireLeaseResponse.LeaseID) + _require.EqualValues(acquireLeaseResponse.LeaseID, blobLeaseClient.LeaseID()) + + _, err = abClient.SetTags(ctx, testcommon.BasicBlobTagsMap, nil) + _require.NotNil(err) + time.Sleep(10 * time.Second) + + // add lease conditions + _, err = abClient.SetTags(ctx, testcommon.BasicBlobTagsMap, &blob.SetTagsOptions{AccessConditions: &blob.AccessConditions{ + LeaseAccessConditions: &blob.LeaseAccessConditions{LeaseID: blobLeaseClient.LeaseID()}}}) + _require.Nil(err) + + _, err = abClient.GetTags(ctx, nil) + _require.NoError(err) + + blobGetTagsResponse, err := abClient.GetTags(ctx, &blob.GetTagsOptions{BlobAccessConditions: &blob.AccessConditions{ + LeaseAccessConditions: &blob.LeaseAccessConditions{LeaseID: blobLeaseClient.LeaseID()}}}) + _require.NoError(err) + + blobTagsSet := blobGetTagsResponse.BlobTagSet + _require.NotNil(blobTagsSet) + _require.Len(blobTagsSet, 3) + for _, blobTag := range blobTagsSet { + _require.Equal(testcommon.BasicBlobTagsMap[*blobTag.Key], *blobTag.Value) + } +} diff --git a/sdk/storage/azblob/assets.json b/sdk/storage/azblob/assets.json index 11783d2a84b4..506e74c970fa 100644 --- a/sdk/storage/azblob/assets.json +++ b/sdk/storage/azblob/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/storage/azblob", - "Tag": "go/storage/azblob_658d0bdec9" + "Tag": "go/storage/azblob_b92bf5d8e3" }