Added token credential tests to blob tests (#6790)
* Added token credential tests to blob tests * Fixed linux build error * HasOption shouldn't crash if option isn't present * Added token credential tests to all relevant blob tests and added to the perf-tests outputs * PR feedback
This commit is contained in:
parent
b1819cda3f
commit
21e92f8712
@ -393,7 +393,7 @@ struct parser_results
|
||||
* Returns the name of the program from the original arguments list. This is
|
||||
* always the first argument.
|
||||
*/
|
||||
const char* program;
|
||||
const char* program = nullptr;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
||||
@ -60,6 +60,28 @@ namespace Azure { namespace Perf {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the option was parsed from command line.
|
||||
*
|
||||
* @param optionName The name of the option.
|
||||
* @return true if the option was parsed from command line.
|
||||
* @return false if the option was not parsed from command line.
|
||||
*/
|
||||
bool HasOption(std::string const& optionName) const
|
||||
{
|
||||
if (m_results.has_option(optionName))
|
||||
{
|
||||
// If there are results for this option , but the first result has a nullptr arg, it's a
|
||||
// boolean parameter with no arguments so return true.
|
||||
if (m_results[optionName].count() != 0)
|
||||
{
|
||||
// No args were passed for this option, it is present.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the option value from the option name.
|
||||
*
|
||||
|
||||
@ -88,16 +88,47 @@ inline void PrintOptions(
|
||||
{
|
||||
try
|
||||
{
|
||||
auto optionName{option.Name};
|
||||
optionsAsJson[optionName]
|
||||
= option.SensitiveData ? "***" : parsedArgs[optionName].as<std::string>();
|
||||
if (parsedArgs.has_option(option.Name))
|
||||
{
|
||||
auto optionName{option.Name};
|
||||
if (option.ExpectedArgs != 0)
|
||||
{
|
||||
optionsAsJson[optionName]
|
||||
= (option.SensitiveData ? "***" : parsedArgs[optionName].as<std::string>());
|
||||
}
|
||||
else
|
||||
{
|
||||
optionsAsJson[optionName] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option.Required)
|
||||
{
|
||||
// re-throw
|
||||
throw std::invalid_argument("Missing mandatory parameter: " + option.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option.ExpectedArgs == 0)
|
||||
{
|
||||
// arg was not parsed
|
||||
optionsAsJson[option.Name] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// arg was not parsed
|
||||
optionsAsJson[option.Name] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::out_of_range const&)
|
||||
{
|
||||
if (!option.Required)
|
||||
{
|
||||
// arg was not parsed
|
||||
optionsAsJson[option.Name] = "default value";
|
||||
optionsAsJson[option.Name] = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -5,8 +5,6 @@ Project: azure-storage-blobs-perf
|
||||
PrimaryPackage: azure-storage-blobs-cpp
|
||||
|
||||
PackageVersions:
|
||||
- azure-storage-blobs-cpp: 12.6.2
|
||||
azure-core-cpp: 1.7.2
|
||||
- azure-storage-blobs-cpp: source
|
||||
azure-core-cpp: source
|
||||
|
||||
@ -18,6 +16,10 @@ Tests:
|
||||
- --size 10485760 --parallel 32
|
||||
- --size 1073741824 --parallel 1 --warmup 60 --duration 60
|
||||
- --size 1073741824 --parallel 8 --warmup 60 --duration 60
|
||||
- --size 10240 --parallel 64 --token-credential
|
||||
- --size 10485760 --parallel 32 --token-credential
|
||||
- --size 1073741824 --parallel 1 --warmup 60 --duration 60 --token-credential
|
||||
- --size 1073741824 --parallel 8 --warmup 60 --duration 60 --token-credential
|
||||
|
||||
- Test: upload
|
||||
Class: UploadBlob
|
||||
@ -26,6 +28,10 @@ Tests:
|
||||
- --size 10485760 --parallel 32
|
||||
- --size 1073741824 --parallel 1 --warmup 60 --duration 60
|
||||
- --size 1073741824 --parallel 8 --warmup 60 --duration 60
|
||||
- --size 10240 --parallel 64 --token-credential
|
||||
- --size 10485760 --parallel 32 --token-credential
|
||||
- --size 1073741824 --parallel 1 --warmup 60 --duration 60 --token-credential
|
||||
- --size 1073741824 --parallel 8 --warmup 60 --duration 60 --token-credential
|
||||
|
||||
- Test: list-blobs
|
||||
Class: ListBlob
|
||||
@ -33,3 +39,6 @@ Tests:
|
||||
- --count 5 --parallel 64
|
||||
- --count 500 --parallel 32
|
||||
- --count 50000 --parallel 32 --warmup 60 --duration 60
|
||||
- --count 5 --parallel 64 --token-credential
|
||||
- --count 500 --parallel 32 --token-credential
|
||||
- --count 50000 --parallel 32 --warmup 60 --duration 60 --token-credential
|
||||
|
||||
@ -64,6 +64,9 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
// Get connection string from env
|
||||
const static std::string envConnectionString
|
||||
= Azure::Core::_internal::Environment::GetVariable("STORAGE_CONNECTION_STRING");
|
||||
|
||||
const static std::string hostName
|
||||
= Azure::Core::_internal::Environment::GetVariable("AZURE_STORAGE_ACCOUNT_NAME");
|
||||
m_connectionString = envConnectionString;
|
||||
|
||||
// Generate random container and blob names.
|
||||
@ -71,9 +74,19 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
m_blobName = "blob" + Azure::Core::Uuid::CreateUuid().ToString();
|
||||
|
||||
// Create client, container and blobClient
|
||||
m_serviceClient = std::make_unique<Azure::Storage::Blobs::BlobServiceClient>(
|
||||
Azure::Storage::Blobs::BlobServiceClient::CreateFromConnectionString(
|
||||
m_connectionString, InitClientOptions<Azure::Storage::Blobs::BlobClientOptions>()));
|
||||
if (!m_options.HasOption("TokenCredential"))
|
||||
{
|
||||
m_serviceClient = std::make_unique<Azure::Storage::Blobs::BlobServiceClient>(
|
||||
Azure::Storage::Blobs::BlobServiceClient::CreateFromConnectionString(
|
||||
m_connectionString, InitClientOptions<Azure::Storage::Blobs::BlobClientOptions>()));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_serviceClient = std::make_unique<Azure::Storage::Blobs::BlobServiceClient>(
|
||||
"https://" + hostName + ".blob.core.windows.net",
|
||||
GetTestCredential(),
|
||||
InitClientOptions<Azure::Storage::Blobs::BlobClientOptions>());
|
||||
}
|
||||
m_containerClient = std::make_unique<Azure::Storage::Blobs::BlobContainerClient>(
|
||||
m_serviceClient->GetBlobContainerClient(m_containerName));
|
||||
m_containerClient->CreateIfNotExists();
|
||||
@ -99,5 +112,4 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
*/
|
||||
std::vector<Azure::Perf::TestOption> GetTestOptions() override { return {}; }
|
||||
};
|
||||
|
||||
}}}} // namespace Azure::Storage::Blobs::Test
|
||||
|
||||
@ -71,7 +71,13 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
std::vector<Azure::Perf::TestOption> GetTestOptions() override
|
||||
{
|
||||
// TODO: Merge with base options
|
||||
return {{"Size", {"--size"}, "Size of payload (in bytes)", 1, true}};
|
||||
|
||||
return {
|
||||
{"TokenCredential",
|
||||
{"--token-credential"},
|
||||
"Use a token credential to run the test. By default, a connection string is used.",
|
||||
0},
|
||||
{"Size", {"--size"}, "Size of payload (in bytes)", 1, true}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -82,7 +82,12 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
std::vector<Azure::Perf::TestOption> GetTestOptions() override
|
||||
{
|
||||
// TODO: Merge with base options
|
||||
return {{"Count", {"--count"}, "Number of blobs to list", 1, true}};
|
||||
return {
|
||||
{"TokenCredential",
|
||||
{"--token-credential"},
|
||||
"Use a token credential to run the test. By default, a connection string is used.",
|
||||
0},
|
||||
{"Count", {"--count"}, "Number of blobs to list", 1, true}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -68,7 +68,12 @@ namespace Azure { namespace Storage { namespace Blobs { namespace Test {
|
||||
std::vector<Azure::Perf::TestOption> GetTestOptions() override
|
||||
{
|
||||
// TODO: Merge with base options
|
||||
return {{"Size", {"--size", "-s"}, "Size of payload (in bytes)", 1, true}};
|
||||
return {
|
||||
{"TokenCredential",
|
||||
{"--token-credential"},
|
||||
"Use a token credential to run the test. By default, a connection string is used.",
|
||||
0},
|
||||
{"Size", {"--size", "-s"}, "Size of payload (in bytes)", 1, true}};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user