Avoid test case throw meaningless exception when sys env is not set. (#723)
* Avoid test case throw meaningless exception when sys env is not set. * Update sdk/storage/azure-storage-common/test/test_base.cpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * Update sdk/storage/azure-storage-common/test/test_base.cpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * Update sdk/storage/azure-storage-common/test/test_base.cpp Co-authored-by: JinmingHu <jinmhu@microsoft.com> * Apply clang format Co-authored-by: JinmingHu <jinmhu@microsoft.com>
This commit is contained in:
parent
582377fc1d
commit
966b7892b2
@ -31,6 +31,17 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
constexpr static const char* c_AadClientId = "";
|
||||
constexpr static const char* c_AadClientSecret = "";
|
||||
|
||||
std::string GetEnv(const std::string& name)
|
||||
{
|
||||
const char* ret = std::getenv(name.data());
|
||||
if (!ret)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
name + " is required to run the tests but not set as an environment variable.");
|
||||
}
|
||||
return std::string(ret);
|
||||
}
|
||||
|
||||
const std::string& StandardStorageConnectionString()
|
||||
{
|
||||
const static std::string connectionString = []() -> std::string {
|
||||
@ -38,7 +49,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_StandardStorageConnectionString;
|
||||
}
|
||||
return std::getenv("STANDARD_STORAGE_CONNECTION_STRING");
|
||||
return GetEnv("STANDARD_STORAGE_CONNECTION_STRING");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -50,7 +61,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_PremiumStorageConnectionString;
|
||||
}
|
||||
return std::getenv("PREMIUM_STORAGE_CONNECTION_STRING");
|
||||
return GetEnv("PREMIUM_STORAGE_CONNECTION_STRING");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -62,7 +73,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_BlobStorageConnectionString;
|
||||
}
|
||||
return std::getenv("BLOB_STORAGE_CONNECTION_STRING");
|
||||
return GetEnv("BLOB_STORAGE_CONNECTION_STRING");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -74,7 +85,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_PremiumFileConnectionString;
|
||||
}
|
||||
return std::getenv("PREMIUM_FILE_CONNECTION_STRING");
|
||||
return GetEnv("PREMIUM_FILE_CONNECTION_STRING");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -86,7 +97,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_AdlsGen2ConnectionString;
|
||||
}
|
||||
return std::getenv("ADLS_GEN2_CONNECTION_STRING");
|
||||
return GetEnv("ADLS_GEN2_CONNECTION_STRING");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -98,7 +109,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_AadTenantId;
|
||||
}
|
||||
return std::getenv("AAD_TENANT_ID");
|
||||
return GetEnv("AAD_TENANT_ID");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -110,7 +121,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_AadClientId;
|
||||
}
|
||||
return std::getenv("AAD_CLIENT_ID");
|
||||
return GetEnv("AAD_CLIENT_ID");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -122,7 +133,7 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
{
|
||||
return c_AadClientSecret;
|
||||
}
|
||||
return std::getenv("AAD_CLIENT_SECRET");
|
||||
return GetEnv("AAD_CLIENT_SECRET");
|
||||
}();
|
||||
return connectionString;
|
||||
}
|
||||
@ -296,5 +307,4 @@ namespace Azure { namespace Storage { namespace Test {
|
||||
return secondaryUri.GetAbsoluteUrl();
|
||||
}
|
||||
|
||||
|
||||
}}} // namespace Azure::Storage::Test
|
||||
|
||||
Loading…
Reference in New Issue
Block a user