diff --git a/repertory/repertory_test/src/app_config_test.cpp b/repertory/repertory_test/src/app_config_test.cpp index 0ec90fad..414c8c3e 100644 --- a/repertory/repertory_test/src/app_config_test.cpp +++ b/repertory/repertory_test/src/app_config_test.cpp @@ -35,6 +35,7 @@ public: static std::atomic idx; std::string encrypt_directory; + std::string remote_directory; std::string s3_directory; std::string sia_directory; @@ -46,6 +47,13 @@ public: std::to_string(++idx), }); + remote_directory = utils::path::combine(test::get_test_output_dir(), + { + "app_config_test", + "remote", + std::to_string(++idx), + }); + s3_directory = utils::path::combine(test::get_test_output_dir(), { "app_config_test", @@ -188,6 +196,10 @@ static void test_getter_setter(app_config &cfg, get_t getter, set_t setter, (cfg.*setter)(val2); ASSERT_TRUE((cfg.*getter)() == val2); + if (key.empty()) { + return; + } + EXPECT_STREQ(val_str.c_str(), cfg.set_value_by_name(key, val_str).c_str()); } @@ -352,8 +364,106 @@ static void common_tests(app_config &config, provider_type prov) { download_type::direct, download_type::default_, JSON_PREFERRED_DOWNLOAD_TYPE, "ring_buffer"); }}, - {JSON_REMOTE_CONFIG, [](auto &&cfg) {}}, - {JSON_REMOTE_MOUNT, [](auto &&cfg) {}}, + {JSON_REMOTE_CONFIG, + [](app_config &cfg) { + remote::remote_config remote_cfg1{}; + remote_cfg1.api_port = 1U; + remote_cfg1.encryption_token = "2"; + remote_cfg1.host_name_or_ip = "3"; + remote_cfg1.max_connections = 4U; + remote_cfg1.recv_timeout_ms = 5U; + remote_cfg1.send_timeout_ms = 6U; + + remote::remote_config remote_cfg2{}; + remote_cfg1.api_port = 6U; + remote_cfg1.encryption_token = "5"; + remote_cfg1.host_name_or_ip = "4"; + remote_cfg1.max_connections = 3U; + remote_cfg1.recv_timeout_ms = 2U; + remote_cfg1.send_timeout_ms = 1U; + + test_getter_setter(cfg, &app_config::get_remote_config, + &app_config::set_remote_config, remote_cfg1, + remote_cfg2, "", ""); + + remote::remote_config remote_cfg3{}; + remote_cfg1.api_port = 1U; + remote_cfg1.encryption_token = "2"; + remote_cfg1.host_name_or_ip = "3"; + remote_cfg1.max_connections = 4U; + remote_cfg1.recv_timeout_ms = 5U; + remote_cfg1.send_timeout_ms = 6U; + + auto value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_API_PORT), + std::to_string(remote_cfg3.api_port)); + EXPECT_STREQ(std::to_string(remote_cfg3.api_port).c_str(), + value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_ENCRYPTION_TOKEN), + remote_cfg3.encryption_token); + EXPECT_STREQ(remote_cfg3.encryption_token.c_str(), value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_HOST_NAME_OR_IP), + remote_cfg3.host_name_or_ip); + EXPECT_STREQ(remote_cfg3.host_name_or_ip.c_str(), value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_MAX_CONNECTIONS), + std::to_string(remote_cfg3.max_connections)); + EXPECT_STREQ(std::to_string(remote_cfg3.max_connections).c_str(), + value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_RECV_TIMEOUT_MS), + std::to_string(remote_cfg3.recv_timeout_ms)); + EXPECT_STREQ(std::to_string(remote_cfg3.recv_timeout_ms).c_str(), + value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_CONFIG, JSON_SEND_TIMEOUT_MS), + std::to_string(remote_cfg3.send_timeout_ms)); + EXPECT_STREQ(std::to_string(remote_cfg3.send_timeout_ms).c_str(), + value.c_str()); + }}, + {JSON_REMOTE_MOUNT, + [](auto &&cfg) { + remote::remote_mount mnt_cfg1{}; + mnt_cfg1.api_port = 1U; + mnt_cfg1.client_pool_size = 2U; + mnt_cfg1.enable = false; + mnt_cfg1.encryption_token = "3"; + + remote::remote_mount mnt_cfg2{}; + mnt_cfg2.api_port = 3U; + mnt_cfg2.client_pool_size = 4U; + mnt_cfg2.enable = true; + mnt_cfg2.encryption_token = "5"; + + test_getter_setter(cfg, &app_config::get_remote_mount, + &app_config::get_remote_mount, mnt_cfg1, mnt_cfg2, + "", ""); + + remote::remote_mount mnt_cfg3{}; + auto value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_API_PORT), + std::to_string(mnt_cfg3.api_port)); + EXPECT_STREQ(std::to_string(mnt_cfg3.api_port).c_str(), value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_CLIENT_POOL_SIZE), + std::to_string(mnt_cfg3.client_pool_size)); + EXPECT_STREQ(std::to_string(mnt_cfg3.client_pool_size).c_str(), + value.c_str()); + + value = cfg.set_value_by_name( + fmt::format("{}.{}", JSON_REMOTE_MOUNT, JSON_ENABLE_REMOTE_MOUNT), + utils::string::from_bool(mnt_cfg3.enable)); + EXPECT_STREQ(utils::string::from_bool(mnt_cfg3.enable).c_str(), + value.c_str()); + }}, {JSON_RETRY_READ_COUNT, [](app_config &cfg) { test_getter_setter(cfg, &app_config::get_retry_read_count, @@ -466,6 +576,12 @@ TEST_F(app_config_test, encrypt_config) { common_tests(config, provider_type::encrypt); } +TEST_F(app_config_test, remote_config) { + app_config config(provider_type::remote, remote_directory); + defaults_tests(config.get_json(), provider_type::remote); + common_tests(config, provider_type::remote); +} + TEST_F(app_config_test, s3_config) { app_config config(provider_type::s3, s3_directory); defaults_tests(config.get_json(), provider_type::s3);