diff --git a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp index e015f75b..9cce1618 100644 --- a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp @@ -251,16 +251,13 @@ protected: } public: - static auto create_file_and_test(std::string &file_name) -> std::string { + static auto create_file_and_test(std::string &file_name, + mode_t perms) -> std::string { file_name += std::to_string(++idx); auto file_path = utils::path::combine(mount_location, {file_name}); - auto fd = - open(file_path.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP); - EXPECT_LE(1, fd); - - EXPECT_TRUE(utils::file::file(file_path).exists()); - EXPECT_FALSE(utils::file::directory(file_path).exists()); + auto handle = open(file_path.c_str(), O_CREAT | O_RDWR, perms); + EXPECT_LE(1, handle); auto opt_size = utils::file::file{file_path}.size(); EXPECT_TRUE(opt_size.has_value()); @@ -268,22 +265,45 @@ public: EXPECT_EQ(0U, opt_size.value()); } - EXPECT_EQ(0, close(fd)); + EXPECT_EQ(0, close(handle)); + + EXPECT_TRUE(utils::file::file(file_path).exists()); + EXPECT_FALSE(utils::file::directory(file_path).exists()); + + struct stat64 unix_st {}; + EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st)); + EXPECT_EQ(getgid(), unix_st.st_gid); + EXPECT_EQ(getuid(), unix_st.st_uid); return file_path; } - static auto create_directory_and_test(std::string &dir_name) -> std::string { + static auto create_file_and_test(std::string &file_name) -> std::string { + return create_file_and_test(file_name, ACCESSPERMS); + } + + static auto create_directory_and_test(std::string &dir_name, + mode_t perms) -> std::string { dir_name += std::to_string(++idx); auto dir_path = utils::path::combine(mount_location, {dir_name}); - EXPECT_TRUE(utils::file::directory(dir_path).create_directory()); + mkdir(dir_path.c_str(), perms); EXPECT_TRUE(utils::file::directory(dir_path).exists()); EXPECT_FALSE(utils::file::file(dir_path).exists()); + + struct stat64 unix_st {}; + EXPECT_EQ(0, stat64(dir_path.c_str(), &unix_st)); + EXPECT_EQ(getgid(), unix_st.st_gid); + EXPECT_EQ(getuid(), unix_st.st_uid); + return dir_path; } + static auto create_directory_and_test(std::string &dir_name) -> std::string { + return create_directory_and_test(dir_name, ACCESSPERMS); + } + static auto create_root_file(std::string &file_name) -> std::string { auto file_path = create_file_and_test(file_name); auto api_path = utils::path::create_api_path(file_name); diff --git a/repertory/repertory_test/src/fuse_drive_directory_test.cpp b/repertory/repertory_test/src/fuse_drive_create_test.cpp similarity index 55% rename from repertory/repertory_test/src/fuse_drive_directory_test.cpp rename to repertory/repertory_test/src/fuse_drive_create_test.cpp index 12a002ee..3be7367f 100644 --- a/repertory/repertory_test/src/fuse_drive_directory_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_create_test.cpp @@ -26,26 +26,38 @@ namespace repertory { TYPED_TEST_CASE(fuse_test, fuse_provider_types); -TYPED_TEST(fuse_test, directory_can_create_and_remove_directory) { - auto dir_name = std::string{"dir"}; +TYPED_TEST(fuse_test, create_can_create_and_remove_directory) { + std::string dir_name{"create_test"}; + auto dir_path = this->create_directory_and_test(dir_name); + this->rmdir_and_test(dir_path); +} - auto dir_path = utils::path::combine(this->mount_location, {dir_name}); - EXPECT_EQ(0, mkdir(dir_path.c_str(), S_IRUSR | S_IXUSR)); +TYPED_TEST(fuse_test, create_can_create_and_remove_file) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name); + this->unlink_file_and_test(file_path); +} - EXPECT_TRUE(utils::file::directory(dir_path).exists()); - EXPECT_FALSE(utils::file::file(dir_path).exists()); +TYPED_TEST(fuse_test, create_can_create_directory_with_specific_perms) { + std::string dir_name{"create_test"}; + auto dir_path = this->create_directory_and_test(dir_name, S_IRUSR); struct stat64 unix_st {}; - stat64(dir_path.c_str(), &unix_st); + EXPECT_EQ(0, stat64(dir_path.c_str(), &unix_st)); + EXPECT_EQ(S_IRUSR, unix_st.st_mode & ACCESSPERMS); - EXPECT_EQ(getgid(), unix_st.st_gid); - EXPECT_EQ(getuid(), unix_st.st_uid); + this->rmdir_and_test(dir_path); +} - EXPECT_EQ(static_cast(S_IRUSR | S_IXUSR), - ACCESSPERMS & unix_st.st_mode); +TYPED_TEST(fuse_test, create_can_create_file_with_specific_perms) { + std::string file_name{"create_test"}; + auto file_path = this->create_file_and_test(file_name, S_IRUSR); - EXPECT_TRUE(utils::file::directory(dir_path).remove()); - EXPECT_FALSE(utils::file::directory(dir_path).exists()); + struct stat64 unix_st {}; + EXPECT_EQ(0, stat64(file_path.c_str(), &unix_st)); + EXPECT_EQ(S_IRUSR, unix_st.st_mode & ACCESSPERMS); + + this->unlink_file_and_test(file_path); } } // namespace repertory