fuse unit tests and fixes
This commit is contained in:
parent
43ce2d13ec
commit
fc7c6b9705
@ -49,23 +49,44 @@ constexpr const auto SLEEP_SECONDS{1.5s};
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace repertory {
|
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 {
|
template <typename provider_t> class fuse_test : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
static std::string cfg_directory;
|
|
||||||
static std::unique_ptr<app_config> config;
|
static std::unique_ptr<app_config> config;
|
||||||
static std::filesystem::path current_directory;
|
static std::filesystem::path current_directory;
|
||||||
static provider_type current_provider;
|
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_args;
|
||||||
|
static std::vector<std::string> drive_args2;
|
||||||
static std::unique_ptr<meta_db> meta;
|
static std::unique_ptr<meta_db> meta;
|
||||||
static std::string mount_location;
|
static std::string mount_location;
|
||||||
static std::string test_directory;
|
static std::string mount_location2;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void SetUpTestCase() {
|
static void SetUpTestCase() {
|
||||||
current_directory = std::filesystem::current_path();
|
current_directory = std::filesystem::current_path();
|
||||||
|
|
||||||
test_directory = utils::path::combine(
|
const auto mount_s3 = [&]() {
|
||||||
|
{
|
||||||
|
auto test_directory = utils::path::combine(
|
||||||
test::get_test_output_dir(),
|
test::get_test_output_dir(),
|
||||||
{
|
{
|
||||||
"fuse_test",
|
"fuse_test",
|
||||||
@ -73,16 +94,12 @@ protected:
|
|||||||
});
|
});
|
||||||
|
|
||||||
mount_location = utils::path::combine(test_directory, {"mount"});
|
mount_location = utils::path::combine(test_directory, {"mount"});
|
||||||
|
|
||||||
ASSERT_TRUE(utils::file::directory(mount_location).create_directory());
|
ASSERT_TRUE(utils::file::directory(mount_location).create_directory());
|
||||||
|
|
||||||
cfg_directory = utils::path::combine(test_directory, {"cfg"});
|
auto cfg_directory = utils::path::combine(test_directory, {"cfg"});
|
||||||
ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory());
|
ASSERT_TRUE(utils::file::directory(cfg_directory).create_directory());
|
||||||
|
|
||||||
config = std::make_unique<app_config>(current_provider, cfg_directory);
|
config = std::make_unique<app_config>(current_provider, cfg_directory);
|
||||||
|
|
||||||
switch (current_provider) {
|
|
||||||
case provider_type::s3: {
|
|
||||||
{
|
{
|
||||||
app_config src_cfg{
|
app_config src_cfg{
|
||||||
provider_type::s3,
|
provider_type::s3,
|
||||||
@ -91,16 +108,40 @@ protected:
|
|||||||
config->set_enable_drive_events(true);
|
config->set_enable_drive_events(true);
|
||||||
config->set_event_level(event_level::trace);
|
config->set_event_level(event_level::trace);
|
||||||
config->set_s3_config(src_cfg.get_s3_config());
|
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>({
|
drive_args = std::vector<std::string>({
|
||||||
|
"-dd",
|
||||||
|
config->get_data_directory(),
|
||||||
"-s3",
|
"-s3",
|
||||||
"-na",
|
"-na",
|
||||||
"s3",
|
"s3",
|
||||||
|
mount_location,
|
||||||
});
|
});
|
||||||
} break;
|
}
|
||||||
|
|
||||||
case provider_type::sia: {
|
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{
|
app_config src_cfg{
|
||||||
provider_type::sia,
|
provider_type::sia,
|
||||||
@ -110,40 +151,102 @@ protected:
|
|||||||
config->set_event_level(event_level::trace);
|
config->set_event_level(event_level::trace);
|
||||||
config->set_host_config(src_cfg.get_host_config());
|
config->set_host_config(src_cfg.get_host_config());
|
||||||
config->set_sia_config(src_cfg.get_sia_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>({
|
drive_args = std::vector<std::string>({
|
||||||
|
"-dd",
|
||||||
|
config->get_data_directory(),
|
||||||
"-na",
|
"-na",
|
||||||
"sia",
|
"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: {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
mount_remote();
|
||||||
} break;
|
} 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:
|
default:
|
||||||
throw std::runtime_error("provider type is not implemented");
|
throw std::runtime_error("provider type is not implemented");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
meta = std::make_unique<meta_db>(*config);
|
|
||||||
|
|
||||||
drive_args.push_back(mount_location);
|
|
||||||
execute_mount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TearDownTestCase() {
|
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);
|
std::filesystem::current_path(current_directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,6 +289,7 @@ public:
|
|||||||
auto file_path = create_file_and_test(file_name);
|
auto file_path = create_file_and_test(file_name);
|
||||||
auto api_path = utils::path::create_api_path(file_name);
|
auto api_path = utils::path::create_api_path(file_name);
|
||||||
|
|
||||||
|
[[maybe_unused]] auto res =
|
||||||
meta->set_item_meta(api_path, {
|
meta->set_item_meta(api_path, {
|
||||||
{META_UID, "0"},
|
{META_UID, "0"},
|
||||||
{META_GID, "0"},
|
{META_GID, "0"},
|
||||||
@ -194,18 +298,18 @@ public:
|
|||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void execute_mount() {
|
static void execute_mount(auto args, auto location) {
|
||||||
auto mount_cmd = "./repertory -dd \"" + config->get_data_directory() +
|
auto mount_cmd = "./repertory " + utils::string::join(args, ' ');
|
||||||
"\"" + " " + utils::string::join(drive_args, ' ');
|
std::cout << "mount command: " << mount_cmd << std::endl;
|
||||||
ASSERT_EQ(0, system(mount_cmd.c_str()));
|
ASSERT_EQ(0, system(mount_cmd.c_str()));
|
||||||
std::this_thread::sleep_for(5s);
|
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};
|
auto unmounted{false};
|
||||||
for (int i = 0; not unmounted && (i < 50); i++) {
|
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;
|
unmounted = res == 0;
|
||||||
ASSERT_EQ(0, res);
|
ASSERT_EQ(0, res);
|
||||||
if (not unmounted) {
|
if (not unmounted) {
|
||||||
@ -234,6 +338,7 @@ public:
|
|||||||
auto api_path = utils::path::create_api_path(
|
auto api_path = utils::path::create_api_path(
|
||||||
utils::path::strip_to_file_name(file_path));
|
utils::path::strip_to_file_name(file_path));
|
||||||
|
|
||||||
|
[[maybe_unused]] auto res =
|
||||||
meta->set_item_meta(api_path, {
|
meta->set_item_meta(api_path, {
|
||||||
{META_UID, std::to_string(getuid())},
|
{META_UID, std::to_string(getuid())},
|
||||||
{META_GID, std::to_string(getgid())},
|
{META_GID, std::to_string(getgid())},
|
||||||
@ -244,34 +349,32 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename provider_t>
|
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>
|
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>
|
template <typename provider_t>
|
||||||
std::filesystem::path fuse_test<provider_t>::current_directory{};
|
provider_type fuse_test<provider_t>::current_provider{provider_t::type2};
|
||||||
|
|
||||||
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{};
|
|
||||||
|
|
||||||
template <typename provider_t>
|
template <typename provider_t>
|
||||||
std::vector<std::string> fuse_test<provider_t>::drive_args;
|
std::vector<std::string> fuse_test<provider_t>::drive_args;
|
||||||
|
|
||||||
template <typename provider_t>
|
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>
|
template <typename provider_t>
|
||||||
std::unique_ptr<meta_db> fuse_test<provider_t>::meta{};
|
std::unique_ptr<meta_db> fuse_test<provider_t>::meta{};
|
||||||
|
|
||||||
template <typename provider_t>
|
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>;
|
template <typename provider_t>
|
||||||
// using fuse_provider_types = ::testing::Types<s3_provider, sia_provider>;
|
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
|
} // namespace repertory
|
||||||
|
|
||||||
#endif // !defined(_WIN32)
|
#endif // !defined(_WIN32)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user