Skip to content

Commit

Permalink
Remove linking azure-storage-blobs in azure-data-tables tests and dec…
Browse files Browse the repository at this point in the history
…ouple storage-common test base from blobs (#6141)

* Remove linking azure-storage-blobs in azure-data-tables tests

* Decouple storage-common tests and blobs by removing some dependency.

* Remove dependency in test_base.hpp on certain headers from storage-common that aren't needed.

* Remove pragma once that weren't needed, and reduce the blobs headers included to the specific ones.

* Fix the copy/paste typo for account types in test_base.
  • Loading branch information
ahsonkhan authored Oct 31, 2024
1 parent 99e0895 commit 57cc679
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@

namespace Azure { namespace Storage { namespace Blobs { namespace Models {

bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs);
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs)
{
return lhs.Id == rhs.Id && lhs.StartsOn.HasValue() == rhs.StartsOn.HasValue()
&& (!lhs.StartsOn.HasValue() || lhs.StartsOn.Value() == rhs.StartsOn.Value())
&& lhs.ExpiresOn.HasValue() == rhs.ExpiresOn.HasValue()
&& (!lhs.ExpiresOn.HasValue() || lhs.ExpiresOn.Value() == rhs.ExpiresOn.Value())
&& lhs.Permissions == rhs.Permissions;
}

}}}} // namespace Azure::Storage::Blobs::Models

Expand Down
67 changes: 47 additions & 20 deletions sdk/storage/azure-storage-common/test/ut/test_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@
#include <sstream>
#include <string>

namespace Azure { namespace Storage { namespace Blobs { namespace Models {

bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs)
{
return lhs.Id == rhs.Id && lhs.StartsOn.HasValue() == rhs.StartsOn.HasValue()
&& (!lhs.StartsOn.HasValue() || lhs.StartsOn.Value() == rhs.StartsOn.Value())
&& lhs.ExpiresOn.HasValue() == rhs.ExpiresOn.HasValue()
&& (!lhs.ExpiresOn.HasValue() || lhs.ExpiresOn.Value() == rhs.ExpiresOn.Value())
&& lhs.Permissions == rhs.Permissions;
}

}}}} // namespace Azure::Storage::Blobs::Models

