mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
added unit tests of uuid_mountpoint_factory
This commit is contained in:
parent
096c244445
commit
2b91f159cf
@ -8,6 +8,7 @@ pkg_check_modules(GMOCK gmock)
|
||||
|
||||
add_executable(alltests
|
||||
test/tempdir.cc
|
||||
test/file_utils.cc
|
||||
test/msleep.cc
|
||||
test/die_if.cc
|
||||
test/mock_authenticator.cc
|
||||
@ -29,6 +30,7 @@ add_executable(alltests
|
||||
test/adapter/test_authenticators.cc
|
||||
test/adapter/test_mountpoint.cc
|
||||
test/adapter/test_uuid_mountpoint.cc
|
||||
test/adapter/test_uuid_mountpoint_factory.cc
|
||||
test/adapter/test_fuse_req.cc
|
||||
test/adapter/jsonrpc/test_util.cc
|
||||
test/adapter/jsonrpc/test_is_request.cc
|
||||
|
@ -7,20 +7,36 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct wf_impl_uuid_mountpoint_factory
|
||||
{
|
||||
char * root_path;
|
||||
bool root_created;
|
||||
};
|
||||
|
||||
void *
|
||||
wf_impl_uuid_mountpoint_factory_create(
|
||||
char * root_path)
|
||||
char const * root_path)
|
||||
{
|
||||
mkdir(root_path, 0755);
|
||||
struct wf_impl_uuid_mountpoint_factory * factory = NULL;
|
||||
bool root_created = false;
|
||||
|
||||
struct stat info;
|
||||
int rc = stat(root_path, &info);
|
||||
if ((0 != rc) || (!S_ISDIR(info.st_mode)))
|
||||
{
|
||||
rc = mkdir(root_path, 0755);
|
||||
root_created = true;
|
||||
}
|
||||
|
||||
if (0 == rc)
|
||||
{
|
||||
factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory));
|
||||
factory->root_path = strdup(root_path);
|
||||
factory->root_created = root_created;
|
||||
}
|
||||
|
||||
struct wf_impl_uuid_mountpoint_factory * factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory));
|
||||
factory->root_path = strdup(root_path);
|
||||
|
||||
return factory;
|
||||
}
|
||||
@ -31,7 +47,11 @@ wf_impl_uuid_mountpoint_factory_dispose(
|
||||
{
|
||||
struct wf_impl_uuid_mountpoint_factory * factory = user_data;
|
||||
|
||||
rmdir(factory->root_path);
|
||||
if (factory->root_created)
|
||||
{
|
||||
rmdir(factory->root_path);
|
||||
}
|
||||
|
||||
free(factory->root_path);
|
||||
free(factory);
|
||||
}
|
||||
|
@ -10,14 +10,14 @@ struct wf_mountpoint;
|
||||
|
||||
extern void *
|
||||
wf_impl_uuid_mountpoint_factory_create(
|
||||
char * root_path);
|
||||
char const * root_path);
|
||||
|
||||
extern void
|
||||
wf_impl_uuid_mountpoint_factory_dispose(
|
||||
void * user_data);
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_impl_uuid_mountpoint_factory_create_mountpiont(
|
||||
wf_impl_uuid_mountpoint_factory_create_mountpoint(
|
||||
char const * filesystem,
|
||||
void * user_data);
|
||||
|
||||
|
@ -1,46 +1,16 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tempdir.hpp"
|
||||
#include "file_utils.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);
|
||||
}
|
||||
}
|
||||
using webfuse_test::is_dir;
|
||||
using webfuse_test::is_symlink;
|
||||
using webfuse_test::is_same_path;
|
||||
|
||||
TEST(uuid_mountpoint, create)
|
||||
{
|
||||
|
60
test/adapter/test_uuid_mountpoint_factory.cc
Normal file
60
test/adapter/test_uuid_mountpoint_factory.cc
Normal file
@ -0,0 +1,60 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_adapter.h"
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||
#include "tempdir.hpp"
|
||||
#include "file_utils.hpp"
|
||||
|
||||
using webfuse_test::TempDir;
|
||||
using webfuse_test::is_dir;
|
||||
|
||||
TEST(uuid_mountpoint_factory, create_existing_dir)
|
||||
{
|
||||
TempDir temp("uuid_mountpoint_factory");
|
||||
|
||||
void * factory = wf_impl_uuid_mountpoint_factory_create(temp.path());
|
||||
ASSERT_NE(nullptr, factory);
|
||||
ASSERT_TRUE(is_dir(temp.path()));
|
||||
|
||||
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory);
|
||||
std::string path = wf_mountpoint_get_path(mountpoint);
|
||||
ASSERT_NE(nullptr, factory);
|
||||
ASSERT_TRUE(is_dir(path));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
ASSERT_FALSE(is_dir(path));
|
||||
|
||||
wf_impl_uuid_mountpoint_factory_dispose(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";
|
||||
|
||||
void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str());
|
||||
ASSERT_NE(nullptr, factory);
|
||||
ASSERT_TRUE(is_dir(root_path));
|
||||
|
||||
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory);
|
||||
std::string path = wf_mountpoint_get_path(mountpoint);
|
||||
ASSERT_NE(nullptr, factory);
|
||||
ASSERT_TRUE(is_dir(path));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
ASSERT_FALSE(is_dir(path));
|
||||
|
||||
wf_impl_uuid_mountpoint_factory_dispose(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";
|
||||
|
||||
void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str());
|
||||
ASSERT_EQ(nullptr, factory);
|
||||
}
|
38
test/file_utils.cc
Normal file
38
test/file_utils.cc
Normal file
@ -0,0 +1,38 @@
|
||||
#include "file_utils.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
17
test/file_utils.hpp
Normal file
17
test/file_utils.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef WF_TEST_FILE_UTILS_HPP
|
||||
#define WF_TEST_FILE_UTILS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
bool is_dir(std::string const & path);
|
||||
|
||||
bool is_symlink(std::string const & path);
|
||||
|
||||
bool is_same_path(std::string const & path, std::string const & other);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user