diff --git a/sdk/storage/azblob/appendblob/client_test.go b/sdk/storage/azblob/appendblob/client_test.go index ca6781b40e27..ff924e7680d0 100644 --- a/sdk/storage/azblob/appendblob/client_test.go +++ b/sdk/storage/azblob/appendblob/client_test.go @@ -688,6 +688,8 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendSetImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) + abName := testcommon.GenerateBlobName(testName) abClient := createNewAppendBlob(context.Background(), _require, abName, containerClient) @@ -724,6 +726,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendDeleteImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) abName := testcommon.GenerateBlobName(testName) abClient := createNewAppendBlob(context.Background(), _require, abName, containerClient) @@ -756,6 +759,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendSetLegalHold() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) abName := testcommon.GenerateBlobName(testName) abClient := createNewAppendBlob(context.Background(), _require, abName, containerClient) @@ -2893,7 +2897,11 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetBlobTags() { _, err = abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil) _require.Nil(err) - _, err = abClient.SetTags(context.Background(), testcommon.BasicBlobTagsMap, nil) + var tagsMap = map[string]string{ + "azure": "blob", + } + + _, err = abClient.SetTags(context.Background(), tagsMap, nil) _require.Nil(err) time.Sleep(10 * time.Second) @@ -2902,9 +2910,9 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetBlobTags() { blobTagsSet := blobGetTagsResponse.BlobTagSet _require.NotNil(blobTagsSet) - _require.Len(blobTagsSet, 3) + _require.Len(blobTagsSet, 1) for _, blobTag := range blobTagsSet { - _require.Equal(testcommon.BasicBlobTagsMap[*blobTag.Key], *blobTag.Value) + _require.Equal(tagsMap[*blobTag.Key], *blobTag.Value) } } diff --git a/sdk/storage/azblob/assets.json b/sdk/storage/azblob/assets.json index 506e74c970fa..af9507a89a06 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_b92bf5d8e3" + "Tag": "go/storage/azblob_cbcc92f524" } diff --git a/sdk/storage/azblob/blob/client_test.go b/sdk/storage/azblob/blob/client_test.go index c7e985cd0487..d0668fcd85a2 100644 --- a/sdk/storage/azblob/blob/client_test.go +++ b/sdk/storage/azblob/blob/client_test.go @@ -3439,6 +3439,7 @@ func (s *BlobRecordedTestsSuite) TestSetImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blockBlobName := testcommon.GenerateBlobName(testName) bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient) @@ -3460,6 +3461,7 @@ func (s *BlobRecordedTestsSuite) TestSetImmutabilityPolicy() { _, err = bbClient.Delete(context.Background(), nil) _require.NotNil(err) + testcommon.ValidateBlobErrorCode(_require, err, bloberror.BlobImmutableDueToPolicy) _, err = bbClient.DeleteImmutabilityPolicy(context.Background(), nil) _require.Nil(err) @@ -3476,6 +3478,7 @@ func (s *BlobRecordedTestsSuite) TestDeleteImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blockBlobName := testcommon.GenerateBlobName(testName) bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient) @@ -3508,6 +3511,7 @@ func (s *BlobRecordedTestsSuite) TestSetLegalHold() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blockBlobName := testcommon.GenerateBlobName(testName) bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient) diff --git a/sdk/storage/azblob/blockblob/client_test.go b/sdk/storage/azblob/blockblob/client_test.go index 346b3f51ac8b..98883c4f614f 100644 --- a/sdk/storage/azblob/blockblob/client_test.go +++ b/sdk/storage/azblob/blockblob/client_test.go @@ -549,6 +549,7 @@ func (s *BlockBlobRecordedTestsSuite) TestUploadBlockWithImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blockBlobName := testcommon.GenerateBlobName(testName) bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient) @@ -594,6 +595,7 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlockListWithImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blockBlobName := testcommon.GenerateBlobName(testName) bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient) diff --git a/sdk/storage/azblob/ci.yml b/sdk/storage/azblob/ci.yml index e0623f50e855..f5100e131137 100644 --- a/sdk/storage/azblob/ci.yml +++ b/sdk/storage/azblob/ci.yml @@ -26,3 +26,8 @@ stages: parameters: ServiceDirectory: 'storage/azblob' RunLiveTests: true + EnvVars: + AZURE_CLIENT_ID: $(AZBLOB_CLIENT_ID) + AZURE_TENANT_ID: $(AZBLOB_TENANT_ID) + AZURE_CLIENT_SECRET: $(AZBLOB_CLIENT_SECRET) + AZURE_SUBSCRIPTION_ID: $(AZBLOB_SUBSCRIPTION_ID) diff --git a/sdk/storage/azblob/go.mod b/sdk/storage/azblob/go.mod index b806c73c66ed..5376927d71d4 100644 --- a/sdk/storage/azblob/go.mod +++ b/sdk/storage/azblob/go.mod @@ -6,6 +6,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0 github.com/stretchr/testify v1.7.1 ) diff --git a/sdk/storage/azblob/go.sum b/sdk/storage/azblob/go.sum index 5570bcf240ad..e90fe395aed0 100644 --- a/sdk/storage/azblob/go.sum +++ b/sdk/storage/azblob/go.sum @@ -4,6 +4,10 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 h1:QkAcEIAKbNL4KoFr4Sath github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0/go.mod h1:bhXu1AjYL+wutSL/kpSq6s7733q2Rb0yuot9Zgfqa/0= github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.0.0 h1:lMW1lD/17LUA5z1XTURo7LcVG2ICBPlyMHjIUrcFZNQ= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0 h1:Ma67P/GGprNwsslzEH6+Kb8nybI8jpDTm4Wmzu2ReK8= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0/go.mod h1:c+Lifp3EDEamAkPVzMooRNOK6CZjNSdEnf1A7jsI9u4= github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE= github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/sdk/storage/azblob/internal/testcommon/clients_auth.go b/sdk/storage/azblob/internal/testcommon/clients_auth.go index 470d8f7fb02c..5d9cc24c3575 100644 --- a/sdk/storage/azblob/internal/testcommon/clients_auth.go +++ b/sdk/storage/azblob/internal/testcommon/clients_auth.go @@ -11,6 +11,8 @@ import ( "context" "errors" "fmt" + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas" "strings" "testing" @@ -46,6 +48,8 @@ const ( AccountNameEnvVar = "AZURE_STORAGE_ACCOUNT_NAME" AccountKeyEnvVar = "AZURE_STORAGE_ACCOUNT_KEY" DefaultEndpointSuffixEnvVar = "AZURE_STORAGE_ENDPOINT_SUFFIX" + SubscriptionID = "SUBSCRIPTION_ID" + ResourceGroupName = "RESOURCE_GROUP_NAME" ) const ( @@ -364,3 +368,27 @@ func GetAccountSAS(permissions sas.AccountPermissions, resourceTypes sas.Account return sasQueryParams.Encode(), nil } + +func DeleteContainerUsingManagementClient(_require *require.Assertions, accountType TestAccountType, containerName string) { + if recording.GetRecordMode() == recording.PlaybackMode { + return + } + + accountName, err := GetRequiredEnv(string(accountType) + AccountNameEnvVar) + _require.NoError(err) + + subscriptionID, err := GetRequiredEnv(SubscriptionID) + _require.NoError(err) + + resourceGroupName, err := GetRequiredEnv(ResourceGroupName) + _require.NoError(err) + + cred, err := azidentity.NewDefaultAzureCredential(nil) + _require.NoError(err) + + managementClient, err := armstorage.NewBlobContainersClient(subscriptionID, cred, nil) + _require.NoError(err) + + _, err = managementClient.Delete(context.Background(), resourceGroupName, accountName, containerName, nil) + _require.NoError(err) +} diff --git a/sdk/storage/azblob/pageblob/client_test.go b/sdk/storage/azblob/pageblob/client_test.go index 8d133dec20b0..216acb62c4bd 100644 --- a/sdk/storage/azblob/pageblob/client_test.go +++ b/sdk/storage/azblob/pageblob/client_test.go @@ -3288,6 +3288,8 @@ func (s *PageBlobRecordedTestsSuite) TestPageSetImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) + blobName := testcommon.GenerateBlobName(testName) pbClient := createNewPageBlob(context.Background(), _require, blobName, containerClient) @@ -3324,6 +3326,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageDeleteImmutabilityPolicy() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blobName := testcommon.GenerateBlobName(testName) pbClient := createNewPageBlob(context.Background(), _require, blobName, containerClient) @@ -3356,6 +3359,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageSetLegalHold() { containerName := testcommon.GenerateContainerName(testName) containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient) + defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName) blobName := testcommon.GenerateBlobName(testName) pbClient := createNewPageBlob(context.Background(), _require, blobName, containerClient)