diff --git a/.cspell/words.txt b/.cspell/words.txt index 7ca74458..2d991326 100644 --- a/.cspell/words.txt +++ b/.cspell/words.txt @@ -103,6 +103,7 @@ endforeach endfunction eventlib expect_streq +expect_strne fallocate fallocate_impl fext diff --git a/repertory/repertory_test/include/fixtures/providers_fixture.hpp b/repertory/repertory_test/include/fixtures/providers_fixture.hpp new file mode 100644 index 00000000..7d57ba15 --- /dev/null +++ b/repertory/repertory_test/include/fixtures/providers_fixture.hpp @@ -0,0 +1,221 @@ +/* + Copyright <2018-2025> + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#ifndef REPERTORY_TEST_INCLUDE_FIXTURES_PROVIDERS_FIXTURE_HPP +#define REPERTORY_TEST_INCLUDE_FIXTURES_PROVIDERS_FIXTURE_HPP + +#include "test_common.hpp" + +#include "comm/curl/curl_comm.hpp" +#include "events/event_system.hpp" +#include "file_manager/file_manager.hpp" +#include "fixtures/providers_fixture.hpp" +#include "platform/platform.hpp" +#include "providers/encrypt/encrypt_provider.hpp" +#include "providers/i_provider.hpp" +#include "providers/s3/s3_provider.hpp" +#include "providers/sia/sia_provider.hpp" +#include "utils/collection.hpp" +#include "utils/file.hpp" +#include "utils/path.hpp" +#include "utils/string.hpp" +#include "utils/time.hpp" +#include "utils/utils.hpp" + +namespace repertory { +struct encrypt_provider_type final { + static constexpr provider_type type{provider_type::encrypt}; + + static void setup(std::unique_ptr &comm, + std::unique_ptr &config, + std::unique_ptr &provider) { + auto config_path = + utils::path::combine(test::get_test_output_dir(), { + "provider", + "encrypt", + }); + + config = std::make_unique(type, config_path); + + auto encrypt_path = + utils::path::combine(test::get_test_input_dir(), {"encrypt"}); + + EXPECT_STREQ( + encrypt_path.c_str(), + config->set_value_by_name("EncryptConfig.Path", encrypt_path).c_str()); + EXPECT_STREQ( + "test_token", + config->set_value_by_name("EncryptConfig.EncryptionToken", "test_token") + .c_str()); + + provider = std::make_unique(*config); + EXPECT_TRUE(provider->is_read_only()); + EXPECT_FALSE(provider->is_rename_supported()); + EXPECT_EQ(type, provider->get_provider_type()); + } +}; + +struct s3_provider_encrypted_type final { + static constexpr provider_type type{provider_type::s3}; + + static void setup(std::unique_ptr &comm, + std::unique_ptr &config, + std::unique_ptr &provider) { + auto config_path = + utils::path::combine(test::get_test_output_dir(), { + "provider", + "s3", + }); + + config = std::make_unique(type, config_path); + { + app_config src_cfg( + type, utils::path::combine(test::get_test_config_dir(), {"s3"})); + auto s3_cfg = src_cfg.get_s3_config(); + s3_cfg.encryption_token = "cow_moose_doge_chicken"; + config->set_s3_config(s3_cfg); + } + + comm = std::make_unique(config->get_s3_config()); + + provider = std::make_unique(*config, *comm); + EXPECT_EQ(type, provider->get_provider_type()); + EXPECT_FALSE(provider->is_read_only()); + EXPECT_FALSE(provider->is_rename_supported()); + } +}; + +struct s3_provider_unencrypted_type final { + static constexpr provider_type type{provider_type::s3}; + + static void setup(std::unique_ptr &comm, + std::unique_ptr &config, + std::unique_ptr &provider) { + auto config_path = + utils::path::combine(test::get_test_output_dir(), { + "provider", + "s3", + }); + + config = std::make_unique(type, config_path); + { + app_config src_cfg( + type, utils::path::combine(test::get_test_config_dir(), {"s3"})); + auto s3_cfg = src_cfg.get_s3_config(); + s3_cfg.encryption_token = ""; + config->set_s3_config(s3_cfg); + } + + comm = std::make_unique(config->get_s3_config()); + + provider = std::make_unique(*config, *comm); + EXPECT_EQ(type, provider->get_provider_type()); + EXPECT_FALSE(provider->is_read_only()); + EXPECT_FALSE(provider->is_rename_supported()); + } +}; + +struct sia_provider_type final { + static constexpr provider_type type{provider_type::sia}; + + static void setup(std::unique_ptr &comm, + std::unique_ptr &config, + std::unique_ptr &provider) { + auto config_path = + utils::path::combine(test::get_test_output_dir(), { + "provider", + "sia", + }); + + config = std::make_unique(type, config_path); + { + app_config src_cfg( + provider_type::sia, + utils::path::combine(test::get_test_config_dir(), {"sia"})); + config->set_host_config(src_cfg.get_host_config()); + config->set_sia_config(src_cfg.get_sia_config()); + } + + comm = std::make_unique(config->get_host_config()); + + provider = std::make_unique(*config, *comm); + + EXPECT_EQ(type, provider->get_provider_type()); + EXPECT_FALSE(provider->is_read_only()); + EXPECT_TRUE(provider->is_rename_supported()); + } +}; + +template class providers_test : public ::testing::Test { +public: + static std::unique_ptr comm; + static std::unique_ptr config; + static std::unique_ptr mgr; + static std::unique_ptr provider; + static console_consumer consumer{}; + +protected: + static void SetUpTestCase() { + event_system::instance().start(); + + provider_t::setup(comm, config, provider); + mgr = std::make_unique(*config, *provider); + + EXPECT_TRUE(provider->start( + [&provider](bool directory, api_file &file) -> api_error { + return provider_meta_handler(*provider, directory, file); + }, + mgr.get())); + + mgr->start(); + EXPECT_TRUE(provider->is_online()); + } + + static void TearDownTestCase() { + provider->stop(); + mgr->stop(); + + mgr.reset(); + provider.reset(); + comm.reset(); + + event_system::instance().stop(); + } +}; + +template +std::unique_ptr providers_test::comm; + +template +std::unique_ptr providers_test::config; + +template +std::unique_ptr providers_test::mgr; + +template +std::unique_ptr providers_test::provider; + +using provider_types = + ::testing::Types; +} // namespace repertory + +#endif // REPERTORY_TEST_INCLUDE_FIXTURES_PROVIDERS_FIXTURE_HPP diff --git a/repertory/repertory_test/src/providers_test.cpp b/repertory/repertory_test/src/providers_test.cpp index bcd6afb6..036e5bbb 100644 --- a/repertory/repertory_test/src/providers_test.cpp +++ b/repertory/repertory_test/src/providers_test.cpp @@ -21,20 +21,7 @@ */ #include "test_common.hpp" -#include "comm/curl/curl_comm.hpp" -#include "events/event_system.hpp" -#include "file_manager/file_manager.hpp" -#include "platform/platform.hpp" -#include "providers/encrypt/encrypt_provider.hpp" -#include "providers/i_provider.hpp" -#include "providers/s3/s3_provider.hpp" -#include "providers/sia/sia_provider.hpp" -#include "utils/collection.hpp" -#include "utils/file.hpp" -#include "utils/path.hpp" -#include "utils/string.hpp" -#include "utils/time.hpp" -#include "utils/utils.hpp" +#include "fixtures/providers_fixture.hpp" namespace { #if defined(_WIN32) @@ -181,113 +168,248 @@ const auto pinned_includes_api_path = }); }; -/* -[[nodiscard]] auto read_all_plain(const std::string &path) -> std::string { - repertory::utils::file::file file{path}; - auto data = file.read_all(); - EXPECT_TRUE(data.has_value()); - return data.value_or(std::string{}); -} - -[[nodiscard]] auto chunked_read_bytes(repertory::i_provider &provider, - const std::string &api_path, - std::uint64_t total) -> std::string { - std::string out{}; - std::uint64_t off{0U}; - constexpr const std::array chunks{ - 1U, 7U, 64U, 3U, 1024U, 5U, - }; - std::size_t idx{0U}; - - while (off < total) { - auto want = std::min(chunks.at(idx % std::size(chunks)), - total - off); - std::string part{}; - EXPECT_EQ(api_error::success, - provider.read_file_bytes(api_path, off, want, part)); - EXPECT_EQ(want, static_cast(part.size())); - out.append(part); - off += want; - ++idx; - } - return out; -} */ } // namespace namespace repertory { -static void can_create_and_remove_directory(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { - api_meta_map meta{}; - EXPECT_EQ(api_error::not_implemented, - provider.create_directory("/moose", meta)); +TYPED_TEST_CASE(providers_test, provider_types); - EXPECT_EQ(api_error::not_implemented, provider.remove_directory("/moose")); +TYPED_TEST(providers_test, get_file_list) { + api_file_list list{}; + std::string marker; + EXPECT_EQ(api_error::success, this->provider->get_file_list(list, marker)); + if (this->provider->get_provider_type() == provider_type::encrypt) { + EXPECT_EQ(std::size_t(2U), list.size()); + + std::vector expected_parents{ + {"/"}, + {"/sub10"}, + }; + std::vector expected_paths{ + {"/test.txt"}, + {"/sub10/moose.txt"}, + }; + + for (auto &file : list) { + decrypt_parts(*this->config, file.api_parent); + decrypt_parts(*this->config, file.api_path); + utils::collection::remove_element(expected_parents, file.api_parent); + utils::collection::remove_element(expected_paths, file.api_path); + } + EXPECT_TRUE(expected_parents.empty()); + EXPECT_TRUE(expected_paths.empty()); + } +} + +TYPED_TEST(providers_test, get_and_set_item_meta_with_upload_file) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + std::string api_path{}; + EXPECT_EQ(api_error::success, + this->provider->get_api_path_from_source( + utils::path::combine(this->config->get_encrypt_config().path, + {"test.txt"}), + api_path)); + + std::string val{}; + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, META_SOURCE, val)); + EXPECT_FALSE(val.empty()); + EXPECT_TRUE(utils::file::file{val}.exists()); + + val.clear(); + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, META_DIRECTORY, val)); + EXPECT_FALSE(utils::string::to_bool(val)); return; } - create_directory(provider, "/pt01"); - EXPECT_EQ(api_error::success, provider.remove_directory("/pt01")); + auto &file = test::create_random_file(128U); + auto api_path = + fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); + create_file(*this->provider, api_path); + + stop_type stop_requested{false}; + ASSERT_EQ(api_error::success, this->provider->upload_file( + api_path, file.get_path(), stop_requested)); + + auto size_str = std::to_string(*file.size()); + EXPECT_EQ(api_error::success, + this->provider->set_item_meta(api_path, META_SIZE, size_str)); + EXPECT_EQ(api_error::success, this->provider->set_item_meta( + api_path, META_SOURCE, file.get_path())); + + std::string val{}; + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, META_SIZE, val)); + EXPECT_STREQ(size_str.c_str(), val.c_str()); + + val.clear(); + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, META_SOURCE, val)); + EXPECT_STREQ(file.get_path().c_str(), val.c_str()); + + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path)); +} + +TYPED_TEST(providers_test, can_create_and_remove_directory) { + if (this->provider->is_read_only()) { + api_meta_map meta{}; + EXPECT_EQ(api_error::not_implemented, + this->provider->create_directory("/moose", meta)); + + EXPECT_EQ(api_error::not_implemented, + this->provider->remove_directory("/moose")); + return; + } + + create_directory(*this->provider, "/pt01"); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/pt01")); bool exists{}; - EXPECT_EQ(api_error::success, provider.is_directory("/pt01", exists)); + EXPECT_EQ(api_error::success, this->provider->is_directory("/pt01", exists)); EXPECT_FALSE(exists); } -static void create_directory_fails_if_already_exists(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, get_and_set_item_meta2_with_upload_file) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + std::string api_path{}; + EXPECT_EQ(api_error::success, + this->provider->get_api_path_from_source( + utils::path::combine(this->config->get_encrypt_config().path, + {"test.txt"}), + api_path)); + + api_meta_map meta{}; + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, meta)); + EXPECT_TRUE(meta.contains(META_SOURCE)); + EXPECT_TRUE(meta.contains(META_DIRECTORY)); + EXPECT_FALSE(utils::string::to_bool(meta[META_DIRECTORY])); return; } - create_directory(provider, "/pt01"); + auto &file = test::create_random_file(64U); + auto api_path = + fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); + create_file(*this->provider, api_path); + + stop_type stop_requested{false}; + ASSERT_EQ(api_error::success, this->provider->upload_file( + api_path, file.get_path(), stop_requested)); + + api_meta_map to_set{ + {META_SIZE, std::to_string(*file.size())}, + {META_SOURCE, file.get_path()}, + }; + EXPECT_EQ(api_error::success, + this->provider->set_item_meta(api_path, to_set)); + + api_meta_map meta{}; + EXPECT_EQ(api_error::success, this->provider->get_item_meta(api_path, meta)); + EXPECT_STREQ(std::to_string(*file.size()).c_str(), meta[META_SIZE].c_str()); + EXPECT_STREQ(file.get_path().c_str(), meta[META_SOURCE].c_str()); + EXPECT_FALSE(utils::string::to_bool(meta[META_DIRECTORY])); + + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path)); +} + +TYPED_TEST(providers_test, get_item_meta_fails_if_path_not_found) { + std::string val{}; + EXPECT_EQ( + api_error::item_not_found, + this->provider->get_item_meta("/cow/moose/doge/chicken", META_SIZE, val)); + EXPECT_TRUE(val.empty()); +} + +TYPED_TEST(providers_test, get_item_meta2_fails_if_path_not_found) { + api_meta_map meta{}; + EXPECT_EQ(api_error::item_not_found, + this->provider->get_item_meta("/cow/moose/doge/chicken", meta)); + EXPECT_TRUE(meta.empty()); +} + +TYPED_TEST(providers_test, is_file_fails_if_not_found) { + bool exists{}; + auto res = this->provider->is_file("/cow/moose/doge/chicken", exists); + + EXPECT_EQ(api_error::success, res); + EXPECT_FALSE(exists); +} + +TYPED_TEST(providers_test, is_directory_fails_if_not_found) { + bool exists{}; + auto res = this->provider->is_directory("/cow/moose/doge/chicken", exists); + + EXPECT_EQ(api_error::success, res); + EXPECT_FALSE(exists); +} + +TYPED_TEST(providers_test, can_create_and_remove_file) { + if (this->provider->is_read_only()) { + api_meta_map meta{}; + EXPECT_EQ(api_error::not_implemented, + this->provider->create_file("/moose.txt", meta)); + return; + } + + create_file(*this->provider, "/pt01.txt"); + + bool exists{}; + EXPECT_EQ(api_error::success, this->provider->is_file("/pt01.txt", exists)); + EXPECT_TRUE(exists); + + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); + + EXPECT_EQ(api_error::success, this->provider->is_file("/pt01.txt", exists)); + EXPECT_FALSE(exists); +} + +TYPED_TEST(providers_test, create_directory_fails_if_already_exists) { + if (this->provider->is_read_only()) { + return; + } + + create_directory(*this->provider, "/pt01"); api_meta_map meta{}; EXPECT_EQ(api_error::directory_exists, - provider.create_directory("/pt01", meta)); - EXPECT_EQ(api_error::success, provider.remove_directory("/pt01")); + this->provider->create_directory("/pt01", meta)); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/pt01")); } -static void -create_directory_fails_if_file_already_exists(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, create_directory_fails_if_file_already_exists) { + if (this->provider->is_read_only()) { return; } - create_file(provider, "/pt01"); + create_file(*this->provider, "/pt01"); api_meta_map meta{}; - EXPECT_EQ(api_error::item_exists, provider.create_directory("/pt01", meta)); + EXPECT_EQ(api_error::item_exists, + this->provider->create_directory("/pt01", meta)); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01")); } -static void create_directory_clone_source_meta(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { - EXPECT_EQ(api_error::not_implemented, - provider.create_directory_clone_source_meta("/moose", "/moose")); +TYPED_TEST(providers_test, create_directory_clone_source_meta) { + if (this->provider->is_read_only()) { + EXPECT_EQ( + api_error::not_implemented, + this->provider->create_directory_clone_source_meta("/moose", "/moose")); return; } - create_directory(provider, "/clone"); + create_directory(*this->provider, "/clone"); api_meta_map meta_orig{}; - EXPECT_EQ(api_error::success, provider.get_item_meta("/clone", meta_orig)); - EXPECT_EQ(api_error::success, - provider.create_directory_clone_source_meta("/clone", "/clone2")); + this->provider->get_item_meta("/clone", meta_orig)); + + EXPECT_EQ( + api_error::success, + this->provider->create_directory_clone_source_meta("/clone", "/clone2")); api_meta_map meta_clone{}; - EXPECT_EQ(api_error::success, provider.get_item_meta("/clone2", meta_clone)); + EXPECT_EQ(api_error::success, + this->provider->get_item_meta("/clone2", meta_clone)); EXPECT_EQ(meta_orig.size(), meta_clone.size()); for (const auto &item : meta_orig) { @@ -301,158 +423,115 @@ static void create_directory_clone_source_meta(i_provider &provider) { EXPECT_STREQ(item.second.c_str(), meta_clone[item.first].c_str()); } - EXPECT_EQ(api_error::success, provider.remove_directory("/clone")); - EXPECT_EQ(api_error::success, provider.remove_directory("/clone2")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/clone")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/clone2")); } -static void create_directory_clone_source_meta_fails_if_already_exists( - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, + create_directory_clone_source_meta_fails_if_already_exists) { + if (this->provider->is_read_only()) { return; } - create_directory(provider, "/clone"); - create_directory(provider, "/clone2"); + create_directory(*this->provider, "/clone"); + create_directory(*this->provider, "/clone2"); - EXPECT_EQ(api_error::directory_exists, - provider.create_directory_clone_source_meta("/clone", "/clone2")); + EXPECT_EQ( + api_error::directory_exists, + this->provider->create_directory_clone_source_meta("/clone", "/clone2")); - EXPECT_EQ(api_error::success, provider.remove_directory("/clone")); - EXPECT_EQ(api_error::success, provider.remove_directory("/clone2")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/clone")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/clone2")); } -static void create_directory_clone_source_meta_fails_if_directory_not_found( - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, + create_directory_clone_source_meta_fails_if_directory_not_found) { + if (this->provider->is_read_only()) { return; } - EXPECT_EQ(api_error::directory_not_found, - provider.create_directory_clone_source_meta("/clone", "/clone2")); + EXPECT_EQ( + api_error::directory_not_found, + this->provider->create_directory_clone_source_meta("/clone", "/clone2")); } -static void create_directory_clone_source_meta_fails_if_file_already_exists( - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, + create_directory_clone_source_meta_fails_if_file_already_exists) { + if (this->provider->is_read_only()) { return; } - create_directory(provider, "/clone"); - create_file(provider, "/clone2"); + create_directory(*this->provider, "/clone"); + create_file(*this->provider, "/clone2"); + EXPECT_EQ( + api_error::item_exists, + this->provider->create_directory_clone_source_meta("/clone", "/clone2")); + + EXPECT_EQ(api_error::success, this->provider->remove_directory("/clone")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/clone2")); +} + +TYPED_TEST(providers_test, create_file_fails_if_already_exists) { + if (this->provider->is_read_only()) { + return; + } + + create_file(*this->provider, "/pt01.txt"); + + api_meta_map meta{}; EXPECT_EQ(api_error::item_exists, - provider.create_directory_clone_source_meta("/clone", "/clone2")); + this->provider->create_file("/pt01.txt", meta)); - EXPECT_EQ(api_error::success, provider.remove_directory("/clone")); - EXPECT_EQ(api_error::success, provider.remove_file("/clone2")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); } -static void can_create_and_remove_file(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { - api_meta_map meta{}; - EXPECT_EQ(api_error::not_implemented, - provider.create_file("/moose.txt", meta)); +TYPED_TEST(providers_test, create_file_fails_if_directory_already_exists) { + if (this->provider->is_read_only()) { return; } - create_file(provider, "/pt01.txt"); - - bool exists{}; - EXPECT_EQ(api_error::success, provider.is_file("/pt01.txt", exists)); - EXPECT_TRUE(exists); - - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); - - EXPECT_EQ(api_error::success, provider.is_file("/pt01.txt", exists)); - EXPECT_FALSE(exists); -} - -static void create_file_fails_if_already_exists(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { - return; - } - - create_file(provider, "/pt01.txt"); + create_directory(*this->provider, "/pt01"); api_meta_map meta{}; - EXPECT_EQ(api_error::item_exists, provider.create_file("/pt01.txt", meta)); + EXPECT_EQ(api_error::directory_exists, + this->provider->create_file("/pt01", meta)); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/pt01")); } -static void -create_file_fails_if_directory_already_exists(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { - return; - } - - create_directory(provider, "/pt01"); - - api_meta_map meta{}; - EXPECT_EQ(api_error::directory_exists, provider.create_file("/pt01", meta)); - - EXPECT_EQ(api_error::success, provider.remove_directory("/pt01")); -} - -static void get_api_path_from_source(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.get_provider_type() == provider_type::encrypt) { +TYPED_TEST(providers_test, get_api_path_from_source) { + if (this->provider->get_provider_type() == provider_type::encrypt) { auto source_path = utils::path::combine("./test_input/encrypt", {"test.txt"}); std::string api_path{}; EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); std::string file_name{api_path.substr(1U)}; - decrypt_parts(cfg, file_name); + decrypt_parts(*this->config, file_name); EXPECT_STREQ("test.txt", file_name.c_str()); return; } - create_file(provider, "/pt01.txt"); + create_file(*this->provider, "/pt01.txt"); filesystem_item fsi{}; EXPECT_EQ(api_error::success, - provider.get_filesystem_item("/pt01.txt", false, fsi)); + this->provider->get_filesystem_item("/pt01.txt", false, fsi)); std::string api_path{}; - EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(fsi.source_path, api_path)); + EXPECT_EQ(api_error::success, this->provider->get_api_path_from_source( + fsi.source_path, api_path)); EXPECT_STREQ("/pt01.txt", api_path.c_str()); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); } -static void -get_api_path_from_source_fails_if_file_not_found(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); +TYPED_TEST(providers_test, get_api_path_from_source_fails_if_file_not_found) { std::string source_path{}; - if (provider.get_provider_type() == provider_type::encrypt) { - source_path = utils::path::combine(cfg.get_encrypt_config().path, + if (this->provider->get_provider_type() == provider_type::encrypt) { + source_path = utils::path::combine(this->config->get_encrypt_config().path, {"test_not_found.txt"}); } else { source_path = utils::path::combine("./", {"test_not_found.txt"}); @@ -460,61 +539,24 @@ get_api_path_from_source_fails_if_file_not_found(const app_config &cfg, std::string api_path{}; EXPECT_EQ(api_error::item_not_found, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); EXPECT_TRUE(api_path.empty()); } -static void get_directory_item_count(const app_config & /* cfg */, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - 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")); - - auto source_path = - utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"}); - - std::string api_path{}; - EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); - EXPECT_EQ(std::size_t(1U), provider.get_directory_item_count(api_path)); - return; - } - - create_file(provider, "/pt01.txt"); - create_file(provider, "/pt02.txt"); - create_directory(provider, "/dir01"); - create_directory(provider, "/dir02"); - - directory_item_list list{}; - EXPECT_EQ(api_error::success, provider.get_directory_items("/", list)); - check_forced_dirs(list); - EXPECT_GE(list.size(), std::size_t(6U)); - - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pt02.txt")); - EXPECT_EQ(api_error::success, provider.remove_directory("/dir01")); - EXPECT_EQ(api_error::success, provider.remove_directory("/dir02")); -} - -static void get_directory_items(const app_config &cfg, i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.get_provider_type() == provider_type::encrypt) { +TYPED_TEST(providers_test, get_directory_items) { + if (this->provider->get_provider_type() == provider_type::encrypt) { directory_item_list list{}; - EXPECT_EQ(api_error::success, provider.get_directory_items("/", list)); + EXPECT_EQ(api_error::success, + this->provider->get_directory_items("/", list)); check_forced_dirs(list); EXPECT_EQ(std::size_t(4U), list.size()); directory_item_list list_decrypted{list.begin() + 2U, list.end()}; for (auto &dir_item : list_decrypted) { - decrypt_parts(cfg, dir_item.api_parent); - decrypt_parts(cfg, dir_item.api_path); + decrypt_parts(*this->config, dir_item.api_parent); + decrypt_parts(*this->config, dir_item.api_path); } auto dir = @@ -539,21 +581,22 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) { EXPECT_EQ(std::size_t(82U), file->size); #endif - auto source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"sub10"}); + auto source_path = utils::path::combine( + this->config->get_encrypt_config().path, {"sub10"}); std::string api_path{}; EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); list.clear(); - EXPECT_EQ(api_error::success, provider.get_directory_items(api_path, list)); + EXPECT_EQ(api_error::success, + this->provider->get_directory_items(api_path, list)); check_forced_dirs(list); EXPECT_EQ(std::size_t(3U), list.size()); directory_item_list list_decrypted2{list.begin() + 2U, list.end()}; for (auto &dir_item : list_decrypted2) { - decrypt_parts(cfg, dir_item.api_parent); - decrypt_parts(cfg, dir_item.api_path); + decrypt_parts(*this->config, dir_item.api_parent); + decrypt_parts(*this->config, dir_item.api_path); } auto file2 = @@ -571,13 +614,13 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) { return; } - create_file(provider, "/pt01.txt"); - create_file(provider, "/pt02.txt"); - create_directory(provider, "/dir01"); - create_directory(provider, "/dir02"); + create_file(*this->provider, "/pt01.txt"); + create_file(*this->provider, "/pt02.txt"); + create_directory(*this->provider, "/dir01"); + create_directory(*this->provider, "/dir02"); directory_item_list list{}; - EXPECT_EQ(api_error::success, provider.get_directory_items("/", list)); + EXPECT_EQ(api_error::success, this->provider->get_directory_items("/", list)); check_forced_dirs(list); EXPECT_GE(list.size(), std::size_t(6U)); @@ -609,68 +652,88 @@ static void get_directory_items(const app_config &cfg, i_provider &provider) { EXPECT_TRUE((*iter).directory); EXPECT_EQ(std::uint64_t{0U}, (*iter).size); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pt02.txt")); - EXPECT_EQ(api_error::success, provider.remove_directory("/dir01")); - EXPECT_EQ(api_error::success, provider.remove_directory("/dir02")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt02.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir01")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir02")); } - -static void -get_directory_items_fails_if_directory_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); +TYPED_TEST(providers_test, get_directory_items_fails_if_directory_not_found) { directory_item_list list{}; EXPECT_EQ(api_error::directory_not_found, - provider.get_directory_items("/not_found", list)); + this->provider->get_directory_items("/not_found", list)); EXPECT_TRUE(list.empty()); } -static void get_directory_items_fails_if_item_is_file(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.get_provider_type() == provider_type::encrypt) { - auto source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); +TYPED_TEST(providers_test, get_directory_items_fails_if_item_is_file) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + auto source_path = utils::path::combine( + this->config->get_encrypt_config().path, {"test.txt"}); std::string api_path{}; EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); directory_item_list list{}; EXPECT_EQ(api_error::item_exists, - provider.get_directory_items(api_path, list)); + this->provider->get_directory_items(api_path, list)); EXPECT_TRUE(list.empty()); return; } - create_file(provider, "/pt01.txt"); + create_file(*this->provider, "/pt01.txt"); directory_item_list list{}; EXPECT_EQ(api_error::item_exists, - provider.get_directory_items("/pt01.txt", list)); + this->provider->get_directory_items("/pt01.txt", list)); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); } +TYPED_TEST(providers_test, get_directory_item_count) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + EXPECT_EQ(std::size_t(2U), this->provider->get_directory_item_count("/")); + EXPECT_EQ(std::size_t(0U), + this->provider->get_directory_item_count("/not_found")); -static void get_file(const app_config &cfg, i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.get_provider_type() == provider_type::encrypt) { auto source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); + utils::path::combine(test::get_test_input_dir(), {"encrypt", "sub10"}); std::string api_path{}; EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); + EXPECT_EQ(std::size_t(1U), + this->provider->get_directory_item_count(api_path)); + return; + } + + create_file(*this->provider, "/pt01.txt"); + create_file(*this->provider, "/pt02.txt"); + create_directory(*this->provider, "/dir01"); + create_directory(*this->provider, "/dir02"); + + directory_item_list list{}; + EXPECT_EQ(api_error::success, this->provider->get_directory_items("/", list)); + check_forced_dirs(list); + EXPECT_GE(list.size(), std::size_t(6U)); + + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt02.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir01")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir02")); +} + +TYPED_TEST(providers_test, get_file) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + auto source_path = utils::path::combine( + this->config->get_encrypt_config().path, {"test.txt"}); + + std::string api_path{}; + EXPECT_EQ(api_error::success, + this->provider->get_api_path_from_source(source_path, api_path)); api_file file{}; - EXPECT_EQ(api_error::success, provider.get_file(api_path, file)); - decrypt_parts(cfg, file.api_path); - decrypt_parts(cfg, file.api_parent); + EXPECT_EQ(api_error::success, this->provider->get_file(api_path, file)); + decrypt_parts(*this->config, file.api_path); + decrypt_parts(*this->config, file.api_parent); EXPECT_STREQ("/test.txt", file.api_path.c_str()); EXPECT_STREQ("/", file.api_parent.c_str()); @@ -683,10 +746,10 @@ static void get_file(const app_config &cfg, i_provider &provider) { return; } - create_file(provider, "/pt01.txt"); + create_file(*this->provider, "/pt01.txt"); api_file file{}; - EXPECT_EQ(api_error::success, provider.get_file("/pt01.txt", file)); + EXPECT_EQ(api_error::success, this->provider->get_file("/pt01.txt", file)); EXPECT_STREQ("/pt01.txt", file.api_path.c_str()); EXPECT_STREQ("/", file.api_parent.c_str()); @@ -699,91 +762,50 @@ static void get_file(const app_config &cfg, i_provider &provider) { EXPECT_LT(utils::time::get_time_now() - (utils::time::NANOS_PER_SECOND * 5U), file.modified_date); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); } - -static void get_file_fails_if_file_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); +TYPED_TEST(providers_test, get_file_fails_if_file_not_found) { api_file file{}; - EXPECT_EQ(api_error::item_not_found, provider.get_file("/not_found", file)); + EXPECT_EQ(api_error::item_not_found, + this->provider->get_file("/not_found", file)); } -static void get_file_fails_if_item_is_directory(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.get_provider_type() == provider_type::encrypt) { - auto source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"sub10"}); +TYPED_TEST(providers_test, get_file_fails_if_item_is_directory) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + auto source_path = utils::path::combine( + this->config->get_encrypt_config().path, {"sub10"}); std::string api_path{}; EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); api_file file{}; - EXPECT_EQ(api_error::directory_exists, provider.get_file(api_path, file)); + EXPECT_EQ(api_error::directory_exists, + this->provider->get_file(api_path, file)); return; } - create_directory(provider, "/dir01"); + create_directory(*this->provider, "/dir01"); api_file file{}; - EXPECT_EQ(api_error::directory_exists, provider.get_file("/dir01", file)); + EXPECT_EQ(api_error::directory_exists, + this->provider->get_file("/dir01", file)); - EXPECT_EQ(api_error::success, provider.remove_directory("/dir01")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir01")); } - -static void get_file_list(const app_config &cfg, i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - api_file_list list{}; - std::string marker; - EXPECT_EQ(api_error::success, provider.get_file_list(list, marker)); - if (provider.get_provider_type() == provider_type::encrypt) { - EXPECT_EQ(std::size_t(2U), list.size()); - - std::vector expected_parents{ - {"/"}, - {"/sub10"}, - }; - std::vector expected_paths{ - {"/test.txt"}, - {"/sub10/moose.txt"}, - }; - - for (auto &file : list) { - decrypt_parts(cfg, file.api_parent); - decrypt_parts(cfg, file.api_path); - utils::collection::remove_element(expected_parents, file.api_parent); - utils::collection::remove_element(expected_paths, file.api_path); - } - EXPECT_TRUE(expected_parents.empty()); - EXPECT_TRUE(expected_paths.empty()); - } -} - -static void get_file_size(const app_config &cfg, i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.get_provider_type() == provider_type::encrypt) { - auto source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); +TYPED_TEST(providers_test, get_file_size) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + auto source_path = utils::path::combine( + this->config->get_encrypt_config().path, {"test.txt"}); auto src_size = utils::file::file{source_path}.size(); EXPECT_TRUE(src_size.has_value()); std::string api_path{}; EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); std::uint64_t size{}; - auto res = provider.get_file_size(api_path, size); + auto res = this->provider->get_file_size(api_path, size); EXPECT_EQ(api_error::success, res); EXPECT_EQ(utils::encryption::encrypting_reader::calculate_encrypted_size( src_size.value(), true), @@ -794,55 +816,48 @@ static void get_file_size(const app_config &cfg, i_provider &provider) { auto &file = test::create_random_file(128U); auto api_path = fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); - create_file(provider, api_path); + create_file(*this->provider, api_path); stop_type stop_requested{false}; - auto res = provider.upload_file(api_path, file.get_path(), stop_requested); + auto res = + this->provider->upload_file(api_path, file.get_path(), stop_requested); ASSERT_EQ(api_error::success, res); std::uint64_t size{}; - res = provider.get_file_size(api_path, size); + res = this->provider->get_file_size(api_path, size); EXPECT_EQ(api_error::success, res); EXPECT_EQ(*file.size(), size); - res = provider.remove_file(api_path); + res = this->provider->remove_file(api_path); EXPECT_EQ(api_error::success, res); } -static void get_file_size_fails_if_path_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, get_file_size_fails_if_path_not_found) { std::uint64_t size{}; - auto res = provider.get_file_size("/cow/moose/doge/chicken", size); + auto res = this->provider->get_file_size("/cow/moose/doge/chicken", size); EXPECT_EQ(api_error::item_not_found, res); EXPECT_EQ(0U, size); } -static void get_filesystem_item(const app_config &cfg, i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.get_provider_type() == provider_type::encrypt) { +TYPED_TEST(providers_test, get_filesystem_item) { + if (this->provider->get_provider_type() == provider_type::encrypt) { std::string api_path{}; - EXPECT_EQ( - api_error::success, - provider.get_api_path_from_source( - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}), - api_path)); + EXPECT_EQ(api_error::success, + this->provider->get_api_path_from_source( + utils::path::combine(this->config->get_encrypt_config().path, + {"test.txt"}), + api_path)); filesystem_item fsi{}; - auto res = provider.get_filesystem_item(api_path, false, fsi); + auto res = this->provider->get_filesystem_item(api_path, false, fsi); EXPECT_EQ(api_error::success, res); EXPECT_FALSE(fsi.directory); EXPECT_EQ(api_path, fsi.api_path); std::uint64_t size{}; - res = provider.get_file_size(api_path, size); + res = this->provider->get_file_size(api_path, size); ASSERT_EQ(api_error::success, res); EXPECT_EQ(size, fsi.size); @@ -852,74 +867,58 @@ static void get_filesystem_item(const app_config &cfg, i_provider &provider) { auto &file = test::create_random_file(128U); auto api_path = fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); - create_file(provider, api_path); + create_file(*this->provider, api_path); stop_type stop_requested{false}; - auto res = provider.upload_file(api_path, file.get_path(), stop_requested); + auto res = + this->provider->upload_file(api_path, file.get_path(), stop_requested); ASSERT_EQ(api_error::success, res); EXPECT_EQ(api_error::success, - provider.set_item_meta(api_path, META_SIZE, - std::to_string(*file.size()))); + this->provider->set_item_meta(api_path, META_SIZE, + std::to_string(*file.size()))); filesystem_item fsi{}; - res = provider.get_filesystem_item(api_path, false, fsi); + res = this->provider->get_filesystem_item(api_path, false, fsi); EXPECT_EQ(api_error::success, res); EXPECT_EQ(api_path, fsi.api_path); EXPECT_FALSE(fsi.directory); EXPECT_EQ(*file.size(), fsi.size); - res = provider.remove_file(api_path); + res = this->provider->remove_file(api_path); EXPECT_EQ(api_error::success, res); } -static void get_filesystem_item_root_is_directory(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, get_filesystem_item_root_is_directory) { filesystem_item fsi{}; - auto res = provider.get_filesystem_item("/", true, fsi); + auto res = this->provider->get_filesystem_item("/", true, fsi); EXPECT_EQ(api_error::success, res); EXPECT_TRUE(fsi.directory); EXPECT_EQ("/", fsi.api_path); } -static void -get_filesystem_item_fails_if_file_is_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, get_filesystem_item_fails_if_file_is_not_found) { filesystem_item fsi{}; - auto res = - provider.get_filesystem_item("/cow/moose/doge/chicken", false, fsi); + auto res = this->provider->get_filesystem_item("/cow/moose/doge/chicken", + false, fsi); EXPECT_EQ(api_error::item_not_found, res); } -static void -get_filesystem_item_fails_if_directory_is_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, + get_filesystem_item_fails_if_directory_is_not_found) { filesystem_item fsi{}; - auto res = provider.get_filesystem_item("/cow/moose/doge/chicken", true, fsi); + auto res = + this->provider->get_filesystem_item("/cow/moose/doge/chicken", true, fsi); EXPECT_EQ(api_error::directory_not_found, res); } -static void get_filesystem_item_from_source_path(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, get_filesystem_item_from_source_path) { std::string api_path; std::string source_path; std::uint64_t size{}; - if (provider.get_provider_type() == provider_type::encrypt) { - source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); + if (this->provider->get_provider_type() == provider_type::encrypt) { + source_path = utils::path::combine(this->config->get_encrypt_config().path, + {"test.txt"}); auto src_size = utils::file::file{source_path}.size(); EXPECT_TRUE(src_size.has_value()); @@ -931,409 +930,226 @@ static void get_filesystem_item_from_source_path(const app_config &cfg, api_path = fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); source_path = file.get_path(); - create_file(provider, api_path); + create_file(*this->provider, api_path); - EXPECT_EQ( - api_error::success, - provider.set_item_meta(api_path, { - {META_SIZE, std::to_string(size)}, - {META_SOURCE, source_path}, - })); + EXPECT_EQ(api_error::success, + this->provider->set_item_meta( + api_path, { + {META_SIZE, std::to_string(size)}, + {META_SOURCE, source_path}, + })); stop_type stop_requested{false}; - auto res = provider.upload_file(api_path, source_path, stop_requested); + auto res = + this->provider->upload_file(api_path, source_path, stop_requested); ASSERT_EQ(api_error::success, res); } filesystem_item fsi{}; - auto res = provider.get_filesystem_item_from_source_path(source_path, fsi); + auto res = + this->provider->get_filesystem_item_from_source_path(source_path, fsi); EXPECT_EQ(api_error::success, res); EXPECT_FALSE(fsi.directory); EXPECT_EQ(size, fsi.size); - if (provider.get_provider_type() != provider_type::encrypt) { - EXPECT_EQ(api_error::success, provider.remove_file(api_path)); + if (this->provider->get_provider_type() != provider_type::encrypt) { + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path)); } } - -static void get_filesystem_item_from_source_path_fails_if_file_is_not_found( - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, + get_filesystem_item_from_source_path_fails_if_file_is_not_found) { filesystem_item fsi{}; - auto res = provider.get_filesystem_item_from_source_path( + auto res = this->provider->get_filesystem_item_from_source_path( "/cow/moose/doge/chicken", fsi); EXPECT_EQ(api_error::item_not_found, res); } -static void get_and_set_item_meta_with_upload_file(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.get_provider_type() == provider_type::encrypt) { - std::string api_path{}; - EXPECT_EQ( - api_error::success, - provider.get_api_path_from_source( - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}), - api_path)); - - std::string val{}; - EXPECT_EQ(api_error::success, - provider.get_item_meta(api_path, META_SOURCE, val)); - EXPECT_FALSE(val.empty()); - EXPECT_TRUE(utils::file::file{val}.exists()); - - val.clear(); - EXPECT_EQ(api_error::success, - provider.get_item_meta(api_path, META_DIRECTORY, val)); - EXPECT_FALSE(utils::string::to_bool(val)); - return; - } - - auto &file = test::create_random_file(128U); - auto api_path = - fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); - create_file(provider, api_path); - - stop_type stop_requested{false}; - ASSERT_EQ(api_error::success, - provider.upload_file(api_path, file.get_path(), stop_requested)); - - auto size_str = std::to_string(*file.size()); - EXPECT_EQ(api_error::success, - provider.set_item_meta(api_path, META_SIZE, size_str)); - EXPECT_EQ(api_error::success, - provider.set_item_meta(api_path, META_SOURCE, file.get_path())); - - std::string val{}; - EXPECT_EQ(api_error::success, - provider.get_item_meta(api_path, META_SIZE, val)); - EXPECT_STREQ(size_str.c_str(), val.c_str()); - - val.clear(); - EXPECT_EQ(api_error::success, - provider.get_item_meta(api_path, META_SOURCE, val)); - EXPECT_STREQ(file.get_path().c_str(), val.c_str()); - - EXPECT_EQ(api_error::success, provider.remove_file(api_path)); -} - -static void get_and_set_item_meta2_with_upload_file(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.get_provider_type() == provider_type::encrypt) { - std::string api_path{}; - EXPECT_EQ( - api_error::success, - provider.get_api_path_from_source( - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}), - api_path)); - - api_meta_map meta{}; - EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, meta)); - EXPECT_TRUE(meta.contains(META_SOURCE)); - EXPECT_TRUE(meta.contains(META_DIRECTORY)); - EXPECT_FALSE(utils::string::to_bool(meta[META_DIRECTORY])); - return; - } - - auto &file = test::create_random_file(64U); - auto api_path = - fmt::format("/{}", utils::path::strip_to_file_name(file.get_path())); - create_file(provider, api_path); - - stop_type stop_requested{false}; - ASSERT_EQ(api_error::success, - provider.upload_file(api_path, file.get_path(), stop_requested)); - - api_meta_map to_set{ - {META_SIZE, std::to_string(*file.size())}, - {META_SOURCE, file.get_path()}, - }; - EXPECT_EQ(api_error::success, provider.set_item_meta(api_path, to_set)); - - api_meta_map meta{}; - EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, meta)); - EXPECT_STREQ(std::to_string(*file.size()).c_str(), meta[META_SIZE].c_str()); - EXPECT_STREQ(file.get_path().c_str(), meta[META_SOURCE].c_str()); - EXPECT_FALSE(utils::string::to_bool(meta[META_DIRECTORY])); - - EXPECT_EQ(api_error::success, provider.remove_file(api_path)); -} - -static void get_item_meta_fails_if_path_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - std::string out{}; - EXPECT_EQ(api_error::item_not_found, - provider.get_item_meta("/cow/moose/doge/chicken", META_SIZE, out)); - EXPECT_TRUE(out.empty()); -} - -static void get_item_meta2_fails_if_path_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - api_meta_map meta{}; - EXPECT_EQ(api_error::item_not_found, - provider.get_item_meta("/cow/moose/doge/chicken", meta)); - EXPECT_TRUE(meta.empty()); -} - -static void is_file_fails_if_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - bool exists{}; - auto res = provider.is_file("/cow/moose/doge/chicken", exists); - - EXPECT_EQ(api_error::success, res); - EXPECT_FALSE(exists); -} - -static void is_directory_fails_if_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - bool exists{}; - auto res = provider.is_directory("/cow/moose/doge/chicken", exists); - - EXPECT_EQ(api_error::success, res); - EXPECT_FALSE(exists); -} - -static void remove_file_fails_if_file_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - auto res = provider.remove_file("/cow/moose/doge/chicken"); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, remove_file_fails_if_file_not_found) { + auto res = this->provider->remove_file("/cow/moose/doge/chicken"); + if (this->provider->is_read_only()) { EXPECT_EQ(api_error::not_implemented, res); return; } EXPECT_EQ(api_error::item_not_found, res); } -static void remove_file_fails_if_item_is_directory(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.is_read_only()) { - EXPECT_EQ(api_error::not_implemented, provider.remove_file("/dir01")); - return; - } - - create_directory(provider, "/dir01"); - EXPECT_EQ(api_error::directory_exists, provider.remove_file("/dir01")); - EXPECT_EQ(api_error::success, provider.remove_directory("/dir01")); -} - -static void -remove_directory_fails_if_directory_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - auto res = provider.remove_directory("/cow/moose/doge/chicken"); - if (provider.is_read_only()) { - EXPECT_EQ(api_error::not_implemented, res); - return; - } - EXPECT_EQ(api_error::item_not_found, res); -} - -static void remove_directory_fails_if_item_is_file(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.is_read_only()) { +TYPED_TEST(providers_test, remove_file_fails_if_item_is_directory) { + if (this->provider->is_read_only()) { EXPECT_EQ(api_error::not_implemented, - provider.remove_directory("/pt01.txt")); + this->provider->remove_file("/dir01")); return; } - create_file(provider, "/pt01.txt"); - EXPECT_EQ(api_error::item_not_found, provider.remove_directory("/pt01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pt01.txt")); + create_directory(*this->provider, "/dir01"); + EXPECT_EQ(api_error::directory_exists, this->provider->remove_file("/dir01")); + EXPECT_EQ(api_error::success, this->provider->remove_directory("/dir01")); } -static void get_pinned_files(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { - auto pinned = provider.get_pinned_files(); +TYPED_TEST(providers_test, remove_directory_fails_if_item_is_file) { + if (this->provider->is_read_only()) { + EXPECT_EQ(api_error::not_implemented, + this->provider->remove_directory("/pt01.txt")); + return; + } + + create_file(*this->provider, "/pt01.txt"); + EXPECT_EQ(api_error::item_not_found, + this->provider->remove_directory("/pt01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pt01.txt")); +} + +TYPED_TEST(providers_test, remove_directory_fails_if_directory_not_found) { + auto res = this->provider->remove_directory("/cow/moose/doge/chicken"); + if (this->provider->is_read_only()) { + EXPECT_EQ(api_error::not_implemented, res); + return; + } + EXPECT_EQ(api_error::item_not_found, res); +} + +TYPED_TEST(providers_test, get_pinned_files) { + if (this->provider->is_read_only()) { + auto pinned = this->provider->get_pinned_files(); EXPECT_TRUE(pinned.empty()); return; } - create_file(provider, "/pin01.txt"); - create_file(provider, "/pin02.txt"); - create_file(provider, "/nopin01.txt"); + create_file(*this->provider, "/pin01.txt"); + create_file(*this->provider, "/pin02.txt"); + create_file(*this->provider, "/nopin01.txt"); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin01.txt", META_PINNED, "true")); + this->provider->set_item_meta("/pin01.txt", META_PINNED, "true")); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin02.txt", META_PINNED, "true")); - EXPECT_EQ(api_error::success, - provider.set_item_meta("/nopin01.txt", META_PINNED, "false")); + this->provider->set_item_meta("/pin02.txt", META_PINNED, "true")); + EXPECT_EQ(api_error::success, this->provider->set_item_meta( + "/nopin01.txt", META_PINNED, "false")); - auto pinned = provider.get_pinned_files(); + auto pinned = this->provider->get_pinned_files(); EXPECT_EQ(std::size_t(2U), pinned.size()); EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin01.txt")); EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin02.txt")); EXPECT_FALSE(pinned_includes_api_path(pinned, "/nopin01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pin01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pin02.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/nopin01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pin01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pin02.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/nopin01.txt")); } -static void remove_pin_updates_pinned_files(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.is_read_only()) { - auto pinned = provider.get_pinned_files(); +TYPED_TEST(providers_test, remove_pin_updates_pinned_files) { + if (this->provider->is_read_only()) { + auto pinned = this->provider->get_pinned_files(); EXPECT_TRUE(pinned.empty()); return; } - create_file(provider, "/pin01.txt"); - create_file(provider, "/pin02.txt"); + create_file(*this->provider, "/pin01.txt"); + create_file(*this->provider, "/pin02.txt"); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin01.txt", META_PINNED, "true")); + this->provider->set_item_meta("/pin01.txt", META_PINNED, "true")); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin02.txt", META_PINNED, "true")); + this->provider->set_item_meta("/pin02.txt", META_PINNED, "true")); - auto pinned = provider.get_pinned_files(); + auto pinned = this->provider->get_pinned_files(); EXPECT_EQ(std::size_t(2U), pinned.size()); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin02.txt", META_PINNED, "false")); - pinned = provider.get_pinned_files(); + this->provider->set_item_meta("/pin02.txt", META_PINNED, "false")); + pinned = this->provider->get_pinned_files(); EXPECT_EQ(std::size_t(1U), pinned.size()); EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin01.txt")); EXPECT_FALSE(pinned_includes_api_path(pinned, "/pin02.txt")); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin01.txt", META_PINNED, "false")); - pinned = provider.get_pinned_files(); + this->provider->set_item_meta("/pin01.txt", META_PINNED, "false")); + pinned = this->provider->get_pinned_files(); EXPECT_TRUE(pinned.empty()); - EXPECT_EQ(api_error::success, provider.remove_file("/pin01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pin02.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pin01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pin02.txt")); } -static void remove_file_updates_pinned_files(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.is_read_only()) { - auto pinned = provider.get_pinned_files(); +TYPED_TEST(providers_test, remove_file_updates_pinned_files) { + if (this->provider->is_read_only()) { + auto pinned = this->provider->get_pinned_files(); EXPECT_TRUE(pinned.empty()); return; } - create_file(provider, "/pin_keep.txt"); - create_file(provider, "/pin_delete.txt"); - create_file(provider, "/nopin.txt"); + create_file(*this->provider, "/pin_keep.txt"); + create_file(*this->provider, "/pin_delete.txt"); + create_file(*this->provider, "/nopin.txt"); + EXPECT_EQ(api_error::success, this->provider->set_item_meta( + "/pin_keep.txt", META_PINNED, "true")); + EXPECT_EQ(api_error::success, this->provider->set_item_meta( + "/pin_delete.txt", META_PINNED, "true")); EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin_keep.txt", META_PINNED, "true")); - EXPECT_EQ(api_error::success, - provider.set_item_meta("/pin_delete.txt", META_PINNED, "true")); - EXPECT_EQ(api_error::success, - provider.set_item_meta("/nopin.txt", META_PINNED, "false")); + this->provider->set_item_meta("/nopin.txt", META_PINNED, "false")); - auto pinned = provider.get_pinned_files(); + auto pinned = this->provider->get_pinned_files(); EXPECT_EQ(std::size_t(2U), pinned.size()); EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_keep.txt")); EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_delete.txt")); EXPECT_FALSE(pinned_includes_api_path(pinned, "/nopin.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pin_delete.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_delete.txt")); - pinned = provider.get_pinned_files(); + pinned = this->provider->get_pinned_files(); EXPECT_EQ(std::size_t(1U), pinned.size()); EXPECT_TRUE(pinned_includes_api_path(pinned, "/pin_keep.txt")); EXPECT_FALSE(pinned_includes_api_path(pinned, "/pin_delete.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/pin_keep.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/nopin.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/pin_keep.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/nopin.txt")); } -static void get_total_item_count(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (provider.get_provider_type() == provider_type::encrypt) { +TYPED_TEST(providers_test, get_total_item_count) { + if (this->provider->get_provider_type() == provider_type::encrypt) { // TODO revisit - /* std::uint64_t count{provider.get_total_item_count()}; + /* std::uint64_t count{this->provider->get_total_item_count()}; EXPECT_EQ(3U, count); */ return; } - std::uint64_t before{provider.get_total_item_count()}; + std::uint64_t before{this->provider->get_total_item_count()}; - create_file(provider, "/count01.txt"); - create_file(provider, "/count02.txt"); + create_file(*this->provider, "/count01.txt"); + create_file(*this->provider, "/count02.txt"); - std::uint64_t mid{provider.get_total_item_count()}; + std::uint64_t mid{this->provider->get_total_item_count()}; EXPECT_EQ(before + 2U, mid); - EXPECT_EQ(api_error::success, provider.remove_file("/count01.txt")); - EXPECT_EQ(api_error::success, provider.remove_file("/count02.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/count01.txt")); + EXPECT_EQ(api_error::success, this->provider->remove_file("/count02.txt")); - std::uint64_t after{provider.get_total_item_count()}; + std::uint64_t after{this->provider->get_total_item_count()}; EXPECT_EQ(before, after); } -static void get_used_drive_space(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.is_read_only()) { +TYPED_TEST(providers_test, get_used_drive_space) { + if (this->provider->is_read_only()) { // TODO revisit /* api_file_list list{}; std::string marker; - EXPECT_EQ(api_error::success, provider.get_file_list(list, marker)); + EXPECT_EQ(api_error::success, this->provider->get_file_list(list, marker)); std::uint64_t sum_sizes{}; for (const auto &file : list) { std::uint64_t size{}; EXPECT_EQ(api_error::success, - provider.get_file_size(file.api_path, size)); + this->provider->get_file_size(file.api_path, size)); sum_sizes += size; } - std::uint64_t used{provider.get_used_drive_space()}; + std::uint64_t used{this->provider->get_used_drive_space()}; EXPECT_EQ(sum_sizes, used); */ return; } - std::uint64_t before{provider.get_used_drive_space()}; + std::uint64_t before{this->provider->get_used_drive_space()}; auto &file1 = test::create_random_file(96U); auto &file2 = test::create_random_file(128U); @@ -1343,517 +1159,231 @@ static void get_used_drive_space(i_provider &provider) { auto api_path2 = fmt::format("/{}", utils::path::strip_to_file_name(file2.get_path())); - create_file(provider, api_path1); - create_file(provider, api_path2); + create_file(*this->provider, api_path1); + create_file(*this->provider, api_path2); stop_type stop_requested{false}; - ASSERT_EQ(api_error::success, - provider.upload_file(api_path1, file1.get_path(), stop_requested)); - ASSERT_EQ(api_error::success, - provider.upload_file(api_path2, file2.get_path(), stop_requested)); + ASSERT_EQ( + api_error::success, + this->provider->upload_file(api_path1, file1.get_path(), stop_requested)); + ASSERT_EQ( + api_error::success, + this->provider->upload_file(api_path2, file2.get_path(), stop_requested)); EXPECT_EQ(api_error::success, - provider.set_item_meta(api_path1, META_SIZE, - std::to_string(*file1.size()))); + this->provider->set_item_meta(api_path1, META_SIZE, + std::to_string(*file1.size()))); EXPECT_EQ(api_error::success, - provider.set_item_meta(api_path2, META_SIZE, - std::to_string(*file2.size()))); + this->provider->set_item_meta(api_path2, META_SIZE, + std::to_string(*file2.size()))); - std::uint64_t mid{provider.get_used_drive_space()}; + std::uint64_t mid{this->provider->get_used_drive_space()}; EXPECT_EQ(before + *file1.size() + *file2.size(), mid); - EXPECT_EQ(api_error::success, provider.remove_file(api_path1)); - EXPECT_EQ(api_error::success, provider.remove_file(api_path2)); + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path1)); + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path2)); - std::uint64_t after{provider.get_used_drive_space()}; + std::uint64_t after{this->provider->get_used_drive_space()}; EXPECT_EQ(before, after); } -static void get_total_drive_space(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - std::uint64_t total{provider.get_total_drive_space()}; - std::uint64_t used{provider.get_used_drive_space()}; +TYPED_TEST(providers_test, get_total_drive_space) { + std::uint64_t total{this->provider->get_total_drive_space()}; + std::uint64_t used{this->provider->get_used_drive_space()}; if (total != 0U) { EXPECT_GE(total, used); } } -static void remove_item_meta(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, remove_item_meta) { std::string api_path{"/rim_custom_ok.txt"}; - if (provider.get_provider_type() == provider_type::encrypt) { + if (this->provider->get_provider_type() == provider_type::encrypt) { EXPECT_EQ(api_error::success, - provider.remove_item_meta(api_path, "user.custom")); + this->provider->remove_item_meta(api_path, "user.custom")); return; } - create_file(provider, api_path); + create_file(*this->provider, api_path); EXPECT_EQ(api_error::success, - provider.set_item_meta(api_path, "user.custom", "abc123")); + this->provider->set_item_meta(api_path, "user.custom", "abc123")); api_meta_map before{}; - EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, before)); + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, before)); EXPECT_TRUE(before.contains("user.custom")); EXPECT_EQ(api_error::success, - provider.remove_item_meta(api_path, "user.custom")); + this->provider->remove_item_meta(api_path, "user.custom")); api_meta_map after{}; - EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, after)); + EXPECT_EQ(api_error::success, this->provider->get_item_meta(api_path, after)); EXPECT_FALSE(after.contains("user.custom")); - EXPECT_EQ(api_error::success, provider.remove_file(api_path)); + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path)); } -static void remove_item_meta_path_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - if (provider.get_provider_type() == provider_type::encrypt) { - EXPECT_EQ( - api_error::success, - provider.remove_item_meta("/cow_moose_doge_chicken", "user.custom")); +TYPED_TEST(providers_test, remove_item_meta_path_not_found) { + if (this->provider->get_provider_type() == provider_type::encrypt) { + EXPECT_EQ(api_error::success, + this->provider->remove_item_meta("/cow_moose_doge_chicken", + "user.custom")); return; } - auto res = - provider.remove_item_meta("/cow_moose_doge_chicken", "user.custom"); + auto res = this->provider->remove_item_meta("/cow_moose_doge_chicken", + "user.custom"); EXPECT_EQ(api_error::item_not_found, res); } -static void remove_item_meta_restricted_names_fail(const app_config &cfg, - i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - +TYPED_TEST(providers_test, remove_item_meta_restricted_names_fail) { std::string api_path; - if (provider.get_provider_type() == provider_type::encrypt) { - auto source_path = - utils::path::combine(cfg.get_encrypt_config().path, {"test.txt"}); + if (this->provider->get_provider_type() == provider_type::encrypt) { + auto source_path = utils::path::combine( + this->config->get_encrypt_config().path, {"test.txt"}); EXPECT_EQ(api_error::success, - provider.get_api_path_from_source(source_path, api_path)); + this->provider->get_api_path_from_source(source_path, api_path)); } else { api_path = "/rim_restricted.txt"; - create_file(provider, api_path); + create_file(*this->provider, api_path); } for (const auto &key : META_USED_NAMES) { - auto res = provider.remove_item_meta(api_path, std::string{key}); + auto res = this->provider->remove_item_meta(api_path, std::string{key}); EXPECT_EQ(api_error::permission_denied, res); api_meta_map meta{}; - EXPECT_EQ(api_error::success, provider.get_item_meta(api_path, meta)); + EXPECT_EQ(api_error::success, + this->provider->get_item_meta(api_path, meta)); EXPECT_TRUE(meta.contains(std::string{key})); } - if (provider.get_provider_type() != provider_type::encrypt) { - EXPECT_EQ(api_error::success, provider.remove_file(api_path)); + if (this->provider->get_provider_type() != provider_type::encrypt) { + EXPECT_EQ(api_error::success, this->provider->remove_file(api_path)); } } -static void rename_file(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (not provider.is_rename_supported()) { - auto res = provider.rename_file("/rn_src.txt", "/rn_dst.txt"); +TYPED_TEST(providers_test, rename_file) { + if (not this->provider->is_rename_supported()) { + auto res = this->provider->rename_file("/rn_src.txt", "/rn_dst.txt"); EXPECT_EQ(api_error::not_implemented, res); return; } std::string src{"/rn_src.txt"}; std::string dst{"/rn_dst.txt"}; - create_file(provider, src); + create_file(*this->provider, src); std::string src_meta_size{}; std::string src_meta_source{}; EXPECT_EQ(api_error::success, - provider.get_item_meta(src, META_SIZE, src_meta_size)); + this->provider->get_item_meta(src, META_SIZE, src_meta_size)); EXPECT_EQ(api_error::success, - provider.get_item_meta(src, META_SOURCE, src_meta_source)); + this->provider->get_item_meta(src, META_SOURCE, src_meta_source)); - EXPECT_EQ(api_error::success, provider.rename_file(src, dst)); + EXPECT_EQ(api_error::success, this->provider->rename_file(src, dst)); bool exists{}; - EXPECT_EQ(api_error::success, provider.is_file(src, exists)); + EXPECT_EQ(api_error::success, this->provider->is_file(src, exists)); EXPECT_FALSE(exists); - EXPECT_EQ(api_error::success, provider.is_file(dst, exists)); + EXPECT_EQ(api_error::success, this->provider->is_file(dst, exists)); EXPECT_TRUE(exists); std::string dst_meta_size{}; std::string dst_meta_source{}; EXPECT_EQ(api_error::success, - provider.get_item_meta(dst, META_SIZE, dst_meta_size)); + this->provider->get_item_meta(dst, META_SIZE, dst_meta_size)); EXPECT_EQ(api_error::success, - provider.get_item_meta(dst, META_SOURCE, dst_meta_source)); + this->provider->get_item_meta(dst, META_SOURCE, dst_meta_source)); EXPECT_STREQ(src_meta_size.c_str(), dst_meta_size.c_str()); EXPECT_STREQ(src_meta_source.c_str(), dst_meta_source.c_str()); - EXPECT_EQ(api_error::success, provider.remove_file(dst)); + EXPECT_EQ(api_error::success, this->provider->remove_file(dst)); } -static void rename_file_fails_if_source_not_found(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (not provider.is_rename_supported()) { - auto res = provider.rename_file("/rn_missing.txt", "/rn_any.txt"); +TYPED_TEST(providers_test, rename_file_fails_if_source_not_found) { + if (not this->provider->is_rename_supported()) { + auto res = this->provider->rename_file("/rn_missing.txt", "/rn_any.txt"); EXPECT_EQ(api_error::not_implemented, res); return; } - auto res = provider.rename_file("/rn_missing.txt", "/rn_any.txt"); + auto res = this->provider->rename_file("/rn_missing.txt", "/rn_any.txt"); EXPECT_EQ(api_error::item_not_found, res); } -static void rename_file_fails_if_destination_exists(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (not provider.is_rename_supported()) { - if (provider.get_provider_type() != provider_type::encrypt) { - create_file(provider, "/rn_src_conflict.txt"); - create_file(provider, "/rn_dst_conflict.txt"); +TYPED_TEST(providers_test, rename_file_fails_if_destination_exists) { + if (not this->provider->is_rename_supported()) { + if (this->provider->get_provider_type() != provider_type::encrypt) { + create_file(*this->provider, "/rn_src_conflict.txt"); + create_file(*this->provider, "/rn_dst_conflict.txt"); } - auto res = - provider.rename_file("/rn_src_conflict.txt", "/rn_dst_conflict.txt"); + auto res = this->provider->rename_file("/rn_src_conflict.txt", + "/rn_dst_conflict.txt"); EXPECT_EQ(api_error::not_implemented, res); - if (provider.get_provider_type() != provider_type::encrypt) { + if (this->provider->get_provider_type() != provider_type::encrypt) { EXPECT_EQ(api_error::success, - provider.remove_file("/rn_src_conflict.txt")); + this->provider->remove_file("/rn_src_conflict.txt")); EXPECT_EQ(api_error::success, - provider.remove_file("/rn_dst_conflict.txt")); + this->provider->remove_file("/rn_dst_conflict.txt")); } return; } std::string src{"/rn_src_conflict.txt"}; std::string dst{"/rn_dst_conflict.txt"}; - create_file(provider, src); - create_file(provider, dst); + create_file(*this->provider, src); + create_file(*this->provider, dst); - auto res = provider.rename_file(src, dst); + auto res = this->provider->rename_file(src, dst); EXPECT_EQ(api_error::item_exists, res); bool exists{}; - EXPECT_EQ(api_error::success, provider.is_file(src, exists)); + EXPECT_EQ(api_error::success, this->provider->is_file(src, exists)); EXPECT_TRUE(exists); - EXPECT_EQ(api_error::success, provider.is_file(dst, exists)); + EXPECT_EQ(api_error::success, this->provider->is_file(dst, exists)); EXPECT_TRUE(exists); - EXPECT_EQ(api_error::success, provider.remove_file(src)); - EXPECT_EQ(api_error::success, provider.remove_file(dst)); + EXPECT_EQ(api_error::success, this->provider->remove_file(src)); + EXPECT_EQ(api_error::success, this->provider->remove_file(dst)); } -static void -rename_file_fails_if_destination_is_directory(i_provider &provider) { - fmt::println("testing|{}|{}", - app_config::get_provider_name(provider.get_provider_type()), - __FUNCTION__); - - if (not provider.is_rename_supported()) { - if (provider.get_provider_type() != provider_type::encrypt) { - create_file(provider, "/rn_src_conflict.txt"); - create_directory(provider, "/rn_dst_conflict"); +TYPED_TEST(providers_test, rename_file_fails_if_destination_is_directory) { + if (not this->provider->is_rename_supported()) { + if (this->provider->get_provider_type() != provider_type::encrypt) { + create_file(*this->provider, "/rn_src_conflict.txt"); + create_directory(*this->provider, "/rn_dst_conflict"); } - auto res = provider.rename_file("/rn_src_conflict.txt", "/rn_dst_conflict"); + auto res = + this->provider->rename_file("/rn_src_conflict.txt", "/rn_dst_conflict"); EXPECT_EQ(api_error::not_implemented, res); - if (provider.get_provider_type() != provider_type::encrypt) { + if (this->provider->get_provider_type() != provider_type::encrypt) { EXPECT_EQ(api_error::success, - provider.remove_file("/rn_src_conflict.txt")); + this->provider->remove_file("/rn_src_conflict.txt")); EXPECT_EQ(api_error::success, - provider.remove_directory("/rn_dst_conflict")); + this->provider->remove_directory("/rn_dst_conflict")); } return; } std::string src{"/rn_src_conflict.txt"}; std::string dst{"/rn_dst_conflict"}; - create_file(provider, src); - create_directory(provider, dst); + create_file(*this->provider, src); + create_directory(*this->provider, dst); - auto res = provider.rename_file(src, dst); + auto res = this->provider->rename_file(src, dst); EXPECT_EQ(api_error::directory_exists, res); bool exists{}; - EXPECT_EQ(api_error::success, provider.is_file(src, exists)); + EXPECT_EQ(api_error::success, this->provider->is_file(src, exists)); EXPECT_TRUE(exists); - EXPECT_EQ(api_error::success, provider.is_directory(dst, exists)); + EXPECT_EQ(api_error::success, this->provider->is_directory(dst, exists)); EXPECT_TRUE(exists); - EXPECT_EQ(api_error::success, provider.remove_file(src)); - EXPECT_EQ(api_error::success, provider.remove_directory(dst)); -} - -static void run_tests(const app_config &cfg, i_provider &provider) { - // MOVED - get_file_list(cfg, provider); - - // MOVED - get_and_set_item_meta_with_upload_file(cfg, provider); - // MOVED - get_and_set_item_meta2_with_upload_file(cfg, provider); - get_item_meta_fails_if_path_not_found(provider); - get_item_meta2_fails_if_path_not_found(provider); - - is_file_fails_if_not_found(provider); - is_directory_fails_if_not_found(provider); - - // MOVED - can_create_and_remove_directory(provider); - can_create_and_remove_file(provider); - - create_directory_fails_if_already_exists(provider); - create_directory_fails_if_file_already_exists(provider); - - create_directory_clone_source_meta(provider); - create_directory_clone_source_meta_fails_if_already_exists(provider); - create_directory_clone_source_meta_fails_if_directory_not_found(provider); - create_directory_clone_source_meta_fails_if_file_already_exists(provider); - - create_file_fails_if_already_exists(provider); - create_file_fails_if_directory_already_exists(provider); - - get_api_path_from_source(cfg, provider); - get_api_path_from_source_fails_if_file_not_found(cfg, provider); - - get_directory_items(cfg, provider); - get_directory_items_fails_if_directory_not_found(provider); - get_directory_items_fails_if_item_is_file(cfg, provider); - - get_directory_item_count(cfg, provider); - - get_file(cfg, provider); - get_file_fails_if_file_not_found(provider); - get_file_fails_if_item_is_directory(cfg, provider); - - get_file_size(cfg, provider); - get_file_size_fails_if_path_not_found(provider); - - get_filesystem_item(cfg, provider); - get_filesystem_item_root_is_directory(provider); - get_filesystem_item_fails_if_file_is_not_found(provider); - get_filesystem_item_fails_if_directory_is_not_found(provider); - - get_filesystem_item_from_source_path(cfg, provider); - get_filesystem_item_from_source_path_fails_if_file_is_not_found(provider); - - remove_file_fails_if_file_not_found(provider); - remove_file_fails_if_item_is_directory(provider); - remove_directory_fails_if_directory_not_found(provider); - remove_directory_fails_if_item_is_file(provider); - - get_pinned_files(provider); - remove_pin_updates_pinned_files(provider); - remove_file_updates_pinned_files(provider); - - get_total_item_count(provider); - get_used_drive_space(provider); - get_total_drive_space(provider); - - remove_item_meta(provider); - remove_item_meta_path_not_found(provider); - remove_item_meta_restricted_names_fail(cfg, provider); - - rename_file(provider); - rename_file_fails_if_source_not_found(provider); - rename_file_fails_if_destination_exists(provider); - rename_file_fails_if_destination_is_directory(provider); - - // TODO need to test read when file size changes for encrypt provider - /* - read_file_bytes(provider); - */ -} - -TEST(providers_test, encrypt_provider) { - auto config_path = utils::path::combine(test::get_test_output_dir(), - {"provider", "encrypt"}); - console_consumer consumer{}; - event_system::instance().start(); - - { - app_config cfg(provider_type::encrypt, config_path); - - auto encrypt_path = - utils::path::combine(test::get_test_input_dir(), {"encrypt"}); - - EXPECT_STREQ( - encrypt_path.c_str(), - cfg.set_value_by_name("EncryptConfig.Path", encrypt_path).c_str()); - EXPECT_STREQ( - "test_token", - cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token") - .c_str()); - - encrypt_provider provider{cfg}; - file_manager mgr(cfg, provider); - - EXPECT_TRUE(provider.start( - [&provider](bool directory, api_file &file) -> api_error { - return provider_meta_handler(provider, directory, file); - }, - &mgr)); - - mgr.start(); - - EXPECT_EQ(provider_type::encrypt, provider.get_provider_type()); - EXPECT_TRUE(provider.is_read_only()); - EXPECT_TRUE(provider.is_online()); - EXPECT_FALSE(provider.is_rename_supported()); - - run_tests(cfg, provider); - - provider.stop(); - mgr.stop(); - } - - event_system::instance().stop(); -} - -TEST(providers_test, s3_provider_unencrypted) { - auto config_path = - utils::path::combine(test::get_test_output_dir(), {"provider", "s3"}); - - console_consumer consumer{}; - event_system::instance().start(); - - { - app_config cfg(provider_type::s3, config_path); - { - app_config src_cfg( - provider_type::s3, - utils::path::combine(test::get_test_config_dir(), {"s3"})); - auto s3_cfg = src_cfg.get_s3_config(); - s3_cfg.encryption_token = ""; - cfg.set_s3_config(s3_cfg); - } - - curl_comm comm{cfg.get_s3_config()}; - - s3_provider provider{cfg, comm}; - file_manager mgr(cfg, provider); - - EXPECT_TRUE(provider.start( - [&provider](bool directory, api_file &file) -> api_error { - return provider_meta_handler(provider, directory, file); - }, - &mgr)); - - mgr.start(); - - EXPECT_EQ(provider_type::s3, provider.get_provider_type()); - EXPECT_FALSE(provider.is_read_only()); - EXPECT_TRUE(provider.is_online()); - EXPECT_FALSE(provider.is_rename_supported()); - - run_tests(cfg, provider); - - provider.stop(); - mgr.stop(); - } - - event_system::instance().stop(); -} - -TEST(providers_test, s3_provider_encrypted) { - auto config_path = - utils::path::combine(test::get_test_output_dir(), {"provider", "s3"}); - - console_consumer consumer{}; - event_system::instance().start(); - - { - app_config cfg(provider_type::s3, config_path); - { - app_config src_cfg( - provider_type::s3, - utils::path::combine(test::get_test_config_dir(), {"s3"})); - auto s3_cfg = src_cfg.get_s3_config(); - s3_cfg.encryption_token = "cow_moose_doge_chicken"; - cfg.set_s3_config(s3_cfg); - } - - curl_comm comm{cfg.get_s3_config()}; - - s3_provider provider{cfg, comm}; - file_manager mgr(cfg, provider); - - EXPECT_TRUE(provider.start( - [&provider](bool directory, api_file &file) -> api_error { - return provider_meta_handler(provider, directory, file); - }, - &mgr)); - - mgr.start(); - - EXPECT_EQ(provider_type::s3, provider.get_provider_type()); - EXPECT_FALSE(provider.is_read_only()); - EXPECT_TRUE(provider.is_online()); - EXPECT_FALSE(provider.is_rename_supported()); - - run_tests(cfg, provider); - - provider.stop(); - mgr.stop(); - } - - event_system::instance().stop(); -} - -TEST(providers_test, sia_provider) { - auto config_path = - utils::path::combine(test::get_test_output_dir(), {"provider", "sia"}); - - console_consumer consumer{}; - event_system::instance().start(); - - { - app_config cfg(provider_type::sia, config_path); - { - app_config src_cfg( - provider_type::sia, - utils::path::combine(test::get_test_config_dir(), {"sia"})); - cfg.set_host_config(src_cfg.get_host_config()); - cfg.set_sia_config(src_cfg.get_sia_config()); - } - - curl_comm comm{cfg.get_host_config()}; - - sia_provider provider{cfg, comm}; - file_manager mgr(cfg, provider); - EXPECT_TRUE(provider.start( - [&provider](bool directory, api_file &file) -> api_error { - return provider_meta_handler(provider, directory, file); - }, - &mgr)); - - mgr.start(); - EXPECT_EQ(provider_type::sia, provider.get_provider_type()); - EXPECT_FALSE(provider.is_read_only()); - EXPECT_TRUE(provider.is_online()); - EXPECT_TRUE(provider.is_rename_supported()); - - run_tests(cfg, provider); - - provider.stop(); - mgr.stop(); - } - - event_system::instance().stop(); + EXPECT_EQ(api_error::success, this->provider->remove_file(src)); + EXPECT_EQ(api_error::success, this->provider->remove_directory(dst)); } } // namespace repertory