Refactored app_config unit tests
This commit is contained in:
parent
0eb28f3124
commit
7f957c04dd
@ -160,7 +160,7 @@ static void defaults_tests(const json &json_data, provider_type prov) {
|
||||
json_defaults.erase(JSON_S3_CONFIG);
|
||||
json_defaults[JSON_HOST_CONFIG][JSON_API_PORT] =
|
||||
app_config::default_api_port(prov);
|
||||
json_defaults[JSON_HOST_CONFIG][JSON_API_PORT] =
|
||||
json_defaults[JSON_HOST_CONFIG][JSON_AGENT_STRING] =
|
||||
app_config::default_agent_name(prov);
|
||||
json_defaults[JSON_REMOTE_MOUNT][JSON_API_PORT] =
|
||||
app_config::default_remote_api_port(prov);
|
||||
@ -184,22 +184,131 @@ static void defaults_tests(const json &json_data, provider_type prov) {
|
||||
static void common_tests(app_config &config, provider_type prov) {
|
||||
ASSERT_EQ(config.get_provider_type(), prov);
|
||||
|
||||
std::map<std::string_view, std::function<void(app_config &)>> methods{
|
||||
{JSON_API_AUTH,
|
||||
[](app_config &cfg) {
|
||||
cfg.set_api_auth("");
|
||||
EXPECT_STREQ("", cfg.get_api_auth().c_str());
|
||||
|
||||
cfg.set_api_auth("test");
|
||||
EXPECT_STREQ("test", cfg.get_api_auth().c_str());
|
||||
|
||||
auto value = cfg.set_value_by_name(JSON_API_AUTH, "test2");
|
||||
EXPECT_STREQ("test2", value.c_str());
|
||||
EXPECT_STREQ("test2", cfg.get_api_auth().c_str());
|
||||
|
||||
value = cfg.get_value_by_name(JSON_API_AUTH);
|
||||
EXPECT_STREQ("test2", value.c_str());
|
||||
}},
|
||||
{JSON_API_PORT,
|
||||
[](const app_config &cfg) {
|
||||
cfg.set_api_port(0U);
|
||||
EXPECT_EQ(std::uint16_t(0U), cfg.get_api_port());
|
||||
|
||||
cfg.set_api_port(1024U);
|
||||
EXPECT_EQ(std::uint16_t(1024U), cfg.get_api_port());
|
||||
|
||||
auto value = cfg.set_value_by_name(JSON_API_PORT, "1025");
|
||||
EXPECT_STREQ("1025", value.c_str());
|
||||
EXPECT_EQ(std::uint16_t(1025U), cfg.get_api_port());
|
||||
|
||||
value = cfg.get_value_by_name(JSON_API_PORT);
|
||||
EXPECT_STREQ("1025", value.c_str());
|
||||
}},
|
||||
{JSON_API_USER, [](auto &&cfg) {}},
|
||||
{JSON_DOWNLOAD_TIMEOUT_SECS, [](auto &&cfg) {}},
|
||||
{JSON_DATABASE_TYPE, [](auto &&cfg) {}},
|
||||
{JSON_ENABLE_DOWNLOAD_TIMEOUT, [](auto &&cfg) {}},
|
||||
{JSON_ENABLE_DRIVE_EVENTS, [](auto &&cfg) {}},
|
||||
#if defined(_WIN32)
|
||||
{JSON_ENABLE_MOUNT_MANAGER, [](auto &&cfg) {}},
|
||||
#endif // defined(_WIN32)
|
||||
{JSON_ENCRYPT_CONFIG, [](auto &&cfg) {}},
|
||||
{JSON_EVENT_LEVEL, [](auto &&cfg) {}},
|
||||
{JSON_EVICTION_DELAY_MINS, [](auto &&cfg) {}},
|
||||
{JSON_EVICTION_USE_ACCESS_TIME, [](auto &&cfg) {}},
|
||||
{JSON_HIGH_FREQ_INTERVAL_SECS, [](auto &&cfg) {}},
|
||||
{JSON_HOST_CONFIG, [](auto &&cfg) {}},
|
||||
{JSON_LOW_FREQ_INTERVAL_SECS, [](auto &&cfg) {}},
|
||||
{JSON_MAX_CACHE_SIZE_BYTES, [](auto &&cfg) {}},
|
||||
{JSON_MAX_UPLOAD_COUNT, [](auto &&cfg) {}},
|
||||
{JSON_MED_FREQ_INTERVAL_SECS, [](auto &&cfg) {}},
|
||||
{JSON_ONLINE_CHECK_RETRY_SECS, [](auto &&cfg) {}},
|
||||
{JSON_ORPHANED_FILE_RETENTION_DAYS, [](auto &&cfg) {}},
|
||||
{JSON_PREFERRED_DOWNLOAD_TYPE, [](auto &&cfg) {}},
|
||||
{JSON_REMOTE_CONFIG, [](auto &&cfg) {}},
|
||||
{JSON_REMOTE_MOUNT, [](auto &&cfg) {}},
|
||||
{JSON_RETRY_READ_COUNT, [](auto &&cfg) {}},
|
||||
{JSON_RING_BUFFER_FILE_SIZE, [](auto &&cfg) {}},
|
||||
{JSON_S3_CONFIG, [](auto &&cfg) {}},
|
||||
{JSON_SIA_CONFIG, [](auto &&cfg) {}},
|
||||
{JSON_TASK_WAIT_MS, [](auto &&cfg) {}},
|
||||
};
|
||||
|
||||
switch (config.get_provider_type()) {
|
||||
case provider_type::encrypt:
|
||||
methods.erase(JSON_DOWNLOAD_TIMEOUT_SECS);
|
||||
methods.erase(JSON_ENABLE_DOWNLOAD_TIMEOUT);
|
||||
methods.erase(JSON_EVICTION_DELAY_MINS);
|
||||
methods.erase(JSON_EVICTION_USE_ACCESS_TIME);
|
||||
methods.erase(JSON_HOST_CONFIG);
|
||||
methods.erase(JSON_MAX_CACHE_SIZE_BYTES);
|
||||
methods.erase(JSON_MAX_UPLOAD_COUNT);
|
||||
methods.erase(JSON_ONLINE_CHECK_RETRY_SECS);
|
||||
methods.erase(JSON_ORPHANED_FILE_RETENTION_DAYS);
|
||||
methods.erase(JSON_PREFERRED_DOWNLOAD_TYPE);
|
||||
methods.erase(JSON_REMOTE_CONFIG);
|
||||
methods.erase(JSON_RETRY_READ_COUNT);
|
||||
methods.erase(JSON_RING_BUFFER_FILE_SIZE);
|
||||
methods.erase(JSON_S3_CONFIG);
|
||||
methods.erase(JSON_SIA_CONFIG);
|
||||
break;
|
||||
|
||||
case provider_type::remote:
|
||||
methods.erase(JSON_DATABASE_TYPE);
|
||||
methods.erase(JSON_DOWNLOAD_TIMEOUT_SECS);
|
||||
methods.erase(JSON_ENABLE_DOWNLOAD_TIMEOUT);
|
||||
methods.erase(JSON_ENCRYPT_CONFIG);
|
||||
methods.erase(JSON_EVICTION_DELAY_MINS);
|
||||
methods.erase(JSON_EVICTION_USE_ACCESS_TIME);
|
||||
methods.erase(JSON_HIGH_FREQ_INTERVAL_SECS);
|
||||
methods.erase(JSON_HOST_CONFIG);
|
||||
methods.erase(JSON_LOW_FREQ_INTERVAL_SECS);
|
||||
methods.erase(JSON_MAX_CACHE_SIZE_BYTES);
|
||||
methods.erase(JSON_MAX_UPLOAD_COUNT);
|
||||
methods.erase(JSON_MED_FREQ_INTERVAL_SECS);
|
||||
methods.erase(JSON_ONLINE_CHECK_RETRY_SECS);
|
||||
methods.erase(JSON_ORPHANED_FILE_RETENTION_DAYS);
|
||||
methods.erase(JSON_PREFERRED_DOWNLOAD_TYPE);
|
||||
methods.erase(JSON_REMOTE_MOUNT);
|
||||
methods.erase(JSON_RETRY_READ_COUNT);
|
||||
methods.erase(JSON_RING_BUFFER_FILE_SIZE);
|
||||
methods.erase(JSON_S3_CONFIG);
|
||||
methods.erase(JSON_SIA_CONFIG);
|
||||
break;
|
||||
|
||||
case provider_type::s3:
|
||||
methods.erase(JSON_ENCRYPT_CONFIG);
|
||||
methods.erase(JSON_HOST_CONFIG);
|
||||
methods.erase(JSON_REMOTE_CONFIG);
|
||||
methods.erase(JSON_SIA_CONFIG);
|
||||
break;
|
||||
|
||||
case provider_type::sia:
|
||||
methods.erase(JSON_ENCRYPT_CONFIG);
|
||||
methods.erase(JSON_REMOTE_CONFIG);
|
||||
methods.erase(JSON_S3_CONFIG);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto &[key, test_function] : methods) {
|
||||
fmt::println("testing setting|{}-{}", app_config::get_provider_name(prov),
|
||||
key);
|
||||
test_function(config);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(app_config_test, encrypt_config) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user