diff --git a/repertory/repertory_test/include/fixtures/drive_fixture.hpp b/repertory/repertory_test/include/fixtures/drive_fixture.hpp index c1fc99d8..59bb979a 100644 --- a/repertory/repertory_test/include/fixtures/drive_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/drive_fixture.hpp @@ -19,8 +19,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef REPERTORY_TEST_INCLUDE_FIXTURES_PLATFORM_FIXTURE_HPP -#define REPERTORY_TEST_INCLUDE_FIXTURES_PLATFORM_FIXTURE_HPP +#ifndef REPERTORY_TEST_INCLUDE_FIXTURES_DRIVE_FIXTURE_HPP +#define REPERTORY_TEST_INCLUDE_FIXTURES_DRIVE_FIXTURE_HPP #include "test_common.hpp" @@ -37,7 +37,7 @@ #include "providers/i_provider.hpp" #include "providers/s3/s3_provider.hpp" #include "providers/sia/sia_provider.hpp" -#else +#else // !defined(_WIN32) #include "comm/curl/curl_comm.hpp" #include "db/i_meta_db.hpp" #include "db/meta_db.hpp" @@ -45,10 +45,12 @@ #include "providers/encrypt/encrypt_provider.hpp" #include "providers/s3/s3_provider.hpp" #include "providers/sia/sia_provider.hpp" + #if !defined(ACCESSPERMS) -#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ -#endif -#endif +// 0777 +#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) +#endif // !defined(ACCESSPERMS) +#endif // defined(_WIN32) namespace { std::atomic provider_idx{0U}; @@ -503,20 +505,26 @@ public: #if !defined(_WIN32) template std::unique_ptr drive_fixture::config; + template std::unique_ptr drive_fixture::meta{}; #endif // !defined(_WIN32) template std::filesystem::path drive_fixture::current_directory; + template provider_type drive_fixture::current_provider{provider_t::type2}; + template std::vector drive_fixture::drive_args; + template std::vector drive_fixture::drive_args2; + template std::string drive_fixture::mount_location; + template std::string drive_fixture::mount_location2; @@ -532,4 +540,4 @@ using fuse_test = drive_fixture; #endif } // namespace repertory -#endif // REPERTORY_TEST_INCLUDE_FIXTURES_PLATFORM_FIXTURE_HPP +#endif // REPERTORY_TEST_INCLUDE_FIXTURES_DRIVE_FIXTURE_HPP diff --git a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp deleted file mode 100644 index 7b62352a..00000000 --- a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp +++ /dev/null @@ -1,513 +0,0 @@ -/* - 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_FUSE_FIXTURE_HPP -#define REPERTORY_TEST_INCLUDE_FIXTURES_FUSE_FIXTURE_HPP -#if !defined(_WIN32) - -#include "test_common.hpp" - -#include "app_config.hpp" -#include "comm/curl/curl_comm.hpp" -#include "db/i_meta_db.hpp" -#include "db/meta_db.hpp" -#include "drives/fuse/fuse_drive.hpp" -#include "platform/platform.hpp" -#include "providers/encrypt/encrypt_provider.hpp" -#include "providers/s3/s3_provider.hpp" -#include "providers/sia/sia_provider.hpp" -#include "types/repertory.hpp" -#include "utils/event_capture.hpp" -#include "utils/file_utils.hpp" -#include "utils/path.hpp" -#include "utils/utils.hpp" - -#if !defined(ACCESSPERMS) -#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) /* 0777 */ -#endif - -namespace { -std::atomic provider_idx{0U}; - -constexpr auto SLEEP_SECONDS{1.5s}; -} // namespace - -namespace repertory { -struct local_s3_no_encryption final { - static constexpr provider_type type{provider_type::s3}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct local_s3_encryption final { - static constexpr provider_type type{provider_type::s3}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct local_s3_legacy_encryption final { - static constexpr provider_type type{provider_type::s3}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{true}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct remote_s3_no_encryption final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct remote_s3_encryption final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct remote_s3_legacy_encryption final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{true}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct local_sia final { - static constexpr provider_type type{provider_type::sia}; - static constexpr provider_type type2{provider_type::sia}; - static constexpr std::uint16_t remote_port{41001U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct remote_sia final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::sia}; - static constexpr std::uint16_t remote_port{41001U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct remote_linux_to_winfsp final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::unknown}; - static constexpr std::uint16_t remote_port{41002U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -template class fuse_test : public ::testing::Test { -public: - static std::unique_ptr config; - static std::filesystem::path current_directory; - static provider_type current_provider; - static std::vector drive_args; - static std::vector drive_args2; - static std::unique_ptr meta; - static std::string mount_location; - static std::string mount_location2; - -protected: - static void SetUpTestCase() { - current_directory = std::filesystem::current_path(); - - const auto mount_s3 = [&](bool as_remote) { - if (::testing::Test::HasFatalFailure()) { - return; - } - - { - auto test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "fuse_test", - fmt::format("{}_{}", - app_config::get_provider_name(current_provider), - as_remote), - }); - - mount_location = utils::path::combine(test_directory, {"mount"}); - ASSERT_TRUE(utils::file::directory(mount_location).create_directory()); - - auto cfg_directory = utils::path::combine(test_directory, {"cfg"}); - ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory()); - - config = std::make_unique(current_provider, cfg_directory); - { - app_config src_cfg{ - provider_type::s3, - utils::path::combine(test::get_test_config_dir(), {"s3"}), - }; - - auto cfg = src_cfg.get_s3_config(); - cfg.force_legacy_encryption = provider_t::force_legacy_encryption; - cfg.encryption_token = provider_t::encryption_token; - config->set_enable_drive_events(true); - config->set_event_level(event_level::trace); - config->set_s3_config(cfg); - - auto r_cfg = config->get_remote_mount(); - r_cfg.enable = true; - r_cfg.api_port = provider_t::remote_port; - config->set_remote_mount(r_cfg); - } - - drive_args = std::vector({ - "-dd", - config->get_data_directory(), - "-s3", - "-na", - "s3", - }); - } - - config->set_database_type(database_type::sqlite); - meta = create_meta_db(*config); - execute_mount(drive_args, mount_location); - }; - - const auto mount_sia = [&](bool as_remote) { - if (::testing::Test::HasFatalFailure()) { - return; - } - - { - auto test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "fuse_test", - fmt::format("{}_{}", - app_config::get_provider_name(current_provider), - as_remote), - }); - - mount_location = utils::path::combine(test_directory, {"mount"}); - ASSERT_TRUE(utils::file::directory(mount_location).create_directory()); - - auto cfg_directory = utils::path::combine(test_directory, {"cfg"}); - ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory()); - - config = std::make_unique(current_provider, cfg_directory); - { - app_config src_cfg{ - provider_type::sia, - utils::path::combine(test::get_test_config_dir(), {"sia"}), - }; - config->set_enable_drive_events(true); - config->set_event_level(event_level::trace); - config->set_host_config(src_cfg.get_host_config()); - config->set_sia_config(src_cfg.get_sia_config()); - - auto r_cfg = config->get_remote_mount(); - r_cfg.enable = true; - r_cfg.api_port = provider_t::remote_port; - config->set_remote_mount(r_cfg); - } - - drive_args = std::vector({ - "-dd", - config->get_data_directory(), - "-na", - "sia", - }); - } - - config->set_database_type(database_type::sqlite); - meta = create_meta_db(*config); - execute_mount(drive_args, mount_location); - }; - - const auto mount_remote = [&]() { - if (::testing::Test::HasFatalFailure()) { - return; - } - - { - mount_location2 = mount_location; - auto test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "fuse_test", - fmt::format("{}_{}_{}", - app_config::get_provider_name(provider_t::type), - app_config::get_provider_name(provider_t::type2), - provider_t::remote_port), - }); - - mount_location = utils::path::combine(test_directory, {"mount"}); - ASSERT_TRUE(utils::file::directory(mount_location).create_directory()); - - auto cfg_directory = utils::path::combine(test_directory, {"cfg"}); - ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory()); - - auto config2 = - std::make_unique(provider_type::remote, cfg_directory); - config2->set_enable_drive_events(true); - config2->set_event_level(event_level::trace); - config2->set_database_type(database_type::sqlite); - - drive_args2 = std::vector({ - "-dd", - config2->get_data_directory(), - "-rm", - fmt::format("localhost:{}", provider_t::remote_port), - }); - } - - execute_mount(drive_args2, mount_location); - }; - - switch (provider_t::type) { - case provider_type::s3: { - mount_s3(false); - } break; - - case provider_type::sia: { - mount_sia(false); - } break; - - case provider_type::remote: { - switch (provider_t::type2) { - case provider_type::s3: { - mount_s3(true); - } break; - - case provider_type::sia: { - mount_sia(true); - } break; - - case provider_type::unknown: - mount_remote(); - return; - - default: - throw std::runtime_error("remote provider type is not implemented"); - return; - } - - mount_remote(); - } break; - - default: - throw std::runtime_error("provider type is not implemented"); - return; - } - } - - static void TearDownTestCase() { - if (provider_t::type == provider_type::remote) { - execute_unmount(drive_args2); - execute_unmount(drive_args); - } else { - execute_unmount(drive_args); - } - - meta.reset(); - config.reset(); - - std::filesystem::current_path(current_directory); - } - -public: - static auto create_file_path(std::string &file_name) { - file_name += std::to_string(++provider_idx); - auto file_path = utils::path::combine(mount_location, {file_name}); - return file_path; - } - - static auto create_file_and_test(std::string &file_name, mode_t perms) - -> std::string { - file_name += std::to_string(++provider_idx); - auto file_path = utils::path::combine(mount_location, {file_name}); - - auto handle = open(file_path.c_str(), O_CREAT | O_EXCL | O_RDWR, perms); - EXPECT_LE(1, handle); - - auto opt_size = utils::file::file{file_path}.size(); - EXPECT_TRUE(opt_size.has_value()); - if (opt_size.has_value()) { - EXPECT_EQ(0U, opt_size.value()); - } - - EXPECT_EQ(0, close(handle)); - - EXPECT_TRUE(utils::file::file(file_path).exists()); - EXPECT_FALSE(utils::file::directory(file_path).exists()); - - struct stat64 u_stat{}; - EXPECT_EQ(0, stat64(file_path.c_str(), &u_stat)); - EXPECT_EQ(getgid(), u_stat.st_gid); - EXPECT_EQ(getuid(), u_stat.st_uid); - - return file_path; - } - - static auto create_file_and_test(std::string &file_name) -> std::string { - return create_file_and_test(file_name, ACCESSPERMS); - } - - static auto create_directory_and_test(std::string &dir_name, mode_t perms) - -> std::string { - dir_name += std::to_string(++provider_idx); - - auto dir_path = utils::path::combine(mount_location, {dir_name}); - mkdir(dir_path.c_str(), perms); - - EXPECT_TRUE(utils::file::directory(dir_path).exists()); - EXPECT_EQ(0U, utils::file::directory(dir_path).count(false)); - EXPECT_EQ(0U, utils::file::directory(dir_path).count(true)); - EXPECT_FALSE(utils::file::file(dir_path).exists()); - - struct stat64 u_stat{}; - EXPECT_EQ(0, stat64(dir_path.c_str(), &u_stat)); - EXPECT_EQ(getgid(), u_stat.st_gid); - EXPECT_EQ(getuid(), u_stat.st_uid); - - return dir_path; - } - - static auto create_directory_and_test(std::string &dir_name) -> std::string { - return create_directory_and_test(dir_name, ACCESSPERMS); - } - - static auto create_root_file(std::string &file_name) -> std::string { - auto file_path = create_file_and_test(file_name); - auto api_path = utils::path::create_api_path(file_name); - - [[maybe_unused]] auto res = - meta->set_item_meta(api_path, { - {META_UID, "0"}, - {META_GID, "0"}, - }); - std::this_thread::sleep_for(SLEEP_SECONDS); - - return file_path; - } - - static void execute_mount(auto args, auto location) { - EXPECT_TRUE(utils::file::change_to_process_directory()); - - args.emplace_back(location); -#if defined(__APPLE__) - auto mount_cmd = "./repertory.app/Contents/MacOS/repertory " + - utils::string::join(args, ' '); -#else // !defined(__APPLE__) - auto mount_cmd = "./repertory " + utils::string::join(args, ' '); -#endif // defined(__APPLE__) - - std::cout << "mount command: " << mount_cmd << std::endl; - - ASSERT_EQ(0, system(mount_cmd.c_str())); - std::this_thread::sleep_for(5s); - ASSERT_TRUE(utils::file::directory{location}.exists()); - } - - static void execute_unmount(auto args) { - EXPECT_TRUE(utils::file::change_to_process_directory()); - - args.emplace_back("-unmount"); -#if defined(__APPLE__) - auto unmount_cmd = "./repertory.app/Contents/MacOS/repertory " + - utils::string::join(args, ' '); -#else // !defined(__APPLE__) - auto unmount_cmd = "./repertory " + utils::string::join(args, ' '); -#endif // defined(__APPLE__) - - std::cout << "unmount command: " << unmount_cmd << std::endl; - - auto res = system(unmount_cmd.c_str()); - EXPECT_EQ(0, res); - } - - static void rmdir_and_test(std::string_view dir_path) { - EXPECT_TRUE(utils::file::directory(dir_path).remove()); - EXPECT_FALSE(utils::file::directory(dir_path).exists()); - - EXPECT_FALSE(utils::file::file(dir_path).exists()); - } - - static void unlink_file_and_test(std::string_view file_path) { - EXPECT_TRUE(utils::file::file(file_path).remove()); - EXPECT_FALSE(utils::file::file(file_path).exists()); - - EXPECT_FALSE(utils::file::directory(file_path).exists()); - } - - static void unlink_root_file(const std::string &file_path) { - auto api_path = utils::path::create_api_path( - utils::path::strip_to_file_name(file_path)); - - [[maybe_unused]] auto res = - meta->set_item_meta(api_path, { - {META_UID, std::to_string(getuid())}, - {META_GID, std::to_string(getgid())}, - }); - std::this_thread::sleep_for(SLEEP_SECONDS); - - unlink_file_and_test(file_path); - } -}; - -template -std::unique_ptr fuse_test::config; - -template -std::filesystem::path fuse_test::current_directory; - -template -provider_type fuse_test::current_provider{provider_t::type2}; - -template -std::vector fuse_test::drive_args; - -template -std::vector fuse_test::drive_args2; - -template -std::unique_ptr fuse_test::meta{}; - -template -std::string fuse_test::mount_location; - -template -std::string fuse_test::mount_location2; - -using fuse_provider_types = - ::testing::Types; -// using fuse_provider_types = -// ::testing::Types; -} // namespace repertory - -#endif // !defined(_WIN32) -#endif // REPERTORY_TEST_INCLUDE_FIXTURES_FUSE_FIXTURE_HPP diff --git a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp deleted file mode 100644 index 141c86c9..00000000 --- a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp +++ /dev/null @@ -1,361 +0,0 @@ -/* - 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_WINFSP_FIXTURE_HPP -#define REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP -#if defined(_WIN32) - -#include "test_common.hpp" - -#include "app_config.hpp" -#include "drives/winfsp/remotewinfsp/remote_winfsp_drive.hpp" -#include "drives/winfsp/winfsp_drive.hpp" -#include "platform/platform.hpp" -#include "providers/i_provider.hpp" -#include "providers/s3/s3_provider.hpp" -#include "providers/sia/sia_provider.hpp" -#include "types/repertory.hpp" -#include "utils/file_utils.hpp" -#include "utils/path.hpp" - -namespace { -std::atomic idx{0U}; -constexpr auto SLEEP_SECONDS{1.5s}; -} // namespace - -namespace repertory { -struct local_s3_no_encryption final { - static constexpr provider_type type{provider_type::s3}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct local_s3_encryption final { - static constexpr provider_type type{provider_type::s3}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct local_s3_legacy_encryption final { - static constexpr provider_type type{provider_type::s3}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{true}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct remote_s3_no_encryption final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct remote_s3_encryption final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct remote_s3_legacy_encryption final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::s3}; - static constexpr std::uint16_t remote_port{41000U}; - static constexpr bool force_legacy_encryption{true}; - static constexpr std::string_view encryption_token{"encryption_token"}; -}; - -struct local_sia final { - static constexpr provider_type type{provider_type::sia}; - static constexpr provider_type type2{provider_type::sia}; - static constexpr std::uint16_t remote_port{41001U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct remote_sia final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::sia}; - static constexpr std::uint16_t remote_port{41001U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -struct remote_winfsp_to_linux final { - static constexpr provider_type type{provider_type::remote}; - static constexpr provider_type type2{provider_type::unknown}; - static constexpr std::uint16_t remote_port{41002U}; - static constexpr bool force_legacy_encryption{false}; - static constexpr std::string_view encryption_token{""}; -}; - -template class winfsp_test : public ::testing::Test { -public: - static std::filesystem::path current_directory; - static provider_type current_provider; - static std::vector drive_args; - static std::vector drive_args2; - static std::string mount_location; - static std::string mount_location2; - -protected: - static void SetUpTestCase() { - current_directory = std::filesystem::current_path(); - - mount_location = utils::string::to_lower(std::string{"U:"}); - - const auto mount_s3 = [&](bool as_remote) { - { - auto test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "winfsp_test", - fmt::format("{}_{}", - app_config::get_provider_name(current_provider), - as_remote), - }); - - auto cfg_directory = utils::path::combine(test_directory, {"cfg"}); - ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory()); - - auto config = - std::make_unique(provider_type::s3, cfg_directory); - { - app_config src_cfg{ - provider_type::s3, - utils::path::combine(test::get_test_config_dir(), {"s3"}), - }; - - auto cfg = src_cfg.get_s3_config(); - cfg.force_legacy_encryption = provider_t::force_legacy_encryption; - cfg.encryption_token = provider_t::encryption_token; - config->set_enable_drive_events(true); - config->set_event_level(event_level::trace); - config->set_s3_config(cfg); - - auto r_cfg = config->get_remote_mount(); - r_cfg.enable = true; - r_cfg.api_port = provider_t::remote_port; - config->set_remote_mount(r_cfg); - } - - drive_args = std::vector({ - "-dd", - config->get_data_directory(), - "-s3", - "-na", - "s3", - mount_location, - }); - } - execute_mount(drive_args, mount_location); - }; - - const auto mount_sia = [&](bool as_remote) { - { - auto test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "winfsp_test", - fmt::format("{}_{}", - app_config::get_provider_name(current_provider), - as_remote), - }); - - auto cfg_directory = utils::path::combine(test_directory, {"cfg"}); - ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory()); - - auto config = - std::make_unique(provider_type::sia, cfg_directory); - { - app_config src_cfg{ - provider_type::sia, - utils::path::combine(test::get_test_config_dir(), {"sia"}), - }; - config->set_enable_drive_events(true); - config->set_event_level(event_level::trace); - config->set_host_config(src_cfg.get_host_config()); - config->set_sia_config(src_cfg.get_sia_config()); - - auto r_cfg = config->get_remote_mount(); - r_cfg.enable = true; - r_cfg.api_port = provider_t::remote_port; - config->set_remote_mount(r_cfg); - } - - drive_args = std::vector({ - "-dd", - config->get_data_directory(), - "-na", - "sia", - mount_location, - }); - } - - execute_mount(drive_args, mount_location); - }; - - const auto mount_remote = [&]() { - { - auto test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "winfsp_test", - fmt::format("{}_{}_{}", - app_config::get_provider_name(provider_t::type), - app_config::get_provider_name(provider_t::type2), - provider_t::remote_port), - }); - - mount_location2 = mount_location; - mount_location = utils::string::to_lower(std::string{"V:"}); - - auto cfg_directory = utils::path::combine(test_directory, {"cfg2"}); - ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory()); - - auto config = - std::make_unique(provider_type::remote, cfg_directory); - config->set_enable_drive_events(true); - config->set_event_level(event_level::trace); - - drive_args2 = std::vector({ - "-dd", - config->get_data_directory(), - "-rm", - fmt::format("localhost:{}", provider_t::remote_port), - mount_location, - }); - } - - execute_mount(drive_args2, mount_location); - }; - - switch (provider_t::type) { - case provider_type::s3: { - mount_s3(false); - } break; - - case provider_type::sia: { - mount_sia(false); - } break; - - case provider_type::remote: { - switch (provider_t::type2) { - case provider_type::s3: { - mount_s3(true); - } break; - - case provider_type::sia: { - mount_sia(true); - } break; - - case provider_type::unknown: - mount_remote(); - return; - - default: - throw std::runtime_error("remote provider type is not implemented"); - return; - } - - mount_remote(); - } break; - - default: - throw std::runtime_error("provider type is not implemented"); - return; - } - } - - static void TearDownTestCase() { - if (provider_t::type == provider_type::remote) { - execute_unmount(drive_args2, mount_location); - if (provider_t::type2 != provider_type::unknown) { - execute_unmount(drive_args, mount_location2); - } - } else { - execute_unmount(drive_args, mount_location); - } - std::filesystem::current_path(current_directory); - } - - static void execute_mount(auto args, auto location) { - auto mount_cmd = - "start .\\repertory.exe -f " + utils::string::join(args, ' '); - std::cout << "mount command: " << mount_cmd << std::endl; - ASSERT_EQ(0, system(mount_cmd.c_str())); - std::this_thread::sleep_for(5s); - ASSERT_TRUE(utils::file::directory{location}.exists()); - } - - static void execute_unmount(auto args, auto location) { - std::this_thread::sleep_for(10s); - auto unmounted{false}; - - auto unmount_cmd = - ".\\repertory.exe " + utils::string::join(args, ' ') + " -unmount"; - for (int i = 0; not unmounted && (i < 6); i++) { - std::cout << "unmount command: " << unmount_cmd << std::endl; - system(unmount_cmd.c_str()); - unmounted = not utils::file::directory{location}.exists(); - if (not unmounted) { - std::this_thread::sleep_for(5s); - } - } - - ASSERT_TRUE(unmounted); - } -}; - -template -std::filesystem::path winfsp_test::current_directory; - -template -provider_type winfsp_test::current_provider{provider_t::type2}; - -template -std::vector winfsp_test::drive_args; - -template -std::vector winfsp_test::drive_args2; - -template -std::string winfsp_test::mount_location; - -template -std::string winfsp_test::mount_location2; - -using winfsp_provider_types = - ::testing::Types; -} // namespace repertory - -#endif // defined(_WIN32) -#endif // REPERTORY_TEST_INCLUDE_FIXTURES_WINFSP_FIXTURE_HPP diff --git a/repertory/repertory_test/src/fuse_drive_access_test.cpp b/repertory/repertory_test/src/fuse_drive_access_test.cpp index b4cde5e3..65761203 100644 --- a/repertory/repertory_test/src/fuse_drive_access_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_access_test.cpp @@ -21,7 +21,7 @@ */ #if !defined(_WIN32) -#include "fixtures/fuse_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace { const auto access_permutations = { @@ -71,7 +71,7 @@ void perform_access_test(auto &&permutation, auto &&item_path) { } // namespace namespace repertory { -TYPED_TEST_SUITE(fuse_test, fuse_provider_types); +TYPED_TEST_SUITE(fuse_test, platform_provider_types); TYPED_TEST(fuse_test, access_can_check_if_item_does_not_exist) { EXPECT_EQ( diff --git a/repertory/repertory_test/src/fuse_drive_chmod_test.cpp b/repertory/repertory_test/src/fuse_drive_chmod_test.cpp index f06569b2..aa143a62 100644 --- a/repertory/repertory_test/src/fuse_drive_chmod_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_chmod_test.cpp @@ -21,10 +21,10 @@ */ #if !defined(_WIN32) -#include "fixtures/fuse_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(fuse_test, fuse_provider_types); +TYPED_TEST_SUITE(fuse_test, platform_provider_types); TYPED_TEST(fuse_test, chmod_can_not_chmod_set_sticky_if_not_root) { std::string file_name{"chmod_test"}; diff --git a/repertory/repertory_test/src/fuse_drive_chown_test.cpp b/repertory/repertory_test/src/fuse_drive_chown_test.cpp index abf6fad0..0c2aac85 100644 --- a/repertory/repertory_test/src/fuse_drive_chown_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_chown_test.cpp @@ -21,10 +21,10 @@ */ #if !defined(_WIN32) -#include "fixtures/fuse_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(fuse_test, fuse_provider_types); +TYPED_TEST_SUITE(fuse_test, platform_provider_types); TYPED_TEST(fuse_test, chown_can_chown_group_if_owner_and_a_member_of_the_group) { diff --git a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp index b5691615..02b349c8 100644 --- a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp @@ -21,9 +21,10 @@ */ #if !defined(_WIN32) -#include "fixtures/fuse_fixture.hpp" +#include "fixtures/drive_fixture.hpp" + namespace repertory { -TYPED_TEST_SUITE(fuse_test, fuse_provider_types); +TYPED_TEST_SUITE(fuse_test, platform_provider_types); TYPED_TEST(fuse_test, create_can_create_and_remove_directory) { std::string dir_name{"create_test"}; diff --git a/repertory/repertory_test/src/fuse_drive_rdrw_test.cpp b/repertory/repertory_test/src/fuse_drive_rdrw_test.cpp index 9405e39d..8a295845 100644 --- a/repertory/repertory_test/src/fuse_drive_rdrw_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_rdrw_test.cpp @@ -21,10 +21,10 @@ */ #if !defined(_WIN32) -#include "fixtures/fuse_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(fuse_test, fuse_provider_types); +TYPED_TEST_SUITE(fuse_test, platform_provider_types); TYPED_TEST(fuse_test, rdrw_can_read_and_write_file) { std::string file_name{"create_test"}; diff --git a/repertory/repertory_test/src/fuse_drive_rename_test.cpp b/repertory/repertory_test/src/fuse_drive_rename_test.cpp index 8d696306..0b654c7c 100644 --- a/repertory/repertory_test/src/fuse_drive_rename_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_rename_test.cpp @@ -21,10 +21,10 @@ */ #if !defined(_WIN32) -#include "fixtures/fuse_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(fuse_test, fuse_provider_types); +TYPED_TEST_SUITE(fuse_test, platform_provider_types); TYPED_TEST(fuse_test, can_rename_a_file) {} diff --git a/repertory/repertory_test/src/fuse_drive_test_legacy.cpp b/repertory/repertory_test/src/fuse_drive_test_legacy.cpp index 41ba37cd..1a7b1a33 100644 --- a/repertory/repertory_test/src/fuse_drive_test_legacy.cpp +++ b/repertory/repertory_test/src/fuse_drive_test_legacy.cpp @@ -1,43 +1,3 @@ -// static void test_rename_file(const std::string &from_file_path, -// const std::string &to_file_path, -// bool is_rename_supported) { -// std::cout << __FUNCTION__ << std::endl; -// auto fd = open(from_file_path.c_str(), O_RDWR, S_IRUSR | S_IWUSR | -// S_IRGRP); EXPECT_LE(1, fd); close(fd); -// -// std::this_thread::sleep_for(SLEEP_SECONDS); -// -// if (is_rename_supported) { -// EXPECT_EQ(0, rename(from_file_path.c_str(), to_file_path.c_str())); -// EXPECT_FALSE(utils::file::is_file(from_file_path)); -// EXPECT_TRUE(utils::file::is_file(to_file_path)); -// } else { -// EXPECT_EQ(-1, rename(from_file_path.c_str(), to_file_path.c_str())); -// EXPECT_TRUE(utils::file::is_file(from_file_path)); -// EXPECT_FALSE(utils::file::is_file(to_file_path)); -// } -// } -// -// static void test_rename_directory(const std::string &from_dir_path, -// const std::string &to_dir_path, -// bool is_rename_supported) { -// std::cout << __FUNCTION__ << std::endl; -// EXPECT_EQ(0, mkdir(from_dir_path.c_str(), -// S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP)); -// std::this_thread::sleep_for(SLEEP_SECONDS); -// -// EXPECT_TRUE(utils::file::is_directory(from_dir_path)); -// if (is_rename_supported) { -// EXPECT_EQ(0, rename(from_dir_path.c_str(), to_dir_path.c_str())); -// EXPECT_FALSE(utils::file::is_directory(from_dir_path)); -// EXPECT_TRUE(utils::file::is_directory(to_dir_path)); -// } else { -// EXPECT_EQ(-1, rename(from_dir_path.c_str(), to_dir_path.c_str())); -// EXPECT_TRUE(utils::file::is_directory(from_dir_path)); -// EXPECT_FALSE(utils::file::is_directory(to_dir_path)); -// } -// } -// // static void test_truncate(const std::string &file_path) { // std::cout << __FUNCTION__ << std::endl; // EXPECT_EQ(0, truncate(file_path.c_str(), 10u)); diff --git a/repertory/repertory_test/src/winfsp_drive_create_attr_test.cpp b/repertory/repertory_test/src/winfsp_drive_create_attr_test.cpp index 46f81075..53c98890 100644 --- a/repertory/repertory_test/src/winfsp_drive_create_attr_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_create_attr_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, cr8_attr_can_create_new_file_with_normal_attribute) { auto file_path{ diff --git a/repertory/repertory_test/src/winfsp_drive_create_nl_test.cpp b/repertory/repertory_test/src/winfsp_drive_create_nl_test.cpp index 4a780337..9ed6e779 100644 --- a/repertory/repertory_test/src/winfsp_drive_create_nl_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_create_nl_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, cr8_nl_can_create_file_of_max_component_length) { if (this->current_provider == provider_type::s3) { diff --git a/repertory/repertory_test/src/winfsp_drive_create_test.cpp b/repertory/repertory_test/src/winfsp_drive_create_test.cpp index 609cb969..0d88caef 100644 --- a/repertory/repertory_test/src/winfsp_drive_create_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_create_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, cr8_file_can_create_file) { auto file_path{ diff --git a/repertory/repertory_test/src/winfsp_drive_delete_test.cpp b/repertory/repertory_test/src/winfsp_drive_delete_test.cpp index 49fa2495..bcf6d242 100644 --- a/repertory/repertory_test/src/winfsp_drive_delete_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_delete_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, delete_directory_fails_if_directory_not_empty) { auto dir_path{ diff --git a/repertory/repertory_test/src/winfsp_drive_info_test.cpp b/repertory/repertory_test/src/winfsp_drive_info_test.cpp index df610b7e..c7f9b658 100644 --- a/repertory/repertory_test/src/winfsp_drive_info_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_info_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, info_can_get_tag_info) { auto file_path{ diff --git a/repertory/repertory_test/src/winfsp_drive_rdrw_test.cpp b/repertory/repertory_test/src/winfsp_drive_rdrw_test.cpp index 983cd65e..b0f2524b 100644 --- a/repertory/repertory_test/src/winfsp_drive_rdrw_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_rdrw_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); static void test_file(auto &&mount_location, auto &&file_path, auto &&flags) { SYSTEM_INFO sys_info{}; diff --git a/repertory/repertory_test/src/winfsp_drive_rename_test.cpp b/repertory/repertory_test/src/winfsp_drive_rename_test.cpp index 1a6356ee..c983de87 100644 --- a/repertory/repertory_test/src/winfsp_drive_rename_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_rename_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, rename_can_rename_file_if_dest_does_not_exist) { if (this->current_provider == provider_type::s3) { diff --git a/repertory/repertory_test/src/winfsp_drive_test.cpp b/repertory/repertory_test/src/winfsp_drive_test.cpp index 4b72ffd9..1061b3a7 100644 --- a/repertory/repertory_test/src/winfsp_drive_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_test.cpp @@ -46,10 +46,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, can_set_current_directory_to_mount_location) { EXPECT_TRUE(::SetCurrentDirectoryA(this->mount_location.c_str())); diff --git a/repertory/repertory_test/src/winfsp_drive_volume_test.cpp b/repertory/repertory_test/src/winfsp_drive_volume_test.cpp index e695ea87..1a99e75e 100644 --- a/repertory/repertory_test/src/winfsp_drive_volume_test.cpp +++ b/repertory/repertory_test/src/winfsp_drive_volume_test.cpp @@ -25,10 +25,10 @@ // Implemented test cases based on WinFsp tests: // https://github.com/winfsp/winfsp/blob/v2.0/tst/winfsp-tests // -#include "fixtures/winfsp_fixture.hpp" +#include "fixtures/drive_fixture.hpp" namespace repertory { -TYPED_TEST_SUITE(winfsp_test, winfsp_provider_types); +TYPED_TEST_SUITE(winfsp_test, platform_provider_types); TYPED_TEST(winfsp_test, volume_can_get_volume_info) { std::string volume_label;