Refactored app_config unit tests

This commit is contained in:
Scott E. Graves 2025-02-15 11:54:59 -06:00
parent f8b71093c7
commit 7ef600969c
3 changed files with 112 additions and 1 deletions

View File

@ -14,6 +14,9 @@
* Continue documentation updates
* Fixed setting `ApiAuth` via `set_value_by_name`
* Fixed setting `HostConfig.ApiUser` via `set_value_by_name`
* Fixed setting `HostConfig.Path` via `set_value_by_name`
* Fixed setting `HostConfig.Protocol` via `set_value_by_name`
* Refactored `app_config` unit tests
* Refactored polling to be more accurate on scheduling tasks

View File

@ -165,8 +165,14 @@ app_config::app_config(const provider_type &prov,
[this]() { return get_host_config().api_password; }},
{fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT),
[this]() { return std::to_string(get_host_config().api_port); }},
{fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_USER),
[this]() { return get_host_config().api_user; }},
{fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP),
[this]() { return get_host_config().host_name_or_ip; }},
{fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_PATH),
[this]() { return get_host_config().path; }},
{fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_PROTOCOL),
[this]() { return get_host_config().protocol; }},
{fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS),
[this]() { return std::to_string(get_host_config().timeout_ms); }},
{JSON_LOW_FREQ_INTERVAL_SECS,
@ -377,6 +383,15 @@ app_config::app_config(const provider_type &prov,
return std::to_string(get_host_config().api_port);
},
},
{
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_USER),
[this](const std::string &value) {
auto cfg = get_host_config();
cfg.api_user = value;
set_host_config(cfg);
return get_host_config().api_user;
},
},
{
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP),
[this](const std::string &value) {
@ -386,6 +401,24 @@ app_config::app_config(const provider_type &prov,
return get_host_config().host_name_or_ip;
},
},
{
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_PATH),
[this](const std::string &value) {
auto cfg = get_host_config();
cfg.path = value;
set_host_config(cfg);
return get_host_config().path;
},
},
{
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_PROTOCOL),
[this](const std::string &value) {
auto cfg = get_host_config();
cfg.protocol = value;
set_host_config(cfg);
return get_host_config().protocol;
},
},
{
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS),
[this](const std::string &value) {

View File

@ -336,7 +336,82 @@ static void common_tests(app_config &config, provider_type prov) {
cfg.set_high_frequency_interval_secs(0U);
EXPECT_EQ(1U, cfg.get_high_frequency_interval_secs());
}},
{JSON_HOST_CONFIG, [](auto &&cfg) {}},
{JSON_HOST_CONFIG,
[](app_config &cfg) {
host_config cfg1{};
cfg1.agent_string = "1";
cfg1.api_password = "2";
cfg1.api_user = "3";
cfg1.api_port = 4U;
cfg1.host_name_or_ip = "5";
cfg1.path = "6";
cfg1.protocol = "http";
cfg1.timeout_ms = 8U;
host_config cfg2{};
cfg2.agent_string = "9";
cfg2.api_password = "10";
cfg2.api_user = "11";
cfg2.api_port = 12U;
cfg2.host_name_or_ip = "13";
cfg2.path = "14";
cfg2.protocol = "https";
cfg2.timeout_ms = 16U;
ASSERT_NE(cfg1, cfg2);
test_getter_setter(cfg, &app_config::get_host_config,
&app_config::set_host_config, cfg1, cfg2, "", "");
host_config cfg3{};
cfg3.agent_string = "17";
cfg3.api_password = "18";
cfg3.api_user = "19";
cfg3.api_port = 20U;
cfg3.host_name_or_ip = "21";
cfg3.path = "22";
cfg3.protocol = "http";
cfg3.timeout_ms = 24;
auto value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_AGENT_STRING),
cfg3.agent_string);
EXPECT_STREQ(cfg3.agent_string.c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PASSWORD),
cfg3.api_password);
EXPECT_STREQ(cfg3.api_password.c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_USER),
cfg3.api_user);
EXPECT_STREQ(cfg3.api_user.c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_API_PORT),
std::to_string(cfg3.api_port));
EXPECT_STREQ(std::to_string(cfg3.api_port).c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_HOST_NAME_OR_IP),
cfg3.host_name_or_ip);
EXPECT_STREQ(cfg3.host_name_or_ip.c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_PATH), cfg3.path);
EXPECT_STREQ(cfg3.path.c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_PROTOCOL),
cfg3.protocol);
EXPECT_STREQ(cfg3.protocol.c_str(), value.c_str());
value = cfg.set_value_by_name(
fmt::format("{}.{}", JSON_HOST_CONFIG, JSON_TIMEOUT_MS),
std::to_string(cfg3.timeout_ms));
EXPECT_STREQ(std::to_string(cfg3.timeout_ms).c_str(), value.c_str());
}},
{JSON_LOW_FREQ_INTERVAL_SECS,
[](app_config &cfg) {
test_getter_setter(