fuse unit tests and fixes

This commit is contained in:
Scott E. Graves 2024-11-09 16:58:38 -06:00
parent 43ce2d13ec
commit fc7c6b9705

View File

@ -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 <typename provider_t> class fuse_test : public ::testing::Test {
public:
static std::string cfg_directory;
static std::unique_ptr<app_config> config;
static std::filesystem::path current_directory;
static provider_type current_provider;
static std::unique_ptr<fuse_drive> drive;
static std::vector<std::string> drive_args;
static std::vector<std::string> drive_args2;
static std::unique_ptr<meta_db> 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<app_config>(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<app_config>(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<std::string>({
"-dd",
config->get_data_directory(),
"-s3",
"-na",
"s3",
mount_location,
});
}
drive_args = std::vector<std::string>({
"-s3",
"-na",
"s3",
});
meta = std::make_unique<meta_db>(*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<app_config>(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<std::string>({
"-dd",
config->get_data_directory(),
"-na",
"sia",
mount_location,
});
}
meta = std::make_unique<meta_db>(*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<app_config>(provider_type::remote, cfg_directory);
config2->set_enable_drive_events(true);
config2->set_event_level(event_level::trace);
drive_args2 = std::vector<std::string>({
"-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<std::string>({
"-na",
"sia",
});
mount_remote();
} break;
// case 0U: {
// config =
// std::make_unique<app_config>(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<meta_db>(*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 <typename provider_t>
std::string fuse_test<provider_t>::cfg_directory{};
std::unique_ptr<app_config> fuse_test<provider_t>::config;
template <typename provider_t>
std::unique_ptr<app_config> fuse_test<provider_t>::config{};
std::filesystem::path fuse_test<provider_t>::current_directory;
template <typename provider_t>
std::filesystem::path fuse_test<provider_t>::current_directory{};
template <typename provider_t>
provider_type fuse_test<provider_t>::current_provider{provider_t::type};
template <typename provider_t>
std::unique_ptr<fuse_drive> fuse_test<provider_t>::drive{};
provider_type fuse_test<provider_t>::current_provider{provider_t::type2};
template <typename provider_t>
std::vector<std::string> fuse_test<provider_t>::drive_args;
template <typename provider_t>
std::string fuse_test<provider_t>::mount_location{};
std::vector<std::string> fuse_test<provider_t>::drive_args2;
template <typename provider_t>
std::unique_ptr<meta_db> fuse_test<provider_t>::meta{};
template <typename provider_t>
std::string fuse_test<provider_t>::test_directory;
std::string fuse_test<provider_t>::mount_location;
using fuse_provider_types = ::testing::Types<s3_provider>;
// using fuse_provider_types = ::testing::Types<s3_provider, sia_provider>;
template <typename provider_t>
std::string fuse_test<provider_t>::mount_location2;
using fuse_provider_types = ::testing::Types<local_s3, remote_s3>;
// using fuse_provider_types =
// ::testing::Types<local_s3, remote_s3, local_sia, remote_sia>;
} // namespace repertory
#endif // !defined(_WIN32)