1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

removed uuid mountpoint and factory

This commit is contained in:
Falk Werner
2020-03-21 09:11:18 +01:00
parent 428c192910
commit 43c989e7af
25 changed files with 65 additions and 512 deletions

View File

@@ -8,13 +8,27 @@
#include "webfuse/adapter/server.h"
#include "webfuse/adapter/server_config.h"
namespace
{
struct wf_mountpoint *
create_mountpoint(
char const * filesystem,
void * user_data)
{
(void) filesystem;
(void) user_data;
return nullptr;
}
}
TEST(server, create_dispose)
{
mkdir("test", 0700);
struct wf_server_config * config = wf_server_config_create();
wf_server_config_set_mountpoint(config, "test");
wf_server_config_set_mountpoint_factory(config, &create_mountpoint, nullptr);
struct wf_server * server = wf_server_create(config);
ASSERT_NE(nullptr, server);

View File

@@ -120,38 +120,18 @@ TEST(server_config, set_port)
wf_server_config_dispose(config);
}
TEST(server_config, set_mountpoint)
{
TempDir temp("server_config");
wf_server_config * config = wf_server_config_create();
ASSERT_NE(nullptr, config);
ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint);
ASSERT_EQ(nullptr, config->mountpoint_factory.user_data);
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
wf_server_config_set_mountpoint(config, temp.path());
ASSERT_NE(nullptr, config->mountpoint_factory.create_mountpoint);
ASSERT_NE(nullptr, config->mountpoint_factory.user_data);
ASSERT_NE(nullptr, config->mountpoint_factory.dispose);
wf_server_config_dispose(config);
}
TEST(server_config, set_mounpoint_factory)
{
wf_server_config * config = wf_server_config_create();
ASSERT_NE(nullptr, config);
ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint);
ASSERT_EQ(nullptr, config->mountpoint_factory.user_data);
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
int value = 42;
void * user_data = reinterpret_cast<void*>(&value);
wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data);
ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint);
ASSERT_EQ(user_data, config->mountpoint_factory.user_data);
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
wf_server_config_dispose(config);
}

View File

@@ -1,72 +0,0 @@
#include <gtest/gtest.h>
#include "webfuse/utils/tempdir.hpp"
#include "webfuse/utils/file_utils.hpp"
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/uuid_mountpoint.h"
#include <string>
using webfuse_test::TempDir;
using webfuse_test::is_dir;
using webfuse_test::is_symlink;
using webfuse_test::is_same_path;
TEST(uuid_mountpoint, create)
{
TempDir temp("uuid_mountpoint");
std::string filesystem_path = std::string(temp.path()) + "/dummy";
std::string default_path = std::string(temp.path()) + "/dummy/default";
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_create(temp.path(), "dummy");
std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_NE(nullptr, mountpoint);
ASSERT_TRUE(is_dir(filesystem_path));
ASSERT_TRUE(is_symlink(default_path));
ASSERT_TRUE(is_dir(default_path));
ASSERT_TRUE(is_dir(path));
ASSERT_TRUE(is_same_path(default_path, path));
wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(filesystem_path));
ASSERT_FALSE(is_symlink(default_path));
ASSERT_FALSE(is_dir(default_path));
ASSERT_FALSE(is_dir(path));
}
TEST(uuid_mountpoint, relink_default)
{
TempDir temp("uuid_mountpoint");
std::string filesystem_path = std::string(temp.path()) + "/dummy";
std::string default_path = std::string(temp.path()) + "/dummy/default";
wf_mountpoint * mountpoint_a = wf_impl_uuid_mountpoint_create(temp.path(), "dummy");
std::string path_a = wf_mountpoint_get_path(mountpoint_a);
wf_mountpoint * mountpoint_b = wf_impl_uuid_mountpoint_create(temp.path(), "dummy");
std::string path_b = wf_mountpoint_get_path(mountpoint_b);
ASSERT_TRUE(is_dir(filesystem_path));
ASSERT_TRUE(is_symlink(default_path));
ASSERT_TRUE(is_dir(default_path));
ASSERT_TRUE(is_dir(path_a));
ASSERT_TRUE(is_dir(path_b));
ASSERT_TRUE(is_same_path(default_path, path_a));
wf_mountpoint_dispose(mountpoint_a);
ASSERT_TRUE(is_dir(filesystem_path));
ASSERT_TRUE(is_symlink(default_path));
ASSERT_TRUE(is_dir(default_path));
ASSERT_FALSE(is_dir(path_a));
ASSERT_TRUE(is_dir(path_b));
ASSERT_TRUE(is_same_path(default_path, path_b));
wf_mountpoint_dispose(mountpoint_b);
ASSERT_FALSE(is_dir(filesystem_path));
ASSERT_FALSE(is_symlink(default_path));
ASSERT_FALSE(is_dir(default_path));
ASSERT_FALSE(is_dir(path_a));
ASSERT_FALSE(is_dir(path_b));
}

