Adding BlobDeleteType to Delete API (#291)

* Adding BlobDeleteType to Delete API

* Added test for soft delete and undelete

* Adding skip to this test as verisioning must be disabled in advance

* Permanent Delete method

* Updated test to run with alternate bsu

* Error handling in test

* Adding sleep in test

* Adding sleep after creation

* Improving test for Delete API

* Checking test

* Adding more sleeps

* Updating pipeline

* Break up tests

* Clean up, removing comments
This commit is contained in:
siminsavani-msft 2021-08-26 20:58:57 -04:00 коммит произвёл GitHub
Родитель 6996bcb207
Коммит ce5190c9fe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 100 добавлений и 0 удалений

Просмотреть файл

@ -143,6 +143,17 @@ func (b BlobURL) Delete(ctx context.Context, deleteOptions DeleteSnapshotsOption
nil, BlobDeleteNone)
}
// PermanentDelete permanently deletes soft-deleted snapshots & soft-deleted version blobs and is a dangerous operation and SHOULD NOT BE USED.
// WARNING: This operation should not be used unless you know exactly the implications. We will not provide support for this API.
// For more information, see https://docs.microsoft.com/rest/api/storageservices/delete-blob.
func (b BlobURL) PermanentDelete(ctx context.Context, deleteOptions DeleteSnapshotsOptionType, ac BlobAccessConditions) (*BlobDeleteResponse, error) {
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag := ac.ModifiedAccessConditions.pointers()
return b.blobClient.Delete(ctx, nil, nil, nil, ac.LeaseAccessConditions.pointers(), deleteOptions,
ifModifiedSince, ifUnmodifiedSince, ifMatchETag, ifNoneMatchETag,
nil, // Blob ifTags
nil, BlobDeletePermanent)
}
// SetTags operation enables users to set tags on a blob or specific blob version, but not snapshot.
// Each call to this operation replaces all existing tags attached to the blob.
// To remove all tags from the blob, call this operation with no tags set.

Просмотреть файл

@ -206,6 +206,95 @@ func (s *aztestsSuite) TestAccountListContainersMaxResultsSufficient(c *chk.C) {
c.Assert(len(response.ContainerItems) >= 2, chk.Equals, true)
}
func CreateBlobWithRetentionPolicy(c *chk.C) (BlockBlobURL, ContainerURL) {
bsu, err := getAlternateBSU()
c.Assert(err, chk.IsNil)
days := int32(5)
allowDelete := true
_, err = bsu.SetProperties(ctx, StorageServiceProperties{DeleteRetentionPolicy: &RetentionPolicy{Enabled: true, Days: &days, AllowPermanentDelete: &allowDelete}})
c.Assert(err, chk.IsNil)
// From FE, 30 seconds is guaranteed to be enough.
time.Sleep(time.Second * 30)
// create container and blobs
containerURL, _ := createNewContainer(c, bsu)
testSize := 8 * 1024
r, _ := getRandomDataAndReader(testSize)
blobURL, _ := getBlockBlobURL(c, containerURL)
cResp, err := blobURL.Upload(ctx, r, BlobHTTPHeaders{}, nil, BlobAccessConditions{}, DefaultAccessTier, nil, ClientProvidedKeyOptions{})
c.Assert(err, chk.IsNil)
c.Assert(cResp.StatusCode(), chk.Equals, 201)
return blobURL, containerURL
}
func (s *aztestsSuite) TestUndelete(c *chk.C) {
blobURL, containerURL := CreateBlobWithRetentionPolicy(c)
defer deleteContainer(c, containerURL)
// Soft delete blob
_, err := blobURL.Delete(ctx, DeleteSnapshotsOptionNone, BlobAccessConditions{}) //soft delete
c.Assert(err, chk.IsNil)
// Check that blob has been soft deleted
_, err = blobURL.GetProperties(ctx, BlobAccessConditions{}, ClientProvidedKeyOptions{})
c.Assert(err, chk.NotNil)
// Undelete soft deleted blob
undelResp, err := blobURL.Undelete(ctx)
c.Assert(err, chk.IsNil)
c.Assert(undelResp, chk.NotNil)
c.Assert(undelResp.StatusCode(), chk.Equals, 200)
blobProp, err := blobURL.GetProperties(ctx, BlobAccessConditions{}, ClientProvidedKeyOptions{})
c.Assert(blobProp.StatusCode(), chk.Equals, 200)
}
func (s *aztestsSuite) TestPermanentDelete(c *chk.C) {
blobURL, containerURL := CreateBlobWithRetentionPolicy(c)
defer deleteContainer(c, containerURL)
// Create snapshot for second blob
snapResp, err := blobURL.CreateSnapshot(ctx, Metadata{}, BlobAccessConditions{}, ClientProvidedKeyOptions{})
c.Assert(snapResp, chk.NotNil)
c.Assert(err, chk.IsNil)
// Check snapshot and blob exist
listBlobResp1, err := containerURL.ListBlobsFlatSegment(ctx, Marker{}, ListBlobsSegmentOptions{Details: BlobListingDetails{Snapshots: true}})
c.Assert(err, chk.IsNil)
c.Assert(listBlobResp1.Segment.BlobItems, chk.HasLen, 2)
// Soft delete snapshot
snapshotBlob := blobURL.WithSnapshot(snapResp.Snapshot())
_, err = snapshotBlob.Delete(ctx, DeleteSnapshotsOptionNone, BlobAccessConditions{})
c.Assert(err, chk.IsNil)
// Check that both blobs and snapshot exist
listBlobResp2, err := containerURL.ListBlobsFlatSegment(ctx, Marker{}, ListBlobsSegmentOptions{Details: BlobListingDetails{Deleted: true, Snapshots: true}})
c.Assert(err, chk.IsNil)
c.Assert(listBlobResp2.Segment.BlobItems, chk.HasLen, 2)
// Permanent delete snapshot
delResp, err := snapshotBlob.PermanentDelete(ctx, DeleteSnapshotsOptionNone, BlobAccessConditions{})
c.Assert(err, chk.IsNil)
c.Assert(delResp, chk.NotNil)
c.Assert(delResp.StatusCode(), chk.Equals, 202)
// Check that snapshot has been deleted
spBlobResp, err := snapshotBlob.GetProperties(ctx, BlobAccessConditions{}, ClientProvidedKeyOptions{})
c.Assert(err, chk.NotNil)
c.Assert(spBlobResp, chk.IsNil)
// Check that only blob exists
listBlobResp3, err := containerURL.ListBlobsFlatSegment(ctx, Marker{}, ListBlobsSegmentOptions{Details: BlobListingDetails{Deleted: true, Snapshots: true}})
c.Assert(err, chk.IsNil)
c.Assert(listBlobResp3.Segment.BlobItems, chk.HasLen, 1)
c.Assert(listBlobResp3.Segment.BlobItems[0].Deleted, chk.Equals, false)
}
func (s *aztestsSuite) TestAccountDeleteRetentionPolicy(c *chk.C) {
bsu := getBSU()