namespace Azure { namespace Storage { namespace Test {

constexpr static const char* StandardStorageConnectionStringValue = "";
Expand Down Expand Up @@ -79,11 +66,52 @@ namespace Azure { namespace Storage { namespace Test {
TestBase::TearDown();
}

std::string ParseConnectionStringAndGetAccountName(const std::string& connectionString)
{
std::map<std::string, std::string> connectionStringMap;

std::string::const_iterator cur = connectionString.begin();

while (cur != connectionString.end())
{
auto key_begin = cur;
auto key_end = std::find(cur, connectionString.end(), '=');
std::string key = std::string(key_begin, key_end);
cur = key_end;
if (cur != connectionString.end())
{
++cur;
}

auto value_begin = cur;
auto value_end = std::find(cur, connectionString.end(), ';');
std::string value = std::string(value_begin, value_end);
cur = value_end;
if (cur != connectionString.end())
{
++cur;
}

if (!key.empty() || !value.empty())
{
connectionStringMap[std::move(key)] = std::move(value);
}
}

auto getWithDefault = [](const std::map<std::string, std::string>& m,
const std::string& key,
const std::string& defaultValue = std::string()) {
auto ite = m.find(key);
return ite == m.end() ? defaultValue : ite->second;
};

return getWithDefault(connectionStringMap, "AccountName");
}

const std::string& StorageTest::StandardStorageAccountName()
{
const static std::string accountName
= Azure::Storage::_internal::ParseConnectionString(StandardStorageConnectionString())
.AccountName;
= ParseConnectionStringAndGetAccountName(StandardStorageConnectionString());
return accountName;
}

Expand All @@ -102,8 +130,7 @@ namespace Azure { namespace Storage { namespace Test {
const std::string& StorageTest::PremiumFileAccountName()
{
const static std::string accountName
= Azure::Storage::_internal::ParseConnectionString(PremiumFileConnectionString())
.AccountName;
= ParseConnectionStringAndGetAccountName(PremiumFileConnectionString());
return accountName;
}

Expand All @@ -122,7 +149,7 @@ namespace Azure { namespace Storage { namespace Test {
const std::string& StorageTest::AdlsGen2AccountName()
{
const static std::string accountName
= Azure::Storage::_internal::ParseConnectionString(AdlsGen2ConnectionString()).AccountName;
= ParseConnectionStringAndGetAccountName(AdlsGen2ConnectionString());
return accountName;
}

Expand Down Expand Up @@ -204,9 +231,9 @@ namespace Azure { namespace Storage { namespace Test {
return Azure::Core::_internal::StringExtensions::ToLower(RandomString(size));
}

Storage::Metadata StorageTest::RandomMetadata(size_t size)
Metadata StorageTest::RandomMetadata(size_t size)
{
Storage::Metadata result;
Metadata result;
for (size_t i = 0; i < size; ++i)
{
result["meta" + LowercaseRandomString(5)] = RandomString(10);
Expand Down
7 changes: 3 additions & 4 deletions sdk/storage/azure-storage-common/test/ut/test_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include <azure/core/platform.hpp>
#include <azure/core/test/test_base.hpp>
#include <azure/identity/client_secret_credential.hpp>
#include <azure/storage/blobs.hpp>
#include <azure/storage/common/internal/constants.hpp>
#include <azure/storage/common/storage_common.hpp>

#include <cctype>
#include <chrono>
Expand All @@ -25,6 +22,8 @@

namespace Azure { namespace Storage {

using Metadata = Azure::Core::CaseInsensitiveMap;

namespace Test {

class StorageTest : public Azure::Core::Test::TestBase {
Expand Down Expand Up @@ -121,7 +120,7 @@ namespace Azure { namespace Storage {
char RandomChar();
std::string RandomString(size_t size = 10);
std::string LowercaseRandomString(size_t size = 10);
Storage::Metadata RandomMetadata(size_t size = 5);
Metadata RandomMetadata(size_t size = 5);
void RandomBuffer(char* buffer, size_t length);
void RandomBuffer(uint8_t* buffer, size_t length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@

namespace Azure { namespace Storage { namespace Blobs { namespace Models {

bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs);
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs)
{
return lhs.Id == rhs.Id && lhs.StartsOn.HasValue() == rhs.StartsOn.HasValue()
&& (!lhs.StartsOn.HasValue() || lhs.StartsOn.Value() == rhs.StartsOn.Value())
&& lhs.ExpiresOn.HasValue() == rhs.ExpiresOn.HasValue()
&& (!lhs.ExpiresOn.HasValue() || lhs.ExpiresOn.Value() == rhs.ExpiresOn.Value())
&& lhs.Permissions == rhs.Permissions;
}

}}}} // namespace Azure::Storage::Blobs::Models

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "share_directory_client_test.hpp"

#include <azure/storage/common/crypt.hpp>

#include <algorithm>
#include <chrono>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "share_file_client_test.hpp"

#include <azure/core/cryptography/hash.hpp>
#include <azure/storage/blobs/blob_container_client.hpp>
#include <azure/storage/blobs/block_blob_client.hpp>
#include <azure/storage/common/crypt.hpp>
#include <azure/storage/common/internal/file_io.hpp>
#include <azure/storage/common/storage_common.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "share_client_test.hpp"

#include <azure/storage/common/crypt.hpp>
#include <azure/storage/files/shares/share_sas_builder.hpp>

#include <chrono>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "queue_client_test.hpp"

#include <azure/storage/common/crypt.hpp>
#include <azure/storage/queues/queue_sas_builder.hpp>

#include <chrono>
Expand Down
2 changes: 1 addition & 1 deletion sdk/tables/azure-data-tables/test/ut/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ create_map_file(azure-data-tables-test azure-data-tables-test.map)
# Include shared test headers
target_include_directories(azure-data-tables-test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../storage/azure-storage-common)

target_link_libraries(azure-data-tables-test PRIVATE azure-data-tables azure-storage-blobs azure-identity azure-core-test-fw gtest gtest_main gmock)
target_link_libraries(azure-data-tables-test PRIVATE azure-data-tables azure-identity azure-core-test-fw gtest gtest_main gmock)

# gtest_discover_tests will scan the test from azure-data-tables-test and call add_test
# for each test to ctest. This enables `ctest -r` to run specific tests directly.
Expand Down

0 comments on commit 57cc679

Please sign in to comment.