From 77299455f975ab5cdf5c4601351485f59d836194 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sun, 10 Nov 2024 16:32:38 -0600 Subject: [PATCH] fuse unit tests and fixes --- .../include/fixtures/fuse_fixture.hpp | 6 ++++ .../src/fuse_drive_create_and_open_test.cpp | 30 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp index 5995519b..60db866f 100644 --- a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp @@ -251,6 +251,12 @@ protected: } public: + static auto create_file_path(std::string &file_name) { + file_name += std::to_string(++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); diff --git a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp index 3be7367f..3967c683 100644 --- a/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_create_and_open_test.cpp @@ -59,6 +59,36 @@ TYPED_TEST(fuse_test, create_can_create_file_with_specific_perms) { this->unlink_file_and_test(file_path); } + +TYPED_TEST(fuse_test, create_can_create_file) { + auto file_path = this->create_file_path("create_test"); + + auto handle = open(file_path.c_str(), O_CREAT, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + this->unlink_file_and_test(file_path); +} + +TYPED_TEST(fuse_test, create_can_create_and_truncate_file) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + EXPECT_EQ(0, truncate(file_path.c_str(), 24U)); + + auto size = utils::file::file{file_path}.size(); + EXPECT_TRUE(size.has_value()); + EXPECT_EQ(24U, *size); + + auto handle = open(file_path.c_str(), O_TRUNC, ACCESSPERMS); + EXPECT_LE(1, handle); + close(handle); + + size = utils::file::file{file_path}.size(); + EXPECT_TRUE(size.has_value()); + EXPECT_EQ(0U, *size); + + this->unlink_file_and_test(file_path); +} } // namespace repertory #endif // !defined(_WIN32)