From ad820dcc2791f1429c10d5ee2eb42fb70930fdfa Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 15 Feb 2025 23:29:20 -0600 Subject: [PATCH] [Unit Test] Complete all providers unit tests #12 --- .../providers/encrypt/encrypt_provider.cpp | 23 ++++++++--- .../repertory_test/src/providers_test.cpp | 38 +++++++++---------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp index a33b9c3e..27ecc120 100644 --- a/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp +++ b/repertory/librepertory/src/providers/encrypt/encrypt_provider.cpp @@ -40,6 +40,7 @@ #include "utils/file_utils.hpp" #include "utils/path.hpp" #include "utils/polling.hpp" +#include namespace repertory { encrypt_provider::encrypt_provider(app_config &config) @@ -342,13 +343,23 @@ auto encrypt_provider::get_file_list(api_file_list &list, const auto &cfg{get_encrypt_config()}; try { - for (const auto &dir_entry : utils::file::directory{cfg.path}.get_items()) { - std::string api_path{}; - if (process_directory_entry(*dir_entry.get(), cfg, api_path)) { - list.emplace_back(create_api_file( - api_path, dir_entry->is_directory_item(), dir_entry->get_path())); + using func = std::function; + const func process_directory = [&](std::string path) { + for (const auto &dir_entry : utils::file::directory{path}.get_items()) { + std::string api_path{}; + if (dir_entry->is_directory_item()) { + process_directory_entry(*dir_entry.get(), cfg, api_path); + process_directory(dir_entry->get_path()); + continue; + } + + if (process_directory_entry(*dir_entry.get(), cfg, api_path)) { + list.emplace_back(create_api_file( + api_path, dir_entry->is_directory_item(), dir_entry->get_path())); + } } - } + }; + process_directory(cfg.path); return api_error::success; } catch (const std::exception &ex) { diff --git a/repertory/repertory_test/src/providers_test.cpp b/repertory/repertory_test/src/providers_test.cpp index 5a7e6dd5..2480e6af 100644 --- a/repertory/repertory_test/src/providers_test.cpp +++ b/repertory/repertory_test/src/providers_test.cpp @@ -19,8 +19,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if 0 - #include "test_common.hpp" #include "comm/curl/curl_comm.hpp" @@ -346,8 +344,8 @@ create_file_fails_if_directory_already_exists(i_provider &provider) { static void get_api_path_from_source(const app_config &cfg, i_provider &provider) { if (provider.get_provider_type() == provider_type::encrypt) { - const auto source_path = - utils::path::combine("./test_date/encrypt", {"test.txt"}); + auto source_path = + utils::path::combine("./test_input/encrypt", {"test.txt"}); std::string api_path{}; EXPECT_EQ(api_error::success, @@ -391,13 +389,13 @@ get_api_path_from_source_fails_if_file_not_found(const app_config &cfg, EXPECT_TRUE(api_path.empty()); } -static void get_directory_item_count(const app_config &cfg, +static void get_directory_item_count(const app_config & /* cfg */, i_provider &provider) { if (provider.get_provider_type() == provider_type::encrypt) { EXPECT_EQ(std::size_t(2U), provider.get_directory_item_count("/")); EXPECT_EQ(std::size_t(0U), provider.get_directory_item_count("/not_found")); - const auto source_path = + auto source_path = utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"}); std::string api_path{}; @@ -443,7 +441,7 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) { EXPECT_EQ(std::size_t(46U), file->size); #endif - const auto source_path = + auto source_path = utils::path::combine(cfg.get_encrypt_config().path, {"sub10"}); std::string api_path{}; EXPECT_EQ(api_error::success, @@ -486,7 +484,7 @@ get_directory_items_fails_if_directory_not_found(i_provider &provider) { static void get_directory_items_fails_if_item_is_file(const app_config &cfg, i_provider &provider) { if (provider.get_provider_type() == provider_type::encrypt) { - const auto source_path = + auto source_path = utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); std::string api_path{}; @@ -502,7 +500,7 @@ static void get_directory_items_fails_if_item_is_file(const app_config &cfg, static void get_file(const app_config &cfg, i_provider &provider) { if (provider.get_provider_type() == provider_type::encrypt) { - const auto source_path = + auto source_path = utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); std::string api_path{}; @@ -533,7 +531,7 @@ static void get_file_fails_if_file_not_found(i_provider &provider) { static void get_file_fails_if_item_is_directory(const app_config &cfg, i_provider &provider) { if (provider.get_provider_type() == provider_type::encrypt) { - const auto source_path = + auto source_path = utils::path::combine(cfg.get_encrypt_config().path, {"sub10"}); std::string api_path{}; @@ -630,8 +628,9 @@ static void run_tests(const app_config &cfg, i_provider &provider) { } TEST(providers_test, encrypt_provider) { - const auto config_path = - utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"}); + auto config_path = utils::path::combine(test::get_test_output_dir(), + {"provider", "encrypt"}); + fmt::println("config|{}", config_path); console_consumer consumer{}; event_system::instance().start(); @@ -639,8 +638,9 @@ TEST(providers_test, encrypt_provider) { { app_config cfg(provider_type::encrypt, config_path); - const auto encrypt_path = + auto encrypt_path = utils::path::combine(test::get_test_input_dir(), {"encrypt"}); + fmt::println("encrypt|{}", encrypt_path); EXPECT_STREQ( encrypt_path.c_str(), @@ -674,8 +674,8 @@ TEST(providers_test, encrypt_provider) { } TEST(providers_test, s3_provider) { - const auto config_path = - utils::path::combine(test::get_test_output_dir(), {"s3_provider"}); + auto config_path = + utils::path::combine(test::get_test_output_dir(), {"provider", "s3"}); console_consumer consumer{}; event_system::instance().start(); @@ -685,7 +685,7 @@ TEST(providers_test, s3_provider) { { app_config src_cfg( provider_type::s3, - utils::path::combine(test::get_test_config_dir(), {"storj"})); + utils::path::combine(test::get_test_config_dir(), {"s3"})); cfg.set_s3_config(src_cfg.get_s3_config()); } @@ -714,8 +714,8 @@ TEST(providers_test, s3_provider) { } TEST(providers_test, sia_provider) { - const auto config_path = - utils::path::combine(test::get_test_output_dir(), {"sia_provider"}); + auto config_path = + utils::path::combine(test::get_test_output_dir(), {"sia", "provider"}); console_consumer consumer{}; event_system::instance().start(); @@ -753,5 +753,3 @@ TEST(providers_test, sia_provider) { event_system::instance().stop(); } } // namespace repertory - -#endif // 0