Skip to content

Commit 6cd8433

Browse files
Cleanup after SetImmutabilityPolicy() and SetLegalHold() tests (Azure#20429)
* Using storage management plane sdk for container deletion
1 parent 8c1454f commit 6cd8433

File tree

9 files changed

+60
-4
lines changed

9 files changed

+60
-4
lines changed

sdk/storage/azblob/appendblob/client_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,8 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendSetImmutabilityPolicy() {
688688

689689
containerName := testcommon.GenerateContainerName(testName)
690690
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
691+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
692+
691693
abName := testcommon.GenerateBlobName(testName)
692694
abClient := createNewAppendBlob(context.Background(), _require, abName, containerClient)
693695

@@ -724,6 +726,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendDeleteImmutabilityPolicy() {
724726

725727
containerName := testcommon.GenerateContainerName(testName)
726728
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
729+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
727730

728731
abName := testcommon.GenerateBlobName(testName)
729732
abClient := createNewAppendBlob(context.Background(), _require, abName, containerClient)
@@ -756,6 +759,7 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendSetLegalHold() {
756759

757760
containerName := testcommon.GenerateContainerName(testName)
758761
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
762+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
759763

760764
abName := testcommon.GenerateBlobName(testName)
761765
abClient := createNewAppendBlob(context.Background(), _require, abName, containerClient)
@@ -2893,7 +2897,11 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetBlobTags() {
28932897
_, err = abClient.AppendBlock(context.Background(), streaming.NopCloser(strings.NewReader("Appending block\n")), nil)
28942898
_require.Nil(err)
28952899

2896-
_, err = abClient.SetTags(context.Background(), testcommon.BasicBlobTagsMap, nil)
2900+
var tagsMap = map[string]string{
2901+
"azure": "blob",
2902+
}
2903+
2904+
_, err = abClient.SetTags(context.Background(), tagsMap, nil)
28972905
_require.Nil(err)
28982906
time.Sleep(10 * time.Second)
28992907

@@ -2902,9 +2910,9 @@ func (s *AppendBlobRecordedTestsSuite) TestAppendBlobSetBlobTags() {
29022910

29032911
blobTagsSet := blobGetTagsResponse.BlobTagSet
29042912
_require.NotNil(blobTagsSet)
2905-
_require.Len(blobTagsSet, 3)
2913+
_require.Len(blobTagsSet, 1)
29062914
for _, blobTag := range blobTagsSet {
2907-
_require.Equal(testcommon.BasicBlobTagsMap[*blobTag.Key], *blobTag.Value)
2915+
_require.Equal(tagsMap[*blobTag.Key], *blobTag.Value)
29082916
}
29092917
}
29102918

sdk/storage/azblob/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "go",
44
"TagPrefix": "go/storage/azblob",
5-
"Tag": "go/storage/azblob_b92bf5d8e3"
5+
"Tag": "go/storage/azblob_cbcc92f524"
66
}

sdk/storage/azblob/blob/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,7 @@ func (s *BlobRecordedTestsSuite) TestSetImmutabilityPolicy() {
34393439

34403440
containerName := testcommon.GenerateContainerName(testName)
34413441
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3442+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
34423443

34433444
blockBlobName := testcommon.GenerateBlobName(testName)
34443445
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
@@ -3460,6 +3461,7 @@ func (s *BlobRecordedTestsSuite) TestSetImmutabilityPolicy() {
34603461

34613462
_, err = bbClient.Delete(context.Background(), nil)
34623463
_require.NotNil(err)
3464+
testcommon.ValidateBlobErrorCode(_require, err, bloberror.BlobImmutableDueToPolicy)
34633465

34643466
_, err = bbClient.DeleteImmutabilityPolicy(context.Background(), nil)
34653467
_require.Nil(err)
@@ -3476,6 +3478,7 @@ func (s *BlobRecordedTestsSuite) TestDeleteImmutabilityPolicy() {
34763478

34773479
containerName := testcommon.GenerateContainerName(testName)
34783480
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3481+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
34793482

34803483
blockBlobName := testcommon.GenerateBlobName(testName)
34813484
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
@@ -3508,6 +3511,7 @@ func (s *BlobRecordedTestsSuite) TestSetLegalHold() {
35083511

35093512
containerName := testcommon.GenerateContainerName(testName)
35103513
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3514+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
35113515

35123516
blockBlobName := testcommon.GenerateBlobName(testName)
35133517
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)

sdk/storage/azblob/blockblob/client_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ func (s *BlockBlobRecordedTestsSuite) TestUploadBlockWithImmutabilityPolicy() {
549549

550550
containerName := testcommon.GenerateContainerName(testName)
551551
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
552+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
552553

553554
blockBlobName := testcommon.GenerateBlobName(testName)
554555
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)
@@ -594,6 +595,7 @@ func (s *BlockBlobRecordedTestsSuite) TestPutBlockListWithImmutabilityPolicy() {
594595

595596
containerName := testcommon.GenerateContainerName(testName)
596597
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
598+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
597599

598600
blockBlobName := testcommon.GenerateBlobName(testName)
599601
bbClient := testcommon.CreateNewBlockBlob(context.Background(), _require, blockBlobName, containerClient)

sdk/storage/azblob/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ stages:
2626
parameters:
2727
ServiceDirectory: 'storage/azblob'
2828
RunLiveTests: true
29+
EnvVars:
30+
AZURE_CLIENT_ID: $(AZBLOB_CLIENT_ID)
31+
AZURE_TENANT_ID: $(AZBLOB_TENANT_ID)
32+
AZURE_CLIENT_SECRET: $(AZBLOB_CLIENT_SECRET)
33+
AZURE_SUBSCRIPTION_ID: $(AZBLOB_SUBSCRIPTION_ID)

sdk/storage/azblob/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0
77
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0
88
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0
9+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0
910
github.com/stretchr/testify v1.7.1
1011
)
1112

sdk/storage/azblob/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0 h1:QkAcEIAKbNL4KoFr4Sath
44
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0/go.mod h1:bhXu1AjYL+wutSL/kpSq6s7733q2Rb0yuot9Zgfqa/0=
55
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw=
66
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
7+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.0.0 h1:lMW1lD/17LUA5z1XTURo7LcVG2ICBPlyMHjIUrcFZNQ=
8+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8=
9+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0 h1:Ma67P/GGprNwsslzEH6+Kb8nybI8jpDTm4Wmzu2ReK8=
10+
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0/go.mod h1:c+Lifp3EDEamAkPVzMooRNOK6CZjNSdEnf1A7jsI9u4=
711
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 h1:BWe8a+f/t+7KY7zH2mqygeUD0t8hNFXe08p1Pb3/jKE=
812
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4=
913
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

sdk/storage/azblob/internal/testcommon/clients_auth.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"context"
1212
"errors"
1313
"fmt"
14+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
15+
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage"
1416
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"
1517
"strings"
1618
"testing"
@@ -46,6 +48,8 @@ const (
4648
AccountNameEnvVar = "AZURE_STORAGE_ACCOUNT_NAME"
4749
AccountKeyEnvVar = "AZURE_STORAGE_ACCOUNT_KEY"
4850
DefaultEndpointSuffixEnvVar = "AZURE_STORAGE_ENDPOINT_SUFFIX"
51+
SubscriptionID = "SUBSCRIPTION_ID"
52+
ResourceGroupName = "RESOURCE_GROUP_NAME"
4953
)
5054

5155
const (
@@ -364,3 +368,27 @@ func GetAccountSAS(permissions sas.AccountPermissions, resourceTypes sas.Account
364368

365369
return sasQueryParams.Encode(), nil
366370
}
371+
372+
func DeleteContainerUsingManagementClient(_require *require.Assertions, accountType TestAccountType, containerName string) {
373+
if recording.GetRecordMode() == recording.PlaybackMode {
374+
return
375+
}
376+
377+
accountName, err := GetRequiredEnv(string(accountType) + AccountNameEnvVar)
378+
_require.NoError(err)
379+
380+
subscriptionID, err := GetRequiredEnv(SubscriptionID)
381+
_require.NoError(err)
382+
383+
resourceGroupName, err := GetRequiredEnv(ResourceGroupName)
384+
_require.NoError(err)
385+
386+
cred, err := azidentity.NewDefaultAzureCredential(nil)
387+
_require.NoError(err)
388+
389+
managementClient, err := armstorage.NewBlobContainersClient(subscriptionID, cred, nil)
390+
_require.NoError(err)
391+
392+
_, err = managementClient.Delete(context.Background(), resourceGroupName, accountName, containerName, nil)
393+
_require.NoError(err)
394+
}

sdk/storage/azblob/pageblob/client_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,8 @@ func (s *PageBlobRecordedTestsSuite) TestPageSetImmutabilityPolicy() {
32883288

32893289
containerName := testcommon.GenerateContainerName(testName)
32903290
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3291+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
3292+
32913293
blobName := testcommon.GenerateBlobName(testName)
32923294
pbClient := createNewPageBlob(context.Background(), _require, blobName, containerClient)
32933295

@@ -3324,6 +3326,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageDeleteImmutabilityPolicy() {
33243326

33253327
containerName := testcommon.GenerateContainerName(testName)
33263328
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3329+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
33273330

33283331
blobName := testcommon.GenerateBlobName(testName)
33293332
pbClient := createNewPageBlob(context.Background(), _require, blobName, containerClient)
@@ -3356,6 +3359,7 @@ func (s *PageBlobRecordedTestsSuite) TestPageSetLegalHold() {
33563359

33573360
containerName := testcommon.GenerateContainerName(testName)
33583361
containerClient := testcommon.CreateNewContainer(context.Background(), _require, containerName, svcClient)
3362+
defer testcommon.DeleteContainerUsingManagementClient(_require, testcommon.TestAccountImmutable, containerName)
33593363

33603364
blobName := testcommon.GenerateBlobName(testName)
33613365
pbClient := createNewPageBlob(context.Background(), _require, blobName, containerClient)

0 commit comments

Comments
 (0)