mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
added unit tests for uuid_mountpoint
This commit is contained in:
parent
cfadf85f49
commit
096c244445
@ -7,6 +7,7 @@ include(GoogleTest)
|
|||||||
pkg_check_modules(GMOCK gmock)
|
pkg_check_modules(GMOCK gmock)
|
||||||
|
|
||||||
add_executable(alltests
|
add_executable(alltests
|
||||||
|
test/tempdir.cc
|
||||||
test/msleep.cc
|
test/msleep.cc
|
||||||
test/die_if.cc
|
test/die_if.cc
|
||||||
test/mock_authenticator.cc
|
test/mock_authenticator.cc
|
||||||
@ -27,6 +28,7 @@ add_executable(alltests
|
|||||||
test/adapter/test_authenticator.cc
|
test/adapter/test_authenticator.cc
|
||||||
test/adapter/test_authenticators.cc
|
test/adapter/test_authenticators.cc
|
||||||
test/adapter/test_mountpoint.cc
|
test/adapter/test_mountpoint.cc
|
||||||
|
test/adapter/test_uuid_mountpoint.cc
|
||||||
test/adapter/test_fuse_req.cc
|
test/adapter/test_fuse_req.cc
|
||||||
test/adapter/jsonrpc/test_util.cc
|
test/adapter/jsonrpc/test_util.cc
|
||||||
test/adapter/jsonrpc/test_is_request.cc
|
test/adapter/jsonrpc/test_is_request.cc
|
||||||
|
@ -82,11 +82,11 @@ wf_impl_uuid_mountpoint_data_dispose(
|
|||||||
|
|
||||||
rmdir(data->full_path);
|
rmdir(data->full_path);
|
||||||
|
|
||||||
if (wf_impl_filesystem_is_link_broken(data->default_path, data->id))
|
if (wf_impl_uuid_mountpoint_is_link_broken(data->default_path, data->id))
|
||||||
{
|
{
|
||||||
unlink(data->default_path);
|
unlink(data->default_path);
|
||||||
|
|
||||||
bool const success = wf_impl_filesystem_link_first_subdir(data->default_path, data->filesystem_path);
|
bool const success = wf_impl_uuid_mountpoint_link_first_subdir(data->default_path, data->filesystem_path);
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
rmdir(data->filesystem_path);
|
rmdir(data->filesystem_path);
|
||||||
@ -110,13 +110,13 @@ wf_impl_uuid_mountpoint_create(
|
|||||||
mkdir(data->filesystem_path, 0755);
|
mkdir(data->filesystem_path, 0755);
|
||||||
|
|
||||||
data->id = wf_impl_uuid_mountpoint_create_id();
|
data->id = wf_impl_uuid_mountpoint_create_id();
|
||||||
char * full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id);
|
data->full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id);
|
||||||
mkdir(data->full_path, 0755);
|
mkdir(data->full_path, 0755);
|
||||||
|
|
||||||
data->default_path = wf_create_string("%s/%s/default", root_path, data->filesystem_path);
|
data->default_path = wf_create_string("%s/%s/default", root_path, filesystem);
|
||||||
symlink(data->id, data->default_path);
|
symlink(data->id, data->default_path);
|
||||||
|
|
||||||
struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(full_path);
|
struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(data->full_path);
|
||||||
wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose);
|
wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose);
|
||||||
|
|
||||||
return mountpoint;
|
return mountpoint;
|
||||||
|
102
test/adapter/test_uuid_mountpoint.cc
Normal file
102
test/adapter/test_uuid_mountpoint.cc
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "tempdir.hpp"
|
||||||
|
#include "webfuse_adapter.h"
|
||||||
|
#include "webfuse/adapter/impl/uuid_mountpoint.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using webfuse_test::TempDir;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
bool is_dir(std::string const & path)
|
||||||
|
{
|
||||||
|
struct stat info;
|
||||||
|
int rc = stat(path.c_str(), &info);
|
||||||
|
|
||||||
|
return (0 == rc) && (S_ISDIR(info.st_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_symlink(std::string const & path)
|
||||||
|
{
|
||||||
|
struct stat info;
|
||||||
|
int rc = lstat(path.c_str(), &info);
|
||||||
|
|
||||||
|
return (0 == rc) && (S_ISLNK(info.st_mode));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_same_path(std::string const & path, std::string const & other)
|
||||||
|
{
|
||||||
|
struct stat info;
|
||||||
|
int rc = stat(path.c_str(), &info);
|
||||||
|
|
||||||
|
struct stat info_other;
|
||||||
|
int rc_other = stat(other.c_str(), &info_other);
|
||||||
|
|
||||||
|
return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
33
test/tempdir.cc
Normal file
33
test/tempdir.cc
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "webfuse/core/string.h"
|
||||||
|
#include "tempdir.hpp"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
TempDir::TempDir(char const * prefix)
|
||||||
|
: path_(wf_create_string("/tmp/%s_XXXXXX", prefix))
|
||||||
|
{
|
||||||
|
char * result = mkdtemp(path_);
|
||||||
|
if (NULL == result)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("unable to create temp dir");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TempDir::~TempDir()
|
||||||
|
{
|
||||||
|
rmdir(path_);
|
||||||
|
free(path_);
|
||||||
|
}
|
||||||
|
|
||||||
|
char const * TempDir::path()
|
||||||
|
{
|
||||||
|
return path_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
21
test/tempdir.hpp
Normal file
21
test/tempdir.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef WF_TEST_TEMPDIR_HPP
|
||||||
|
#define WF_TEST_TEMPDIR_HPP
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
class TempDir
|
||||||
|
{
|
||||||
|
TempDir(TempDir const &) = delete;
|
||||||
|
TempDir & operator=(TempDir const &) = delete;
|
||||||
|
public:
|
||||||
|
TempDir(char const * prefix);
|
||||||
|
~TempDir();
|
||||||
|
char const * path();
|
||||||
|
private:
|
||||||
|
char * path_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user