parent
cfadf85f49
commit
096c244445
@ -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));
|
||||||
|
}
|
@ -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_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -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