diff --git a/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp b/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp index f56be2e50..2124f3967 100644 --- a/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp @@ -298,6 +298,14 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_EQ(res.Value.Details.Metadata, m_blobUploadOptions.Metadata); EXPECT_EQ(res.Value.BlobType, Azure::Storage::Blobs::Models::BlobType::BlockBlob); + std::string tempFilename = RandomString(); + EXPECT_NO_THROW(blockBlobClient.DownloadTo(tempFilename)); + EXPECT_TRUE(ReadFile(tempFilename).empty()); + DeleteFile(tempFilename); + + std::vector buff; + EXPECT_NO_THROW(blockBlobClient.DownloadTo(buff.data(), 0)); + Azure::Storage::Blobs::DownloadBlobOptions options; options.Range = Core::Http::HttpRange(); options.Range.Value().Offset = 0; diff --git a/sdk/storage/azure-storage-common/test/test_base.cpp b/sdk/storage/azure-storage-common/test/test_base.cpp index 93ae9ac04..221151052 100644 --- a/sdk/storage/azure-storage-common/test/test_base.cpp +++ b/sdk/storage/azure-storage-common/test/test_base.cpp @@ -209,8 +209,6 @@ namespace Azure { namespace Storage { namespace Test { Storage::Metadata result; for (size_t i = 0; i < size; ++i) { - // TODO: Use mixed casing after Azure::Core lower cases the headers. - // Metadata keys cannot start with a number. result["m" + LowercaseRandomString(5)] = RandomString(5); } return result; diff --git a/sdk/storage/azure-storage-files-datalake/test/datalake_directory_client_test.cpp b/sdk/storage/azure-storage-files-datalake/test/datalake_directory_client_test.cpp index 6842fc411..327ab60b3 100644 --- a/sdk/storage/azure-storage-files-datalake/test/datalake_directory_client_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/datalake_directory_client_test.cpp @@ -18,7 +18,7 @@ namespace Azure { namespace Storage { namespace Test { void DataLakeDirectoryClientTest::SetUpTestSuite() { DataLakeFileSystemClientTest::SetUpTestSuite(); - m_directoryName = RandomString(10); + m_directoryName = RandomString(); m_directoryClient = std::make_shared( m_fileSystemClient->GetDirectoryClient(m_directoryName)); m_fileSystemClient->GetFileClient(m_directoryName).Create(); @@ -636,7 +636,7 @@ namespace Azure { namespace Storage { namespace Test { { // Create from connection string validates static creator function and shared key // constructor. - auto directoryName = RandomString(10); + auto directoryName = RandomString(); auto connectionStringClient = Azure::Storage::Files::DataLake::DataLakeDirectoryClient::CreateFromConnectionString( AdlsGen2ConnectionString(), m_fileSystemName, directoryName); @@ -652,7 +652,7 @@ namespace Azure { namespace Storage { namespace Test { auto clientSecretClient = Azure::Storage::Files::DataLake::DataLakeDirectoryClient( Azure::Storage::Files::DataLake::_detail::GetDfsUrlFromUrl( Azure::Storage::Files::DataLake::DataLakeDirectoryClient::CreateFromConnectionString( - AdlsGen2ConnectionString(), m_fileSystemName, RandomString(10)) + AdlsGen2ConnectionString(), m_fileSystemName, RandomString()) .GetUrl()), credential); @@ -662,7 +662,7 @@ namespace Azure { namespace Storage { namespace Test { { // Create from Anonymous credential. - auto objectName = RandomString(10); + auto objectName = RandomString(); auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString( AdlsGen2ConnectionString(), m_fileSystemName); Azure::Storage::Blobs::SetBlobContainerAccessPolicyOptions options; diff --git a/sdk/storage/azure-storage-files-datalake/test/datalake_file_client_test.cpp b/sdk/storage/azure-storage-files-datalake/test/datalake_file_client_test.cpp index 7f44c37ef..a2706601a 100644 --- a/sdk/storage/azure-storage-files-datalake/test/datalake_file_client_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/datalake_file_client_test.cpp @@ -33,7 +33,7 @@ namespace Azure { namespace Storage { namespace Test { void DataLakeFileClientTest::SetUpTestSuite() { DataLakeFileSystemClientTest::SetUpTestSuite(); - m_fileName = RandomString(10); + m_fileName = RandomString(); m_fileClient = std::make_shared( m_fileSystemClient->GetFileClient(m_fileName)); m_fileClient->Create(); @@ -247,7 +247,7 @@ namespace Azure { namespace Storage { namespace Test { auto buffer = RandomBuffer(bufferSize); auto bufferStream = std::make_unique( Azure::Core::IO::MemoryBodyStream(buffer)); - auto newFileName = RandomString(10); + auto newFileName = RandomString(); auto newFileClient = std::make_shared( m_fileSystemClient->GetFileClient(newFileName)); newFileClient->Create(); @@ -329,6 +329,23 @@ namespace Azure { namespace Storage { namespace Test { } } + TEST_F(DataLakeFileClientTest, ReadEmptyFile) + { + auto fileClient = m_fileSystemClient->GetFileClient(RandomString()); + fileClient.Create(); + + auto res = fileClient.Download(); + EXPECT_EQ(res.Value.Body->Length(), 0); + + std::string tempFilename = RandomString(); + EXPECT_NO_THROW(fileClient.DownloadTo(tempFilename)); + EXPECT_TRUE(ReadFile(tempFilename).empty()); + DeleteFile(tempFilename); + + std::vector buff; + EXPECT_NO_THROW(fileClient.DownloadTo(buff.data(), 0)); + } + TEST_F(DataLakeFileClientTest, ScheduleForDeletion) { { @@ -464,7 +481,7 @@ namespace Azure { namespace Storage { namespace Test { { // Create from connection string validates static creator function and shared key // constructor. - auto fileName = RandomString(10); + auto fileName = RandomString(); auto connectionStringClient = Azure::Storage::Files::DataLake::DataLakeFileClient::CreateFromConnectionString( AdlsGen2ConnectionString(), m_fileSystemName, fileName); @@ -480,7 +497,7 @@ namespace Azure { namespace Storage { namespace Test { auto clientSecretClient = Azure::Storage::Files::DataLake::DataLakeFileClient( Azure::Storage::Files::DataLake::_detail::GetDfsUrlFromUrl( Azure::Storage::Files::DataLake::DataLakeFileClient::CreateFromConnectionString( - AdlsGen2ConnectionString(), m_fileSystemName, RandomString(10)) + AdlsGen2ConnectionString(), m_fileSystemName, RandomString()) .GetUrl()), credential); @@ -493,7 +510,7 @@ namespace Azure { namespace Storage { namespace Test { std::vector blobContent; blobContent.resize(static_cast(1_MB)); RandomBuffer(reinterpret_cast(&blobContent[0]), blobContent.size()); - auto objectName = RandomString(10); + auto objectName = RandomString(); auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString( AdlsGen2ConnectionString(), m_fileSystemName); Azure::Storage::Blobs::SetBlobContainerAccessPolicyOptions options; diff --git a/sdk/storage/azure-storage-files-datalake/test/datalake_file_system_client_test.cpp b/sdk/storage/azure-storage-files-datalake/test/datalake_file_system_client_test.cpp index 19d2d1f11..f949d1d47 100644 --- a/sdk/storage/azure-storage-files-datalake/test/datalake_file_system_client_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/datalake_file_system_client_test.cpp @@ -30,19 +30,19 @@ namespace Azure { namespace Storage { namespace Test { m_dataLakeServiceClient->GetFileSystemClient(m_fileSystemName)); m_fileSystemClient->Create(); - m_directoryA = LowercaseRandomString(); - m_directoryB = LowercaseRandomString(); + m_directoryA = RandomString(); + m_directoryB = RandomString(); m_pathNameSetA.clear(); m_pathNameSetB.clear(); for (size_t i = 0; i < PathTestSize; ++i) { { - auto name = m_directoryA + "/" + LowercaseRandomString(); + auto name = m_directoryA + "/" + RandomString(); m_fileSystemClient->GetFileClient(name).Create(); m_pathNameSetA.emplace_back(std::move(name)); } { - auto name = m_directoryB + "/" + LowercaseRandomString(); + auto name = m_directoryB + "/" + RandomString(); m_fileSystemClient->GetFileClient(name).Create(); m_pathNameSetB.emplace_back(std::move(name)); } @@ -328,7 +328,7 @@ namespace Azure { namespace Storage { namespace Test { { { // Create from connection string validates static creator function and shared key constructor. - auto fileSystemName = LowercaseRandomString(10); + auto fileSystemName = LowercaseRandomString(); auto connectionStringClient = Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString( AdlsGen2ConnectionString(), fileSystemName); @@ -343,7 +343,7 @@ namespace Azure { namespace Storage { namespace Test { auto clientSecretClient = Azure::Storage::Files::DataLake::DataLakeFileSystemClient( Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString( - AdlsGen2ConnectionString(), LowercaseRandomString(10)) + AdlsGen2ConnectionString(), LowercaseRandomString()) .GetUrl(), credential); diff --git a/sdk/storage/azure-storage-files-datalake/test/datalake_path_client_test.cpp b/sdk/storage/azure-storage-files-datalake/test/datalake_path_client_test.cpp index 15844eac0..477c645b0 100644 --- a/sdk/storage/azure-storage-files-datalake/test/datalake_path_client_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/datalake_path_client_test.cpp @@ -16,7 +16,7 @@ namespace Azure { namespace Storage { namespace Test { void DataLakePathClientTest::SetUpTestSuite() { DataLakeFileSystemClientTest::SetUpTestSuite(); - m_pathName = LowercaseRandomString(10); + m_pathName = RandomString(); m_pathClient = std::make_shared( m_fileSystemClient->GetFileClient(m_pathName)); m_fileSystemClient->GetFileClient(m_pathName).Create(); @@ -73,8 +73,8 @@ namespace Azure { namespace Storage { namespace Test { { // Create path with metadata works - auto client1 = m_fileSystemClient->GetFileClient(LowercaseRandomString()); - auto client2 = m_fileSystemClient->GetFileClient(LowercaseRandomString()); + auto client1 = m_fileSystemClient->GetFileClient(RandomString()); + auto client2 = m_fileSystemClient->GetFileClient(RandomString()); Files::DataLake::CreatePathOptions options1; Files::DataLake::CreatePathOptions options2; options1.Metadata = metadata1; @@ -127,7 +127,7 @@ namespace Azure { namespace Storage { namespace Test { std::vector pathClient; for (int32_t i = 0; i < 2; ++i) { - auto client = m_fileSystemClient->GetFileClient(LowercaseRandomString()); + auto client = m_fileSystemClient->GetFileClient(RandomString()); Files::DataLake::CreatePathOptions options; options.HttpHeaders = httpHeader; EXPECT_NO_THROW(client.Create(options)); @@ -149,7 +149,7 @@ namespace Azure { namespace Storage { namespace Test { std::vector pathClient; for (int32_t i = 0; i < 2; ++i) { - auto client = m_fileSystemClient->GetFileClient(LowercaseRandomString()); + auto client = m_fileSystemClient->GetFileClient(RandomString()); EXPECT_NO_THROW(client.Create()); EXPECT_NO_THROW(client.SetHttpHeaders(httpHeader)); pathClient.emplace_back(std::move(client)); @@ -349,7 +349,7 @@ namespace Azure { namespace Storage { namespace Test { { { // Create from connection string validates static creator function and shared key constructor. - auto pathName = LowercaseRandomString(10); + auto pathName = RandomString(); auto connectionStringClient = Azure::Storage::Files::DataLake::DataLakePathClient::CreateFromConnectionString( AdlsGen2ConnectionString(), m_fileSystemName, pathName); @@ -366,7 +366,7 @@ namespace Azure { namespace Storage { namespace Test { auto clientSecretClient = Azure::Storage::Files::DataLake::DataLakePathClient( Files::DataLake::_detail::GetDfsUrlFromUrl( Azure::Storage::Files::DataLake::DataLakePathClient::CreateFromConnectionString( - AdlsGen2ConnectionString(), m_fileSystemName, LowercaseRandomString(10)) + AdlsGen2ConnectionString(), m_fileSystemName, RandomString()) .GetUrl()), credential); @@ -376,7 +376,7 @@ namespace Azure { namespace Storage { namespace Test { { // Create from Anonymous credential. - auto objectName = LowercaseRandomString(10); + auto objectName = RandomString(); auto containerClient = Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString( AdlsGen2ConnectionString(), m_fileSystemName); Azure::Storage::Blobs::SetBlobContainerAccessPolicyOptions options; diff --git a/sdk/storage/azure-storage-files-datalake/test/datalake_service_client_test.cpp b/sdk/storage/azure-storage-files-datalake/test/datalake_service_client_test.cpp index 073c5cd70..fcffa7d3f 100644 --- a/sdk/storage/azure-storage-files-datalake/test/datalake_service_client_test.cpp +++ b/sdk/storage/azure-storage-files-datalake/test/datalake_service_client_test.cpp @@ -22,19 +22,19 @@ namespace Azure { namespace Storage { namespace Test { m_dataLakeServiceClient = std::make_shared( Files::DataLake::DataLakeServiceClient::CreateFromConnectionString( AdlsGen2ConnectionString())); - m_fileSystemPrefixA = LowercaseRandomString(10); - m_fileSystemPrefixB = LowercaseRandomString(10); + m_fileSystemPrefixA = LowercaseRandomString(); + m_fileSystemPrefixB = LowercaseRandomString(); m_fileSystemNameSetA.clear(); m_fileSystemNameSetB.clear(); for (size_t i = 0; i < FileSystemTestSize; ++i) { { - auto name = m_fileSystemPrefixA + LowercaseRandomString(10); + auto name = m_fileSystemPrefixA + LowercaseRandomString(); m_dataLakeServiceClient->GetFileSystemClient(name).Create(); m_fileSystemNameSetA.emplace_back(std::move(name)); } { - auto name = m_fileSystemPrefixB + LowercaseRandomString(10); + auto name = m_fileSystemPrefixB + LowercaseRandomString(); m_dataLakeServiceClient->GetFileSystemClient(name).Create(); m_fileSystemNameSetB.emplace_back(std::move(name)); } diff --git a/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp index 5248ee9ae..a350321a0 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_client_test.cpp @@ -412,7 +412,7 @@ namespace Azure { namespace Storage { namespace Test { // Set properties works { auto shareClient = Files::Shares::ShareClient::CreateFromConnectionString( - StandardStorageConnectionString(), LowercaseRandomString(10)); + StandardStorageConnectionString(), LowercaseRandomString()); auto options = Files::Shares::CreateShareOptions(); options.AccessTier = Files::Shares::Models::AccessTier::Cool; EXPECT_NO_THROW(shareClient.Create(options)); @@ -469,7 +469,7 @@ namespace Azure { namespace Storage { namespace Test { TEST_F(FileShareClientTest, PremiumShare) { - auto shareName = LowercaseRandomString(10); + auto shareName = LowercaseRandomString(); auto shareClient = Files::Shares::ShareClient::CreateFromConnectionString( PremiumFileConnectionString(), shareName); EXPECT_NO_THROW(shareClient.Create()); diff --git a/sdk/storage/azure-storage-files-shares/test/share_directory_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_directory_client_test.cpp index e7afc7fbb..fc45d9e16 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_directory_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_directory_client_test.cpp @@ -14,7 +14,7 @@ namespace Azure { namespace Storage { namespace Test { void FileShareDirectoryClientTest::SetUpTestSuite() { - m_directoryName = LowercaseRandomString(); + m_directoryName = RandomString(); m_shareName = LowercaseRandomString(); m_shareClient = std::make_shared( Files::Shares::ShareClient::CreateFromConnectionString( @@ -77,7 +77,7 @@ namespace Azure { namespace Storage { namespace Test { std::vector directoryClients; for (int32_t i = 0; i < 5; ++i) { - auto name = RandomString(10); + auto name = RandomString(); Files::Shares::ShareDirectoryClient client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(name); EXPECT_NO_THROW(client.Create()); @@ -93,7 +93,7 @@ namespace Azure { namespace Storage { namespace Test { // Create directory that already exist throws. for (int32_t i = 0; i < 5; ++i) { - auto name = RandomString(10); + auto name = RandomString(); Files::Shares::ShareDirectoryClient client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(name); EXPECT_NO_THROW(client.Create()); @@ -103,23 +103,20 @@ namespace Azure { namespace Storage { namespace Test { { // CreateIfNotExists & DeleteIfExists. { - auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient( - LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); EXPECT_NO_THROW(client.Create()); EXPECT_NO_THROW(client.CreateIfNotExists()); EXPECT_NO_THROW(client.Delete()); EXPECT_NO_THROW(client.DeleteIfExists()); } { - auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient( - LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); EXPECT_NO_THROW(client.CreateIfNotExists()); EXPECT_THROW(client.Create(), StorageException); EXPECT_NO_THROW(client.DeleteIfExists()); } { - auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient( - LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); auto created = client.Create().Value.Created; EXPECT_TRUE(created); auto createResult = client.CreateIfNotExists(); @@ -130,23 +127,21 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_TRUE(deleted); } { - auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient( - LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); auto deleteResult = client.DeleteIfExists(); EXPECT_FALSE(deleteResult.Value.Deleted); } { auto shareClient = Files::Shares::ShareClient::CreateFromConnectionString( StandardStorageConnectionString(), LowercaseRandomString()); - auto client - = shareClient.GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client = shareClient.GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); auto deleteResult = client.DeleteIfExists(); EXPECT_FALSE(deleteResult.Value.Deleted); } { auto client = m_shareClient->GetRootDirectoryClient() - .GetSubdirectoryClient(LowercaseRandomString()) - .GetSubdirectoryClient(LowercaseRandomString()); + .GetSubdirectoryClient(RandomString()) + .GetSubdirectoryClient(RandomString()); auto deleteResult = client.DeleteIfExists(); EXPECT_FALSE(deleteResult.Value.Deleted); } @@ -169,10 +164,8 @@ namespace Azure { namespace Storage { namespace Test { { // Create directory with metadata works - auto client1 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); - auto client2 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client1 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); + auto client2 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); Files::Shares::CreateDirectoryOptions options1; Files::Shares::CreateDirectoryOptions options2; options1.Metadata = metadata1; @@ -195,10 +188,8 @@ namespace Azure { namespace Storage { namespace Test { { // Create directory with permission/permission key works - auto client1 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); - auto client2 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client1 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); + auto client2 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); Files::Shares::CreateDirectoryOptions options1; Files::Shares::CreateDirectoryOptions options2; options1.DirectoryPermission = permission; @@ -210,8 +201,7 @@ namespace Azure { namespace Storage { namespace Test { auto result2 = client2.GetProperties().Value.SmbProperties.PermissionKey; EXPECT_EQ(result1.Value(), result2.Value()); - auto client3 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client3 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); Files::Shares::CreateDirectoryOptions options3; options3.SmbProperties.PermissionKey = result1; EXPECT_NO_THROW(client3.Create(options3)); @@ -227,10 +217,8 @@ namespace Azure { namespace Storage { namespace Test { properties.CreatedOn = std::chrono::system_clock::now(); properties.LastWrittenOn = std::chrono::system_clock::now(); properties.PermissionKey = ""; - auto client1 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); - auto client2 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client1 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); + auto client2 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); EXPECT_NO_THROW(client1.Create()); EXPECT_NO_THROW(client2.Create()); @@ -244,8 +232,7 @@ namespace Azure { namespace Storage { namespace Test { auto result2 = client2.GetProperties().Value.SmbProperties.PermissionKey; EXPECT_EQ(result1.Value(), result2.Value()); - auto client3 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client3 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); Files::Shares::CreateDirectoryOptions options3; options3.SmbProperties.PermissionKey = result1; std::string permissionKey; @@ -267,10 +254,8 @@ namespace Azure { namespace Storage { namespace Test { = m_fileShareDirectoryClient->GetProperties().Value.SmbProperties.PermissionKey; { // Create directory with SmbProperties works - auto client1 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); - auto client2 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client1 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); + auto client2 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); Files::Shares::CreateDirectoryOptions options1; Files::Shares::CreateDirectoryOptions options2; options1.SmbProperties = properties; @@ -293,10 +278,8 @@ namespace Azure { namespace Storage { namespace Test { { // SetProperties works - auto client1 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); - auto client2 - = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(LowercaseRandomString()); + auto client1 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); + auto client2 = m_shareClient->GetRootDirectoryClient().GetSubdirectoryClient(RandomString()); EXPECT_NO_THROW(client1.Create()); EXPECT_NO_THROW(client2.Create()); @@ -343,8 +326,8 @@ namespace Azure { namespace Storage { namespace Test { TEST_F(FileShareDirectoryClientTest, ListFilesAndDirectoriesSinglePageTest) { // Setup - auto directoryNameA = LowercaseRandomString(); - auto directoryNameB = LowercaseRandomString(); + auto directoryNameA = RandomString(); + auto directoryNameB = RandomString(); std::vector directoryNameSetA; std::vector directoryNameSetB; std::vector fileNameSetA; @@ -356,16 +339,16 @@ namespace Azure { namespace Storage { namespace Test { for (size_t i = 0; i < 5; ++i) { { - auto directoryName = LowercaseRandomString(); - auto fileName = LowercaseRandomString(); + auto directoryName = RandomString(); + auto fileName = RandomString(); EXPECT_NO_THROW(clientA.GetSubdirectoryClient(directoryName).Create()); EXPECT_NO_THROW(clientA.GetFileClient(fileName).Create(1024)); directoryNameSetA.emplace_back(std::move(directoryName)); fileNameSetA.emplace_back(std::move(fileName)); } { - auto directoryName = LowercaseRandomString(); - auto fileName = LowercaseRandomString(); + auto directoryName = RandomString(); + auto fileName = RandomString(); EXPECT_NO_THROW(clientB.GetSubdirectoryClient(directoryName).Create()); EXPECT_NO_THROW(clientB.GetFileClient(fileName).Create(1024)); directoryNameSetB.emplace_back(std::move(directoryName)); diff --git a/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp index f75382719..62407d09a 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_file_client_test.cpp @@ -20,9 +20,9 @@ namespace Azure { namespace Storage { namespace Test { void FileShareFileClientTest::SetUpTestSuite() { - m_directoryName = LowercaseRandomString(); + m_directoryName = RandomString(); m_shareName = LowercaseRandomString(); - m_fileName = LowercaseRandomString(); + m_fileName = RandomString(); m_shareClient = std::make_shared( Files::Shares::ShareClient::CreateFromConnectionString( StandardStorageConnectionString(), m_shareName)); @@ -49,7 +49,7 @@ namespace Azure { namespace Storage { namespace Test { std::vector fileClients; for (int32_t i = 0; i < 5; ++i) { - auto fileName = RandomString(10); + auto fileName = RandomString(); Files::Shares::ShareFileClient client = m_fileShareDirectoryClient->GetFileClient(fileName); EXPECT_NO_THROW(client.Create(1024)); fileClients.emplace_back(std::move(client)); @@ -72,36 +72,50 @@ namespace Azure { namespace Storage { namespace Test { { // DeleteIfExists. { - auto client - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); EXPECT_NO_THROW(client.Create(1024)); EXPECT_NO_THROW(client.Delete()); EXPECT_NO_THROW(client.DeleteIfExists()); } { - auto client - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); auto deleteResult = client.DeleteIfExists(); EXPECT_FALSE(deleteResult.Value.Deleted); } { auto shareClient = Files::Shares::ShareClient::CreateFromConnectionString( StandardStorageConnectionString(), LowercaseRandomString()); - auto client - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString()); + auto client = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); auto deleteResult = client.DeleteIfExists(); EXPECT_FALSE(deleteResult.Value.Deleted); } { auto client = m_shareClient->GetRootDirectoryClient() - .GetSubdirectoryClient(LowercaseRandomString()) - .GetFileClient(LowercaseRandomString()); + .GetSubdirectoryClient(RandomString()) + .GetFileClient(RandomString()); auto deleteResult = client.DeleteIfExists(); EXPECT_FALSE(deleteResult.Value.Deleted); } } } + TEST_F(FileShareFileClientTest, DownloadEmptyFile) + { + auto fileClient = m_fileShareDirectoryClient->GetFileClient(RandomString()); + fileClient.Create(0); + + auto res = fileClient.Download(); + EXPECT_EQ(res.Value.BodyStream->Length(), 0); + + std::string tempFilename = RandomString(); + EXPECT_NO_THROW(fileClient.DownloadTo(tempFilename)); + EXPECT_TRUE(ReadFile(tempFilename).empty()); + DeleteFile(tempFilename); + + std::vector buff; + EXPECT_NO_THROW(fileClient.DownloadTo(buff.data(), 0)); + } + TEST_F(FileShareFileClientTest, FileMetadata) { auto metadata1 = RandomMetadata(); @@ -118,8 +132,8 @@ namespace Azure { namespace Storage { namespace Test { { // Create directory with metadata works - auto client1 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); - auto client2 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client1 = m_fileShareDirectoryClient->GetFileClient(RandomString()); + auto client2 = m_fileShareDirectoryClient->GetFileClient(RandomString()); Files::Shares::CreateFileOptions options1; Files::Shares::CreateFileOptions options2; options1.Metadata = metadata1; @@ -142,8 +156,8 @@ namespace Azure { namespace Storage { namespace Test { { // Create directory with permission/permission key works - auto client1 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); - auto client2 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client1 = m_fileShareDirectoryClient->GetFileClient(RandomString()); + auto client2 = m_fileShareDirectoryClient->GetFileClient(RandomString()); Files::Shares::CreateFileOptions options1; Files::Shares::CreateFileOptions options2; options1.Permission = permission; @@ -157,7 +171,7 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_TRUE(result2.HasValue()); EXPECT_EQ(result1.Value(), result2.Value()); - auto client3 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client3 = m_fileShareDirectoryClient->GetFileClient(RandomString()); Files::Shares::CreateFileOptions options3; options3.SmbProperties.PermissionKey = result1; EXPECT_NO_THROW(client3.Create(1024, options3)); @@ -174,8 +188,8 @@ namespace Azure { namespace Storage { namespace Test { properties.CreatedOn = std::chrono::system_clock::now(); properties.LastWrittenOn = std::chrono::system_clock::now(); properties.PermissionKey = ""; - auto client1 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); - auto client2 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client1 = m_fileShareDirectoryClient->GetFileClient(RandomString()); + auto client2 = m_fileShareDirectoryClient->GetFileClient(RandomString()); EXPECT_NO_THROW(client1.Create(1024)); EXPECT_NO_THROW(client2.Create(1024)); @@ -191,7 +205,7 @@ namespace Azure { namespace Storage { namespace Test { EXPECT_TRUE(result2.HasValue()); EXPECT_EQ(result1.Value(), result2.Value()); - auto client3 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client3 = m_fileShareDirectoryClient->GetFileClient(RandomString()); Files::Shares::CreateFileOptions options3; options3.SmbProperties.PermissionKey = result1; std::string permissionKey; @@ -213,8 +227,8 @@ namespace Azure { namespace Storage { namespace Test { properties.PermissionKey = m_fileClient->GetProperties().Value.SmbProperties.PermissionKey; { // Create directory with SmbProperties works - auto client1 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); - auto client2 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client1 = m_fileShareDirectoryClient->GetFileClient(RandomString()); + auto client2 = m_fileShareDirectoryClient->GetFileClient(RandomString()); Files::Shares::CreateFileOptions options1; Files::Shares::CreateFileOptions options2; options1.SmbProperties = properties; @@ -237,8 +251,8 @@ namespace Azure { namespace Storage { namespace Test { { // SetProperties works - auto client1 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); - auto client2 = m_fileShareDirectoryClient->GetFileClient(LowercaseRandomString()); + auto client1 = m_fileShareDirectoryClient->GetFileClient(RandomString()); + auto client2 = m_fileShareDirectoryClient->GetFileClient(RandomString()); EXPECT_NO_THROW(client1.Create(1024)); EXPECT_NO_THROW(client2.Create(1024)); @@ -638,12 +652,6 @@ namespace Azure { namespace Storage { namespace Test { } } - static std::vector Hash(const std::string& data) - { - Azure::Core::Cryptography::Md5Hash instance; - return instance.Final(reinterpret_cast(data.data()), data.size()); - } - TEST_F(FileShareFileClientTest, RangeUploadDownload) { auto rangeSize = 1 * 1024 * 1024; @@ -652,8 +660,7 @@ namespace Azure { namespace Storage { namespace Test { auto memBodyStream = Core::IO::MemoryBodyStream(rangeContent); { // Simple upload/download. - auto fileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); fileClient.Create(static_cast(numOfChunks) * rangeSize); for (int32_t i = 0; i < numOfChunks; ++i) { @@ -682,9 +689,7 @@ namespace Azure { namespace Storage { namespace Test { memBodyStream.Rewind(); Azure::Core::Cryptography::Md5Hash instance; auto md5 = instance.Final(rangeContent.data(), rangeContent.size()); - auto invalidMd5 = Hash(std::string("This is garbage.")); - auto fileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); Files::Shares::UploadFileRangeOptions uploadOptions; fileClient.Create(static_cast(numOfChunks) * rangeSize); ContentHash hash; @@ -692,7 +697,7 @@ namespace Azure { namespace Storage { namespace Test { hash.Algorithm = HashAlgorithm::Md5; uploadOptions.TransactionalContentHash = hash; EXPECT_NO_THROW(fileClient.UploadRange(0, memBodyStream, uploadOptions)); - hash.Value = invalidMd5; + hash.Value = Azure::Core::Convert::Base64Decode(DummyMd5); uploadOptions.TransactionalContentHash = hash; memBodyStream.Rewind(); EXPECT_THROW(fileClient.UploadRange(0, memBodyStream, uploadOptions), StorageException); @@ -706,12 +711,10 @@ namespace Azure { namespace Storage { namespace Test { auto memBodyStream = Core::IO::MemoryBodyStream(fileContent); { // Simple copy works. - auto fileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); fileClient.Create(fileSize); - auto destFileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto destFileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); auto copyOperation = destFileClient.StartCopy(fileClient.GetUrl()); EXPECT_EQ( copyOperation.GetRawResponse().GetStatusCode(), @@ -722,12 +725,10 @@ namespace Azure { namespace Storage { namespace Test { { // Copy mode with override and empty permission throws error.. - auto fileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); fileClient.Create(fileSize); - auto destFileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto destFileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); } } @@ -739,8 +740,7 @@ namespace Azure { namespace Storage { namespace Test { auto halfContent = std::vector(fileContent.begin(), fileContent.begin() + fileSize / 2); halfContent.resize(fileSize); - auto fileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); fileClient.Create(fileSize); EXPECT_NO_THROW(fileClient.UploadRange(0, memBodyStream)); EXPECT_NO_THROW(fileClient.ClearRange(fileSize / 2, fileSize / 2)); @@ -768,8 +768,7 @@ namespace Azure { namespace Storage { namespace Test { auto halfContent = std::vector(fileContent.begin(), fileContent.begin() + fileSize / 2); halfContent.resize(fileSize); - auto fileClient - = m_shareClient->GetRootDirectoryClient().GetFileClient(LowercaseRandomString(10)); + auto fileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); fileClient.Create(fileSize); EXPECT_NO_THROW(fileClient.UploadRange(0, memBodyStream)); EXPECT_NO_THROW(fileClient.ClearRange(fileSize / 2, fileSize / 2)); @@ -868,7 +867,7 @@ namespace Azure { namespace Storage { namespace Test { sourceFileClient.Create(fileSize); EXPECT_NO_THROW(sourceFileClient.UploadRange(0, memBodyStream)); - auto destFileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString(10)); + auto destFileClient = m_shareClient->GetRootDirectoryClient().GetFileClient(RandomString()); destFileClient.Create(fileSize * 4); Azure::Core::Http::HttpRange sourceRange; Azure::Core::Http::HttpRange destRange; diff --git a/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp b/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp index 8758d9569..6beff495d 100644 --- a/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp +++ b/sdk/storage/azure-storage-files-shares/test/share_service_client_test.cpp @@ -30,19 +30,19 @@ namespace Azure { namespace Storage { namespace Test { m_fileShareServiceClient = std::make_shared( Files::Shares::ShareServiceClient::CreateFromConnectionString( StandardStorageConnectionString())); - m_sharePrefixA = LowercaseRandomString(10); - m_sharePrefixB = LowercaseRandomString(10); + m_sharePrefixA = LowercaseRandomString(); + m_sharePrefixB = LowercaseRandomString(); m_shareNameSetA.clear(); m_shareNameSetB.clear(); for (size_t i = 0; i < ShareTestSize; ++i) { { - auto name = m_sharePrefixA + LowercaseRandomString(10); + auto name = m_sharePrefixA + LowercaseRandomString(); m_fileShareServiceClient->GetShareClient(name).Create(); m_shareNameSetA.emplace_back(std::move(name)); } { - auto name = m_sharePrefixB + LowercaseRandomString(10); + auto name = m_sharePrefixB + LowercaseRandomString(); m_fileShareServiceClient->GetShareClient(name).Create(); m_shareNameSetB.emplace_back(std::move(name)); }