[Unit Test] Complete FUSE unit tests #22
This commit is contained in:
parent
2e24f9bb44
commit
3c2c783683
@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
### Issues
|
### Issues
|
||||||
|
|
||||||
|
* \#22 [Unit Test] Complete FUSE unit tests
|
||||||
|
|
||||||
### Changes from v2.0.2-rc
|
### Changes from v2.0.2-rc
|
||||||
|
|
||||||
* Updated copyright to 2018-2025
|
* Updated copyright to 2018-2025
|
||||||
|
|
||||||
## v2.0.2-rc
|
## v2.0.2-rc
|
||||||
@ -13,6 +16,7 @@
|
|||||||
|
|
||||||
* Refactored `config.json` - will need to verify configuration settings prior to mounting
|
* Refactored `config.json` - will need to verify configuration settings prior to mounting
|
||||||
|
|
||||||
|
<!-- markdownlint-disable-next-line -->
|
||||||
### Issues
|
### Issues
|
||||||
|
|
||||||
* \#12 \[Unit Test\] Complete all providers unit tests
|
* \#12 \[Unit Test\] Complete all providers unit tests
|
||||||
|
@ -732,6 +732,9 @@ auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
|
|||||||
if (not fm_->get_open_file(file_info->fh, false, open_file)) {
|
if (not fm_->get_open_file(file_info->fh, false, open_file)) {
|
||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
|
if (open_file->is_directory()) {
|
||||||
|
return api_error::directory_exists;
|
||||||
|
}
|
||||||
|
|
||||||
auto res = check_readable(open_file->get_open_data(file_info->fh),
|
auto res = check_readable(open_file->get_open_data(file_info->fh),
|
||||||
api_error::invalid_handle);
|
api_error::invalid_handle);
|
||||||
@ -1401,6 +1404,10 @@ auto fuse_drive::write_impl(std::string /*api_path*/
|
|||||||
return api_error::item_not_found;
|
return api_error::item_not_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (open_file->is_directory()) {
|
||||||
|
return api_error::directory_exists;
|
||||||
|
}
|
||||||
|
|
||||||
auto res = check_writeable(open_file->get_open_data(file_info->fh),
|
auto res = check_writeable(open_file->get_open_data(file_info->fh),
|
||||||
api_error::invalid_handle);
|
api_error::invalid_handle);
|
||||||
if (res != api_error::success) {
|
if (res != api_error::success) {
|
||||||
|
@ -45,7 +45,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::atomic<std::size_t> idx{0U};
|
std::atomic<std::size_t> provider_idx{0U};
|
||||||
|
|
||||||
constexpr const auto SLEEP_SECONDS{1.5s};
|
constexpr const auto SLEEP_SECONDS{1.5s};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
@ -126,6 +127,7 @@ protected:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config->set_database_type(database_type::sqlite);
|
||||||
meta = create_meta_db(*config);
|
meta = create_meta_db(*config);
|
||||||
execute_mount(drive_args, mount_location);
|
execute_mount(drive_args, mount_location);
|
||||||
};
|
};
|
||||||
@ -171,6 +173,7 @@ protected:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config->set_database_type(database_type::sqlite);
|
||||||
meta = create_meta_db(*config);
|
meta = create_meta_db(*config);
|
||||||
execute_mount(drive_args, mount_location);
|
execute_mount(drive_args, mount_location);
|
||||||
};
|
};
|
||||||
@ -197,6 +200,7 @@ protected:
|
|||||||
std::make_unique<app_config>(provider_type::remote, cfg_directory);
|
std::make_unique<app_config>(provider_type::remote, cfg_directory);
|
||||||
config2->set_enable_drive_events(true);
|
config2->set_enable_drive_events(true);
|
||||||
config2->set_event_level(event_level::trace);
|
config2->set_event_level(event_level::trace);
|
||||||
|
config2->set_database_type(database_type::sqlite);
|
||||||
|
|
||||||
drive_args2 = std::vector<std::string>({
|
drive_args2 = std::vector<std::string>({
|
||||||
"-dd",
|
"-dd",
|
||||||
@ -259,14 +263,14 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static auto create_file_path(std::string &file_name) {
|
static auto create_file_path(std::string &file_name) {
|
||||||
file_name += std::to_string(++idx);
|
file_name += std::to_string(++provider_idx);
|
||||||
auto file_path = utils::path::combine(mount_location, {file_name});
|
auto file_path = utils::path::combine(mount_location, {file_name});
|
||||||
return file_path;
|
return file_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto create_file_and_test(std::string &file_name,
|
static auto create_file_and_test(std::string &file_name,
|
||||||
mode_t perms) -> std::string {
|
mode_t perms) -> std::string {
|
||||||
file_name += std::to_string(++idx);
|
file_name += std::to_string(++provider_idx);
|
||||||
auto file_path = utils::path::combine(mount_location, {file_name});
|
auto file_path = utils::path::combine(mount_location, {file_name});
|
||||||
|
|
||||||
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL | O_RDWR, perms);
|
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL | O_RDWR, perms);
|
||||||
@ -297,7 +301,7 @@ public:
|
|||||||
|
|
||||||
static auto create_directory_and_test(std::string &dir_name,
|
static auto create_directory_and_test(std::string &dir_name,
|
||||||
mode_t perms) -> std::string {
|
mode_t perms) -> std::string {
|
||||||
dir_name += std::to_string(++idx);
|
dir_name += std::to_string(++provider_idx);
|
||||||
|
|
||||||
auto dir_path = utils::path::combine(mount_location, {dir_name});
|
auto dir_path = utils::path::combine(mount_location, {dir_name});
|
||||||
mkdir(dir_path.c_str(), perms);
|
mkdir(dir_path.c_str(), perms);
|
||||||
|
@ -63,8 +63,8 @@ TYPED_TEST(fuse_test, rdrw_can_read_from_offset) {
|
|||||||
|
|
||||||
data_buffer read_buffer(1U);
|
data_buffer read_buffer(1U);
|
||||||
for (std::size_t idx = 0U; idx < write_buffer.size(); ++idx) {
|
for (std::size_t idx = 0U; idx < write_buffer.size(); ++idx) {
|
||||||
auto bytes_read =
|
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(),
|
||||||
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
|
static_cast<off64_t>(idx));
|
||||||
EXPECT_EQ(1U, bytes_read);
|
EXPECT_EQ(1U, bytes_read);
|
||||||
|
|
||||||
EXPECT_EQ(write_buffer.at(idx), read_buffer.at(0U));
|
EXPECT_EQ(write_buffer.at(idx), read_buffer.at(0U));
|
||||||
@ -89,8 +89,8 @@ TYPED_TEST(fuse_test, rdrw_can_read_from_offset_after_eof) {
|
|||||||
|
|
||||||
data_buffer read_buffer(1U);
|
data_buffer read_buffer(1U);
|
||||||
for (std::size_t idx = 0U; idx < write_buffer.size() + 1U; ++idx) {
|
for (std::size_t idx = 0U; idx < write_buffer.size() + 1U; ++idx) {
|
||||||
auto bytes_read =
|
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(),
|
||||||
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
|
static_cast<off64_t>(idx));
|
||||||
if (idx == write_buffer.size()) {
|
if (idx == write_buffer.size()) {
|
||||||
EXPECT_EQ(0U, bytes_read);
|
EXPECT_EQ(0U, bytes_read);
|
||||||
} else {
|
} else {
|
||||||
@ -140,8 +140,7 @@ TYPED_TEST(fuse_test, rdrw_can_not_read_from_wo_file) {
|
|||||||
EXPECT_EQ(write_buffer.size(), bytes_written);
|
EXPECT_EQ(write_buffer.size(), bytes_written);
|
||||||
|
|
||||||
data_buffer read_buffer(1U);
|
data_buffer read_buffer(1U);
|
||||||
auto bytes_read =
|
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(), 0);
|
||||||
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
|
|
||||||
EXPECT_EQ(-1, bytes_read);
|
EXPECT_EQ(-1, bytes_read);
|
||||||
EXPECT_EQ(EBADF, errno);
|
EXPECT_EQ(EBADF, errno);
|
||||||
|
|
||||||
@ -149,6 +148,29 @@ TYPED_TEST(fuse_test, rdrw_can_not_read_from_wo_file) {
|
|||||||
|
|
||||||
this->unlink_file_and_test(file_path);
|
this->unlink_file_and_test(file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TYPED_TEST(fuse_test, rdrw_can_not_read_or_write_to_directory) {
|
||||||
|
std::string dir_name{"create_test"};
|
||||||
|
auto dir_path = this->create_directory_and_test(dir_name);
|
||||||
|
|
||||||
|
auto handle = open(dir_path.c_str(), O_DIRECTORY);
|
||||||
|
ASSERT_GT(handle, -1);
|
||||||
|
|
||||||
|
auto write_buffer = utils::generate_secure_random<data_buffer>(8096U);
|
||||||
|
auto bytes_written =
|
||||||
|
pwrite64(handle, write_buffer.data(), write_buffer.size(), 0U);
|
||||||
|
EXPECT_EQ(-1, bytes_written);
|
||||||
|
EXPECT_EQ(EBADF, errno);
|
||||||
|
|
||||||
|
data_buffer read_buffer(1U);
|
||||||
|
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(), 0);
|
||||||
|
EXPECT_EQ(-1, bytes_read);
|
||||||
|
EXPECT_EQ(EISDIR, errno);
|
||||||
|
|
||||||
|
close(handle);
|
||||||
|
|
||||||
|
this->rmdir_and_test(dir_path);
|
||||||
|
}
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
#endif // !defined(_WIN32)
|
#endif // !defined(_WIN32)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user