Refactored app_config unit tests

This commit is contained in:
Scott E. Graves 2025-02-15 07:55:33 -06:00
parent c94b00a10b
commit be6f6fecaf
4 changed files with 24 additions and 44 deletions

View File

@ -91,7 +91,6 @@ private:
std::atomic<std::uint8_t> max_upload_count_;
std::atomic<std::uint16_t> med_freq_interval_secs_;
std::atomic<std::uint16_t> online_check_retry_secs_;
std::atomic<std::uint16_t> orphaned_file_retention_days_;
std::atomic<download_type> preferred_download_type_;
std::atomic<std::uint16_t> retry_read_count_;
std::atomic<std::uint16_t> ring_buffer_file_size_;
@ -172,8 +171,6 @@ public:
[[nodiscard]] auto get_online_check_retry_secs() const -> std::uint16_t;
[[nodiscard]] auto get_orphaned_file_retention_days() const -> std::uint16_t;
[[nodiscard]] auto get_preferred_download_type() const -> download_type;
[[nodiscard]] auto get_provider_type() const -> provider_type;
@ -242,8 +239,6 @@ public:
void set_online_check_retry_secs(std::uint16_t value);
void set_orphaned_file_retention_days(std::uint16_t value);
void set_preferred_download_type(const download_type &value);
void set_remote_config(remote::remote_config value);

View File

