Skip to content

Commit 57cc679

Browse files
authored
Remove linking azure-storage-blobs in azure-data-tables tests and decouple 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.
1 parent 99e0895 commit 57cc679

9 files changed

Lines changed: 73 additions & 27 deletions

File tree

sdk/storage/azure-storage-blobs/test/ut/blob_container_client_test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@
1313

1414
namespace Azure { namespace Storage { namespace Blobs { namespace Models {
1515

16-
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs);
16+
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs)
17+
{
18+
return lhs.Id == rhs.Id && lhs.StartsOn.HasValue() == rhs.StartsOn.HasValue()
19+
&& (!lhs.StartsOn.HasValue() || lhs.StartsOn.Value() == rhs.StartsOn.Value())
20+
&& lhs.ExpiresOn.HasValue() == rhs.ExpiresOn.HasValue()
21+
&& (!lhs.ExpiresOn.HasValue() || lhs.ExpiresOn.Value() == rhs.ExpiresOn.Value())
22+
&& lhs.Permissions == rhs.Permissions;
23+
}
1724

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

sdk/storage/azure-storage-common/test/ut/test_base.cpp

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919
#include <sstream>
2020
#include <string>
2121

22-
namespace Azure { namespace Storage { namespace Blobs { namespace Models {
23-
24-
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs)
25-
{
26-
return lhs.Id == rhs.Id && lhs.StartsOn.HasValue() == rhs.StartsOn.HasValue()
27-
&& (!lhs.StartsOn.HasValue() || lhs.StartsOn.Value() == rhs.StartsOn.Value())
28-
&& lhs.ExpiresOn.HasValue() == rhs.ExpiresOn.HasValue()
29-
&& (!lhs.ExpiresOn.HasValue() || lhs.ExpiresOn.Value() == rhs.ExpiresOn.Value())
30-
&& lhs.Permissions == rhs.Permissions;
31-
}
32-
33-
}}}} // namespace Azure::Storage::Blobs::Models
34-
3522
namespace Azure { namespace Storage { namespace Test {
3623

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

69+
std::string ParseConnectionStringAndGetAccountName(const std::string& connectionString)
70+
{
71+
std::map<std::string, std::string> connectionStringMap;
72+
73+
std::string::const_iterator cur = connectionString.begin();
74+
75+
while (cur != connectionString.end())
76+
{
77+
auto key_begin = cur;
78+
auto key_end = std::find(cur, connectionString.end(), '=');
79+
std::string key = std::string(key_begin, key_end);
80+
cur = key_end;
81+
if (cur != connectionString.end())
82+
{
83+
++cur;
84+
}
85+
86+
auto value_begin = cur;
87+
auto value_end = std::find(cur, connectionString.end(), ';');
88+
std::string value = std::string(value_begin, value_end);
89+
cur = value_end;
90+
if (cur != connectionString.end())
91+
{
92+
++cur;
93+
}
94+
95+
if (!key.empty() || !value.empty())
96+
{
97+
connectionStringMap[std::move(key)] = std::move(value);
98+
}
99+
}
100+
101+
auto getWithDefault = [](const std::map<std::string, std::string>& m,
102+
const std::string& key,
103+
const std::string& defaultValue = std::string()) {
104+
auto ite = m.find(key);
105+
return ite == m.end() ? defaultValue : ite->second;
106+
};
107+
108+
return getWithDefault(connectionStringMap, "AccountName");
109+
}
110+
82111
const std::string& StorageTest::StandardStorageAccountName()
83112
{
84113
const static std::string accountName
85-
= Azure::Storage::_internal::ParseConnectionString(StandardStorageConnectionString())
86-
.AccountName;
114+
= ParseConnectionStringAndGetAccountName(StandardStorageConnectionString());
87115
return accountName;
88116
}
89117

@@ -102,8 +130,7 @@ namespace Azure { namespace Storage { namespace Test {
102130
const std::string& StorageTest::PremiumFileAccountName()
103131
{
104132
const static std::string accountName
105-
= Azure::Storage::_internal::ParseConnectionString(PremiumFileConnectionString())
106-
.AccountName;
133+
= ParseConnectionStringAndGetAccountName(PremiumFileConnectionString());
107134
return accountName;
108135
}
109136

@@ -122,7 +149,7 @@ namespace Azure { namespace Storage { namespace Test {
122149
const std::string& StorageTest::AdlsGen2AccountName()
123150
{
124151
const static std::string accountName
125-
= Azure::Storage::_internal::ParseConnectionString(AdlsGen2ConnectionString()).AccountName;
152+
= ParseConnectionStringAndGetAccountName(AdlsGen2ConnectionString());
126153
return accountName;
127154
}
128155

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

207-
Storage::Metadata StorageTest::RandomMetadata(size_t size)
234+
Metadata StorageTest::RandomMetadata(size_t size)
208235
{
209-
Storage::Metadata result;
236+
Metadata result;
210237
for (size_t i = 0; i < size; ++i)
211238
{
212239
result["meta" + LowercaseRandomString(5)] = RandomString(10);

sdk/storage/azure-storage-common/test/ut/test_base.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#include <azure/core/platform.hpp>
1111
#include <azure/core/test/test_base.hpp>
1212
#include <azure/identity/client_secret_credential.hpp>
13-
#include <azure/storage/blobs.hpp>
14-
#include <azure/storage/common/internal/constants.hpp>
15-
#include <azure/storage/common/storage_common.hpp>
1613

1714
#include <cctype>
1815
#include <chrono>
@@ -25,6 +22,8 @@
2522

2623
namespace Azure { namespace Storage {
2724

25+
using Metadata = Azure::Core::CaseInsensitiveMap;
26+
2827
namespace Test {
2928

3029
class StorageTest : public Azure::Core::Test::TestBase {
@@ -121,7 +120,7 @@ namespace Azure { namespace Storage {
121120
char RandomChar();
122121
std::string RandomString(size_t size = 10);
123122
std::string LowercaseRandomString(size_t size = 10);
124-
Storage::Metadata RandomMetadata(size_t size = 5);
123+
Metadata RandomMetadata(size_t size = 5);
125124
void RandomBuffer(char* buffer, size_t length);
126125
void RandomBuffer(uint8_t* buffer, size_t length)
127126
{

sdk/storage/azure-storage-files-datalake/test/ut/datalake_file_system_client_test.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
namespace Azure { namespace Storage { namespace Blobs { namespace Models {
1313

14-
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs);
14+
bool operator==(const SignedIdentifier& lhs, const SignedIdentifier& rhs)
15+
{
16+
return lhs.Id == rhs.Id && lhs.StartsOn.HasValue() == rhs.StartsOn.HasValue()
17+
&& (!lhs.StartsOn.HasValue() || lhs.StartsOn.Value() == rhs.StartsOn.Value())
18+
&& lhs.ExpiresOn.HasValue() == rhs.ExpiresOn.HasValue()
19+
&& (!lhs.ExpiresOn.HasValue() || lhs.ExpiresOn.Value() == rhs.ExpiresOn.Value())
20+
&& lhs.Permissions == rhs.Permissions;
21+
}
1522

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

sdk/storage/azure-storage-files-shares/test/ut/share_directory_client_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "share_directory_client_test.hpp"
55

6+
#include <azure/storage/common/crypt.hpp>
7+
68
#include <algorithm>
79
#include <chrono>
810

sdk/storage/azure-storage-files-shares/test/ut/share_file_client_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "share_file_client_test.hpp"
55

66
#include <azure/core/cryptography/hash.hpp>
7+
#include <azure/storage/blobs/blob_container_client.hpp>
8+
#include <azure/storage/blobs/block_blob_client.hpp>
79
#include <azure/storage/common/crypt.hpp>
810
#include <azure/storage/common/internal/file_io.hpp>
911
#include <azure/storage/common/storage_common.hpp>

sdk/storage/azure-storage-files-shares/test/ut/share_sas_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "share_client_test.hpp"
55

6+
#include <azure/storage/common/crypt.hpp>
67
#include <azure/storage/files/shares/share_sas_builder.hpp>
78

89
#include <chrono>

sdk/storage/azure-storage-queues/test/ut/queue_sas_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "queue_client_test.hpp"
55

6+
#include <azure/storage/common/crypt.hpp>
67
#include <azure/storage/queues/queue_sas_builder.hpp>
78

89
#include <chrono>

sdk/tables/azure-data-tables/test/ut/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ create_map_file(azure-data-tables-test azure-data-tables-test.map)
4040
# Include shared test headers
4141
target_include_directories(azure-data-tables-test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../../storage/azure-storage-common)
4242

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

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

0 commit comments

Comments
 (0)