[Unit Test] Complete FUSE unit tests #22

This commit is contained in:
Scott E. Graves 2024-12-29 06:41:55 -06:00
parent 2e24f9bb44
commit 3c2c783683
4 changed files with 47 additions and 10 deletions

View File

@ -4,7 +4,10 @@
### Issues
* \#22 [Unit Test] Complete FUSE unit tests
### Changes from v2.0.2-rc
* Updated copyright to 2018-2025
## v2.0.2-rc
@ -13,6 +16,7 @@
* Refactored `config.json` - will need to verify configuration settings prior to mounting
<!-- markdownlint-disable-next-line -->
### Issues
* \#12 \[Unit Test\] Complete all providers unit tests

View File

@ -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)) {
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),
api_error::invalid_handle);
@ -1401,6 +1404,10 @@ auto fuse_drive::write_impl(std::string /*api_path*/
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),
api_error::invalid_handle);
if (res != api_error::success) {

View File

@ -45,7 +45,8 @@
#endif
namespace {
std::atomic<std::size_t> idx{0U};
std::atomic<std::size_t> provider_idx{0U};
constexpr const auto SLEEP_SECONDS{1.5s};
} // namespace
@ -126,6 +127,7 @@ protected:
});
}
config->set_database_type(database_type::sqlite);
meta = create_meta_db(*config);
execute_mount(drive_args, mount_location);
};
@ -171,6 +173,7 @@ protected:
});
}
config->set_database_type(database_type::sqlite);
meta = create_meta_db(*config);
execute_mount(drive_args, mount_location);
};
@ -197,6 +200,7 @@ protected:
std::make_unique<app_config>(provider_type::remote, cfg_directory);
config2->set_enable_drive_events(true);
config2->set_event_level(event_level::trace);
config2->set_database_type(database_type::sqlite);
drive_args2 = std::vector<std::string>({
"-dd",
@ -259,14 +263,14 @@ protected:
public:
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});
return file_path;
}
static auto create_file_and_test(std::string &file_name,
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 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,
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});
mkdir(dir_path.c_str(), perms);

View File

@ -63,8 +63,8 @@ TYPED_TEST(fuse_test, rdrw_can_read_from_offset) {
data_buffer read_buffer(1U);
for (std::size_t idx = 0U; idx < write_buffer.size(); ++idx) {
auto bytes_read =
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(),
static_cast<off64_t>(idx));
EXPECT_EQ(1U, bytes_read);
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);
for (std::size_t idx = 0U; idx < write_buffer.size() + 1U; ++idx) {
auto bytes_read =
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(),
static_cast<off64_t>(idx));
if (idx == write_buffer.size()) {
EXPECT_EQ(0U, bytes_read);
} else {
@ -140,8 +140,7 @@ TYPED_TEST(fuse_test, rdrw_can_not_read_from_wo_file) {
EXPECT_EQ(write_buffer.size(), bytes_written);
data_buffer read_buffer(1U);
auto bytes_read =
pread64(handle, read_buffer.data(), read_buffer.size(), idx);
auto bytes_read = pread64(handle, read_buffer.data(), read_buffer.size(), 0);
EXPECT_EQ(-1, bytes_read);
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);
}
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
#endif // !defined(_WIN32)