@ -34,12 +34,10 @@ constexpr const auto default_max_cache_size_bytes{
constexpr const auto default_max_upload_count{5U};
constexpr const auto default_med_freq_interval_secs{std::uint16_t{2U * 60U}};
constexpr const auto default_online_check_retry_secs{60U};
constexpr const auto default_orphaned_file_retention_days{15U};
constexpr const auto default_retry_read_count{6U};
constexpr const auto default_ring_buffer_file_size{512U};
constexpr const auto default_task_wait_ms{100U};
constexpr const auto default_timeout_ms{60000U};
constexpr const auto max_orphaned_file_retention_days{std::uint16_t(31U)};
constexpr const auto max_ring_buffer_file_size{std::uint16_t(1024U)};
constexpr const auto max_s3_object_name_length{1024U};
constexpr const auto min_cache_size_bytes{
@ -47,7 +45,6 @@ constexpr const auto min_cache_size_bytes{
};
constexpr const auto min_download_timeout_secs{std::uint8_t(5U)};
constexpr const auto min_online_check_retry_secs{std::uint16_t(15U)};
constexpr const auto min_orphaned_file_retention_days{std::uint16_t(1U)};
constexpr const auto min_retry_read_count{std::uint16_t(2U)};
constexpr const auto min_ring_buffer_file_size{std::uint16_t(64U)};
constexpr const auto min_task_wait_ms{std::uint16_t(50U)};
@ -493,8 +490,6 @@ inline constexpr const auto JSON_MED_FREQ_INTERVAL_SECS{
inline constexpr const auto JSON_META{"Meta"};
inline constexpr const auto JSON_ONLINE_CHECK_RETRY_SECS{
"OnlineCheckRetrySeconds"};
inline constexpr const auto JSON_ORPHANED_FILE_RETENTION_DAYS{
"OrphanedFileRetentionDays"};
inline constexpr const auto JSON_PATH{"Path"};
inline constexpr const auto JSON_PREFERRED_DOWNLOAD_TYPE{
"PreferredDownloadType"};

View File

@ -85,7 +85,6 @@ app_config::app_config(const provider_type &prov,
max_upload_count_(default_max_upload_count),
med_freq_interval_secs_(default_med_freq_interval_secs),
online_check_retry_secs_(default_online_check_retry_secs),
orphaned_file_retention_days_(default_orphaned_file_retention_days),
preferred_download_type_(download_type::default_),
retry_read_count_(default_retry_read_count),
ring_buffer_file_size_(default_ring_buffer_file_size),
@ -180,8 +179,6 @@ app_config::app_config(const provider_type &prov,
[this]() { return std::to_string(get_med_frequency_interval_secs()); }},
{JSON_ONLINE_CHECK_RETRY_SECS,
[this]() { return std::to_string(get_online_check_retry_secs()); }},
{JSON_ORPHANED_FILE_RETENTION_DAYS,
[this]() { return std::to_string(get_orphaned_file_retention_days()); }},
{JSON_PREFERRED_DOWNLOAD_TYPE,
[this]() {
return download_type_to_string(get_preferred_download_type());
@ -433,13 +430,6 @@ app_config::app_config(const provider_type &prov,
return std::to_string(get_online_check_retry_secs());
},
},
{
JSON_ORPHANED_FILE_RETENTION_DAYS,
[this](const std::string &value) {
set_orphaned_file_retention_days(utils::string::to_uint16(value));
return std::to_string(get_orphaned_file_retention_days());
},
},
{
JSON_PREFERRED_DOWNLOAD_TYPE,
[this](const std::string &value) {
@ -812,7 +802,6 @@ auto app_config::get_json() const -> json {
{JSON_MAX_UPLOAD_COUNT, max_upload_count_},
{JSON_MED_FREQ_INTERVAL_SECS, med_freq_interval_secs_},
{JSON_ONLINE_CHECK_RETRY_SECS, online_check_retry_secs_},
{JSON_ORPHANED_FILE_RETENTION_DAYS, orphaned_file_retention_days_},
{JSON_PREFERRED_DOWNLOAD_TYPE, preferred_download_type_},
{JSON_REMOTE_CONFIG, remote_config_},
{JSON_REMOTE_MOUNT, remote_mount_},
@ -834,7 +823,6 @@ auto app_config::get_json() const -> json {
ret.erase(JSON_MAX_CACHE_SIZE_BYTES);
ret.erase(JSON_MAX_UPLOAD_COUNT);
ret.erase(JSON_ONLINE_CHECK_RETRY_SECS);
ret.erase(JSON_ORPHANED_FILE_RETENTION_DAYS);
ret.erase(JSON_PREFERRED_DOWNLOAD_TYPE);
ret.erase(JSON_REMOTE_CONFIG);
ret.erase(JSON_RETRY_READ_COUNT);
@ -856,7 +844,6 @@ auto app_config::get_json() const -> json {
ret.erase(JSON_MAX_UPLOAD_COUNT);
ret.erase(JSON_MED_FREQ_INTERVAL_SECS);
ret.erase(JSON_ONLINE_CHECK_RETRY_SECS);
ret.erase(JSON_ORPHANED_FILE_RETENTION_DAYS);
ret.erase(JSON_PREFERRED_DOWNLOAD_TYPE);
ret.erase(JSON_REMOTE_MOUNT);
ret.erase(JSON_RETRY_READ_COUNT);
@ -912,12 +899,6 @@ auto app_config::get_online_check_retry_secs() const -> std::uint16_t {
return std::max(min_online_check_retry_secs, online_check_retry_secs_.load());
}
auto app_config::get_orphaned_file_retention_days() const -> std::uint16_t {
return std::min(max_orphaned_file_retention_days,
std::max(min_orphaned_file_retention_days,
orphaned_file_retention_days_.load()));
}
auto app_config::get_preferred_download_type() const -> download_type {
return preferred_download_type_;
}
@ -1053,8 +1034,6 @@ auto app_config::load() -> bool {
med_freq_interval_secs_, found);
get_value(json_document, JSON_ONLINE_CHECK_RETRY_SECS,
online_check_retry_secs_, found);
get_value(json_document, JSON_ORPHANED_FILE_RETENTION_DAYS,
orphaned_file_retention_days_, found);
get_value(json_document, JSON_PREFERRED_DOWNLOAD_TYPE,
preferred_download_type_, found);
get_value(json_document, JSON_REMOTE_CONFIG, remote_config_, found);
@ -1206,10 +1185,6 @@ void app_config::set_online_check_retry_secs(std::uint16_t value) {
set_value(online_check_retry_secs_, value);
}
void app_config::set_orphaned_file_retention_days(std::uint16_t value) {
set_value(orphaned_file_retention_days_, value);
}
void app_config::set_preferred_download_type(const download_type &value) {
set_value(preferred_download_type_, value);
}

View File

@ -89,7 +89,6 @@ static void defaults_tests(const json &json_data, provider_type prov) {
{JSON_MAX_UPLOAD_COUNT, default_max_upload_count},
{JSON_MED_FREQ_INTERVAL_SECS, default_med_freq_interval_secs},
{JSON_ONLINE_CHECK_RETRY_SECS, default_online_check_retry_secs},
{JSON_ORPHANED_FILE_RETENTION_DAYS, default_orphaned_file_retention_days},
{JSON_PREFERRED_DOWNLOAD_TYPE, download_type::default_},
{JSON_REMOTE_CONFIG, remote::remote_config{}},
{JSON_REMOTE_MOUNT, remote::remote_mount{}},
@ -111,7 +110,6 @@ static void defaults_tests(const json &json_data, provider_type prov) {
json_defaults.erase(JSON_MAX_CACHE_SIZE_BYTES);
json_defaults.erase(JSON_MAX_UPLOAD_COUNT);
json_defaults.erase(JSON_ONLINE_CHECK_RETRY_SECS);
json_defaults.erase(JSON_ORPHANED_FILE_RETENTION_DAYS);
json_defaults.erase(JSON_PREFERRED_DOWNLOAD_TYPE);
json_defaults.erase(JSON_REMOTE_CONFIG);
json_defaults.erase(JSON_RETRY_READ_COUNT);
@ -136,7 +134,6 @@ static void defaults_tests(const json &json_data, provider_type prov) {
json_defaults.erase(JSON_MAX_UPLOAD_COUNT);
json_defaults.erase(JSON_MED_FREQ_INTERVAL_SECS);
json_defaults.erase(JSON_ONLINE_CHECK_RETRY_SECS);
json_defaults.erase(JSON_ORPHANED_FILE_RETENTION_DAYS);
json_defaults.erase(JSON_PREFERRED_DOWNLOAD_TYPE);
json_defaults.erase(JSON_REMOTE_MOUNT);
json_defaults.erase(JSON_RETRY_READ_COUNT);
@ -314,10 +311,13 @@ static void common_tests(app_config &config, provider_type prov) {
EXPECT_EQ(min_cache_size_bytes, cfg.get_max_cache_size_bytes());
}},
{JSON_MAX_UPLOAD_COUNT,
[](auto &&cfg) {
[](app_config &cfg) {
test_getter_setter(cfg, &app_config::get_max_upload_count,
&app_config::set_max_upload_count, std::uint8_t{1U},
std::uint8_t{2U}, JSON_MAX_UPLOAD_COUNT, "3");
cfg.set_max_upload_count(0U);
EXPECT_EQ(1U, cfg.get_max_upload_count());
}},
{JSON_MED_FREQ_INTERVAL_SECS,
[](app_config &cfg) {
@ -332,9 +332,26 @@ static void common_tests(app_config &config, provider_type prov) {
cfg.set_med_frequency_interval_secs(0U);
EXPECT_EQ(1U, cfg.get_med_frequency_interval_secs());
}},
{JSON_ONLINE_CHECK_RETRY_SECS, [](auto &&cfg) {}},
{JSON_ORPHANED_FILE_RETENTION_DAYS, [](auto &&cfg) {}},
{JSON_PREFERRED_DOWNLOAD_TYPE, [](auto &&cfg) {}},
{JSON_ONLINE_CHECK_RETRY_SECS,
[](app_config &cfg) {
test_getter_setter(cfg, &app_config::get_online_check_retry_secs,
&app_config::set_online_check_retry_secs,
std::uint16_t{min_online_check_retry_secs + 1U},
std::uint16_t{min_online_check_retry_secs + 2U},
JSON_ONLINE_CHECK_RETRY_SECS,
std::to_string(min_online_check_retry_secs + 3U));
cfg.set_online_check_retry_secs(min_online_check_retry_secs - 1U);
EXPECT_EQ(min_online_check_retry_secs,
cfg.get_online_check_retry_secs());
}},
{JSON_PREFERRED_DOWNLOAD_TYPE,
[](app_config &cfg) {
test_getter_setter(cfg, &app_config::get_preferred_download_type,
&app_config::set_preferred_download_type,
download_type::direct, download_type::default_,
JSON_PREFERRED_DOWNLOAD_TYPE, "ring_buffer");
}},
{JSON_REMOTE_CONFIG, [](auto &&cfg) {}},
{JSON_REMOTE_MOUNT, [](auto &&cfg) {}},
{JSON_RETRY_READ_COUNT, [](auto &&cfg) {}},
@ -354,7 +371,6 @@ static void common_tests(app_config &config, provider_type prov) {
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);
@ -377,7 +393,6 @@ static void common_tests(app_config &config, provider_type prov) {
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);