View File

@@ -1,61 +0,0 @@
#include <gtest/gtest.h>
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include "webfuse/utils/tempdir.hpp"
#include "webfuse/utils/file_utils.hpp"
using webfuse_test::TempDir;
using webfuse_test::is_dir;
TEST(uuid_mountpoint_factory, create_existing_dir)
{
TempDir temp("uuid_mountpoint_factory");
struct wf_impl_mountpoint_factory factory;
bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, temp.path());
ASSERT_TRUE(factory_created);
ASSERT_TRUE(is_dir(temp.path()));
wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy");
std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_TRUE(is_dir(path));
wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(path));
wf_impl_mountpoint_factory_cleanup(&factory);
// keep dir not created by factory
ASSERT_TRUE(is_dir(temp.path()));
}
TEST(uuid_mountpoint_factory, create_nonexisting_dir)
{
TempDir temp("uuid_mountpoint_factory");
std::string root_path = std::string(temp.path()) + "/root";
struct wf_impl_mountpoint_factory factory;
bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str());
ASSERT_TRUE(factory_created);
ASSERT_TRUE(is_dir(root_path));
wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy");
std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_TRUE(is_dir(path));
wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(path));
wf_impl_mountpoint_factory_cleanup(&factory);
// remove dir, created by factory
ASSERT_FALSE(is_dir(root_path));
}
TEST(uuid_mountpoint_factory, fail_to_created_nested_dir)
{
TempDir temp("uuid_mountpoint_factory");
std::string root_path = std::string(temp.path()) + "/nested/root";
struct wf_impl_mountpoint_factory factory;
bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str());
ASSERT_FALSE(factory_created);
}

View File

@@ -4,11 +4,43 @@
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <sys/stat.h>
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/server.h"
#define WF_PATH_MAX (100)
extern "C"
{
static void webfuse_test_server_cleanup_mountpoint(
void * user_data)
{
char * path = reinterpret_cast<char*>(user_data);
rmdir(path);
free(path);
}
static struct wf_mountpoint *
webfuse_test_server_create_mountpoint(
char const * filesystem,
void * user_data)
{
char const * base_dir = reinterpret_cast<char const*>(user_data);
char path[WF_PATH_MAX];
snprintf(path, WF_PATH_MAX, "%s/%s", base_dir, filesystem);
mkdir(path, 0755);
struct wf_mountpoint * mountpoint = wf_mountpoint_create(path);
wf_mountpoint_set_userdata(
mountpoint,
reinterpret_cast<void*>(strdup(path)),
&webfuse_test_server_cleanup_mountpoint);
return mountpoint;
}
}
namespace webfuse_test
{
@@ -28,7 +60,9 @@ public:
config = wf_server_config_create();
wf_server_config_set_port(config, 8080);
wf_server_config_set_mountpoint(config, base_dir);
wf_server_config_set_mountpoint_factory(config,
&webfuse_test_server_create_mountpoint,
reinterpret_cast<void*>(base_dir));
server = wf_server_create(config);

View File

@@ -68,7 +68,7 @@ TEST_F(IntegrationTest, HasMountpoint)
TEST_F(IntegrationTest, ProvidesTextFile)
{
std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt";
std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt";
ASSERT_EXIT({
struct stat buffer;
@@ -85,7 +85,7 @@ TEST_F(IntegrationTest, ProvidesTextFile)
TEST_F(IntegrationTest, ReadTextFile)
{
std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt";
std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt";
ASSERT_EXIT({
FILE * file = fopen(file_name.c_str(), "rb");
@@ -106,7 +106,7 @@ TEST_F(IntegrationTest, ReadTextFile)
TEST_F(IntegrationTest, ReadDir)
{
std::string dir_name = std::string(GetBaseDir()) + "/cprovider/default";
std::string dir_name = std::string(GetBaseDir()) + "/cprovider";
ASSERT_EXIT({