Storage test cases improvements (#4819)

* soft delete test

* enable setTierCold

* IsConnectionReuse in record-playback mode

* DISABLED_UploadPagesFromUriCrc64AccessCondition

* update recording assets

* ClientSecretCredentialWorks works in record-playback mode

* ServiceContainerSasPermissions and ServiceBlobSasPermissions work in record-playback mode

* BlobServiceClientTest.UserDelegationKey works in record-playback mode

* update recordings

* f
This commit is contained in:
JinmingHu 2023-07-27 11:25:21 +08:00 committed by GitHub
parent ce85f6f12c
commit e77eff6ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 33 deletions

View File

@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "cpp",
"TagPrefix": "cpp/storage",
"Tag": "cpp/storage_17c4a656fc"
"Tag": "cpp/storage_b920de0000"
}

View File

@ -170,7 +170,7 @@ namespace Azure { namespace Storage { namespace Test {
}
}
TEST_F(BlobSasTest, ServiceContainerSasPermissions_LIVEONLY_)
TEST_F(BlobSasTest, ServiceContainerSasPermissions)
{
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);
@ -184,7 +184,8 @@ namespace Azure { namespace Storage { namespace Test {
auto blobServiceClient = Blobs::BlobServiceClient(
m_blobServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret()));
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions()),
InitStorageClientOptions<Blobs::BlobClientOptions>());
userDelegationKey = blobServiceClient.GetUserDelegationKey(sasExpiresOn).Value;
}
@ -279,7 +280,7 @@ namespace Azure { namespace Storage { namespace Test {
}
}
TEST_F(BlobSasTest, ServiceBlobSasPermissions_LIVEONLY_)
TEST_F(BlobSasTest, ServiceBlobSasPermissions)
{
auto sasStartsOn = std::chrono::system_clock::now() - std::chrono::minutes(5);
auto sasExpiresOn = std::chrono::system_clock::now() + std::chrono::minutes(60);
@ -293,7 +294,8 @@ namespace Azure { namespace Storage { namespace Test {
auto blobServiceClient = Blobs::BlobServiceClient(
m_blobServiceClient->GetUrl(),
std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret()));
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions()),
InitStorageClientOptions<Blobs::BlobClientOptions>());
userDelegationKey = blobServiceClient.GetUserDelegationKey(sasExpiresOn).Value;
}

View File

@ -438,7 +438,7 @@ namespace Azure { namespace Storage { namespace Test {
containerClient.DeleteIfExists();
}
TEST_F(BlobServiceClientTest, UserDelegationKey_LIVEONLY_)
TEST_F(BlobServiceClientTest, UserDelegationKey)
{
auto serviceClient = *m_blobServiceClient;
@ -446,7 +446,7 @@ namespace Azure { namespace Storage { namespace Test {
std::shared_ptr<Azure::Core::Credentials::TokenCredential> credential
= std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(), AadClientId(), AadClientSecret());
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions());
Blobs::BlobClientOptions options;
InitStorageClientOptions(options);

View File

@ -76,28 +76,48 @@ namespace Azure { namespace Storage { namespace Test {
TEST_F(BlockBlobClientTest, SoftDelete)
{
const std::string blobName = m_blobName;
auto blobClient = *m_blockBlobClient;
auto clientOptions = InitStorageClientOptions<Blobs::BlobClientOptions>();
auto blobContainerClient
= Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
AdlsGen2ConnectionString(), LowercaseRandomString(), clientOptions);
blobContainerClient.CreateIfNotExists();
auto blobName = RandomString();
auto blobClient = blobContainerClient.GetBlockBlobClient(blobName);
std::vector<uint8_t> emptyContent;
auto blobContent = Azure::Core::IO::MemoryBodyStream(emptyContent.data(), emptyContent.size());
blobClient.Upload(blobContent);
blobClient.UploadFrom(nullptr, 0);
auto blobItem = GetBlobItem(blobName);
auto getBlobItem = [&]() {
Blobs::ListBlobsOptions options;
options.Prefix = blobName;
options.Include = Blobs::Models::ListBlobsIncludeFlags::Deleted;
for (auto page = blobContainerClient.ListBlobs(options); page.HasPage();
page.MoveToNextPage())
{
for (auto& blob : page.Blobs)
{
if (blob.Name == blobName)
{
return std::move(blob);
}
}
}
std::abort();
};
auto blobItem = getBlobItem();
EXPECT_FALSE(blobItem.IsDeleted);
EXPECT_FALSE(blobItem.Details.DeletedOn.HasValue());
EXPECT_FALSE(blobItem.Details.RemainingRetentionDays.HasValue());
blobClient.Delete();
/*
// Soft delete doesn't work in storage account with versioning enabled.
blobItem = GetBlobItem(blobName, Blobs::Models::ListBlobsIncludeFlags::Deleted);
blobItem = getBlobItem();
EXPECT_TRUE(blobItem.IsDeleted);
ASSERT_TRUE(blobItem.Details.DeletedOn.HasValue());
EXPECT_TRUE(IsValidTime(blobItem.Details.DeletedOn.Value()));
EXPECT_TRUE(blobItem.Details.RemainingRetentionDays.HasValue());
*/
blobContainerClient.Delete();
}
TEST_F(BlockBlobClientTest, SmallUploadDownload)
@ -798,7 +818,7 @@ namespace Azure { namespace Storage { namespace Test {
blobItem.Details.RehydratePriority.Value(), Blobs::Models::RehydratePriority::Standard);
}
TEST_F(BlockBlobClientTest, DISABLED_SetTierCold)
TEST_F(BlockBlobClientTest, SetTierCold)
{
m_blockBlobClient->SetAccessTier(Blobs::Models::AccessTier::Cold);
auto properties = m_blockBlobClient->GetProperties().Value;

View File

@ -7,7 +7,7 @@ namespace Azure { namespace Storage { namespace Test {
// If connection is reused, the requests with the same connection should hit the same sever. So
// this test verifies whether a series of requests hit the same server.
TEST_F(BlockBlobClientTest, IsConnectionReused_LIVEONLY_)
TEST_F(BlockBlobClientTest, IsConnectionReused)
{
const std::string containerName = LowercaseRandomString();
const std::string blobName = LowercaseRandomString();

View File

@ -344,16 +344,37 @@ namespace Azure { namespace Storage { namespace Test {
options2.TransactionalContentHash.Value().Value = contentMd5;
EXPECT_NO_THROW(pageBlobClient2.UploadPagesFromUri(
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2));
options2.TransactionalContentHash.Value().Algorithm = HashAlgorithm::Crc64;
options2.TransactionalContentHash.Value().Value
= Azure::Core::Convert::Base64Decode(DummyCrc64);
// EXPECT_THROW(
// pageBlobClient2.UploadPagesFromUri(
// 0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2),
// StorageException);
options2.TransactionalContentHash.Value().Value = contentCrc64;
}
TEST_F(PageBlobClientTest, DISABLED_UploadPagesFromUriCrc64AccessCondition)
{
auto pageBlobClient = *m_pageBlobClient;
std::vector<uint8_t> blobContent = RandomBuffer(static_cast<size_t>(4_KB));
const std::vector<uint8_t> contentCrc64
= Azure::Storage::Crc64Hash().Final(blobContent.data(), blobContent.size());
pageBlobClient.Create(blobContent.size());
auto contentStream = Azure::Core::IO::MemoryBodyStream(blobContent.data(), blobContent.size());
pageBlobClient.UploadPages(0, contentStream);
auto pageBlobClient2 = GetPageBlobClientTestForTest(RandomString());
pageBlobClient2.Create(blobContent.size());
Blobs::UploadPagesFromUriOptions options;
Azure::Core::Http::HttpRange sourceRange;
sourceRange.Offset = 0;
sourceRange.Length = blobContent.size();
options.TransactionalContentHash = ContentHash();
options.TransactionalContentHash.Value().Algorithm = HashAlgorithm::Crc64;
options.TransactionalContentHash.Value().Value = Azure::Core::Convert::Base64Decode(DummyCrc64);
EXPECT_THROW(
pageBlobClient2.UploadPagesFromUri(
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options),
StorageException);
options.TransactionalContentHash.Value().Value = contentCrc64;
EXPECT_NO_THROW(pageBlobClient2.UploadPagesFromUri(
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options2));
0, pageBlobClient.GetUrl() + GetSas(), sourceRange, options));
}
TEST_F(PageBlobClientTest, CreateIfNotExists)

View File

@ -5,16 +5,13 @@
namespace Azure { namespace Storage { namespace Test {
TEST_F(StorageTest, ClientSecretCredentialWorks_LIVEONLY_)
TEST_F(StorageTest, ClientSecretCredentialWorks)
{
const std::string containerName = LowercaseRandomString();
auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(
StandardStorageConnectionString(), containerName);
auto credential = std::make_shared<Azure::Identity::ClientSecretCredential>(
AadTenantId(),
AadClientId(),
AadClientSecret(),
InitStorageClientOptions<Core::Credentials::TokenCredentialOptions>());
AadTenantId(), AadClientId(), AadClientSecret(), GetTokenCredentialOptions());
containerClient = Blobs::BlobContainerClient(
containerClient.GetUrl(), credential, InitStorageClientOptions<Blobs::BlobClientOptions>());