diff --git a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp index 0ad951e7..1f3da221 100644 --- a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp @@ -49,101 +49,204 @@ constexpr const auto SLEEP_SECONDS{1.5s}; } // namespace namespace repertory { +struct local_s3 final { + static constexpr const provider_type type{provider_type::s3}; + static constexpr const provider_type type2{provider_type::s3}; +}; + +struct local_sia final { + static constexpr const provider_type type{provider_type::sia}; + static constexpr const provider_type type2{provider_type::sia}; +}; + +struct remote_s3 final { + static constexpr const provider_type type{provider_type::remote}; + static constexpr const provider_type type2{provider_type::s3}; +}; + +struct remote_sia final { + static constexpr const provider_type type{provider_type::remote}; + static constexpr const provider_type type2{provider_type::sia}; +}; + template class fuse_test : public ::testing::Test { public: - static std::string cfg_directory; static std::unique_ptr config; static std::filesystem::path current_directory; static provider_type current_provider; - static std::unique_ptr drive; static std::vector drive_args; + static std::vector drive_args2; static std::unique_ptr meta; static std::string mount_location; - static std::string test_directory; + static std::string mount_location2; protected: static void SetUpTestCase() { current_directory = std::filesystem::current_path(); - test_directory = utils::path::combine( - test::get_test_output_dir(), - { - "fuse_test", - app_config::get_provider_name(current_provider), - }); - - mount_location = utils::path::combine(test_directory, {"mount"}); - - ASSERT_TRUE(utils::file::directory(mount_location).create_directory()); - - 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); - - switch (current_provider) { - case provider_type::s3: { + const auto mount_s3 = [&]() { { - app_config src_cfg{ - provider_type::s3, - utils::path::combine(test::get_test_config_dir(), {"s3"}), - }; - config->set_enable_drive_events(true); - config->set_event_level(event_level::trace); - config->set_s3_config(src_cfg.get_s3_config()); + auto test_directory = utils::path::combine( + test::get_test_output_dir(), + { + "fuse_test", + app_config::get_provider_name(current_provider), + }); + + 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"}), + }; + config->set_enable_drive_events(true); + config->set_event_level(event_level::trace); + config->set_s3_config(src_cfg.get_s3_config()); + config->set_enable_remote_mount(true); + config->set_remote_port(30000U); + } + + drive_args = std::vector({ + "-dd", + config->get_data_directory(), + "-s3", + "-na", + "s3", + mount_location, + }); } - drive_args = std::vector({ - "-s3", - "-na", - "s3", - }); + meta = std::make_unique(*config); + execute_mount(drive_args, mount_location); + }; + + const auto mount_sia = [&]() { + { + auto test_directory = utils::path::combine( + test::get_test_output_dir(), + { + "fuse_test", + app_config::get_provider_name(current_provider), + }); + + 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()); + config->set_enable_remote_mount(true); + config->set_remote_port(30000U); + } + + drive_args = std::vector({ + "-dd", + config->get_data_directory(), + "-na", + "sia", + mount_location, + }); + } + + meta = std::make_unique(*config); + execute_mount(drive_args, mount_location); + }; + + const auto mount_remote = [&]() { + { + mount_location2 = mount_location; + + auto test_directory = utils::path::combine( + test::get_test_output_dir(), + { + "fuse_test", + app_config::get_provider_name(provider_t::type) + '_' + + app_config::get_provider_name(provider_t::type2), + }); + + 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); + + drive_args2 = std::vector({ + "-dd", + config2->get_data_directory(), + "-rm", + "localhost:30000", + mount_location, + }); + } + + execute_mount(drive_args2, mount_location); + }; + + switch (provider_t::type) { + case provider_type::s3: { + mount_s3(); } break; case provider_type::sia: { - { - 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()); + mount_sia(); + } break; + + case provider_type::remote: { + switch (provider_t::type2) { + case provider_type::s3: { + mount_s3(); + } break; + + case provider_type::sia: { + mount_sia(); + } break; + + default: + throw std::runtime_error("remote provider type is not implemented"); + return; } - drive_args = std::vector({ - "-na", - "sia", - }); + mount_remote(); } break; - // case 0U: { - // config = - // std::make_unique(provider_type::encrypt, - // cfg_directory); - // { - // app_config src_cfg( - // provider_type::s3, - // utils::path::combine(test::get_test_input_dir(), {"encrypt"})); - // config->set_enable_drive_events(true); - // config->set_event_level(event_level::trace); - // config->set_s3_config(src_cfg.get_s3_config()); - // } - // } break; default: throw std::runtime_error("provider type is not implemented"); return; } - - meta = std::make_unique(*config); - - drive_args.push_back(mount_location); - execute_mount(); } static void TearDownTestCase() { - execute_unmount(); + if (provider_t::type == provider_type::remote) { + execute_unmount(mount_location); + execute_unmount(mount_location2); + } else { + execute_unmount(mount_location); + } + + meta.reset(); + config.reset(); + std::filesystem::current_path(current_directory); } @@ -186,26 +289,27 @@ public: auto file_path = create_file_and_test(file_name); auto api_path = utils::path::create_api_path(file_name); - meta->set_item_meta(api_path, { - {META_UID, "0"}, - {META_GID, "0"}, - }); + [[maybe_unused]] auto res = + meta->set_item_meta(api_path, { + {META_UID, "0"}, + {META_GID, "0"}, + }); return file_path; } - static void execute_mount() { - auto mount_cmd = "./repertory -dd \"" + config->get_data_directory() + - "\"" + " " + utils::string::join(drive_args, ' '); + static void execute_mount(auto args, auto location) { + auto mount_cmd = "./repertory " + 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{mount_location}.exists()); + ASSERT_TRUE(utils::file::directory{location}.exists()); } - static void execute_unmount() { + static void execute_unmount(auto location) { auto unmounted{false}; for (int i = 0; not unmounted && (i < 50); i++) { - auto res = fuse_base::unmount(mount_location); + auto res = fuse_base::unmount(location); unmounted = res == 0; ASSERT_EQ(0, res); if (not unmounted) { @@ -234,44 +338,43 @@ public: auto api_path = utils::path::create_api_path( utils::path::strip_to_file_name(file_path)); - meta->set_item_meta(api_path, { - {META_UID, std::to_string(getuid())}, - {META_GID, std::to_string(getgid())}, - }); + [[maybe_unused]] auto res = + meta->set_item_meta(api_path, { + {META_UID, std::to_string(getuid())}, + {META_GID, std::to_string(getgid())}, + }); unlink_file_and_test(file_path); } }; template -std::string fuse_test::cfg_directory{}; +std::unique_ptr fuse_test::config; template -std::unique_ptr fuse_test::config{}; +std::filesystem::path fuse_test::current_directory; template -std::filesystem::path fuse_test::current_directory{}; - -template -provider_type fuse_test::current_provider{provider_t::type}; - -template -std::unique_ptr fuse_test::drive{}; +provider_type fuse_test::current_provider{provider_t::type2}; template std::vector fuse_test::drive_args; template -std::string fuse_test::mount_location{}; +std::vector fuse_test::drive_args2; template std::unique_ptr fuse_test::meta{}; template -std::string fuse_test::test_directory; +std::string fuse_test::mount_location; -using fuse_provider_types = ::testing::Types; -// using fuse_provider_types = ::testing::Types; +template +std::string fuse_test::mount_location2; + +using fuse_provider_types = ::testing::Types; +// using fuse_provider_types = +// ::testing::Types; } // namespace repertory #endif // !defined(_WIN32)