fuse unit tests and fixes
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-11-11 12:58:02 -06:00
parent 074a026d64
commit bd836b9ecb

View File

@ -60,6 +60,7 @@ TYPED_TEST(fuse_test, create_can_create_file_with_specific_perms) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
// 1. Create File - O_CREAT
TYPED_TEST(fuse_test, create_can_create_file) { TYPED_TEST(fuse_test, create_can_create_file) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
@ -71,28 +72,7 @@ TYPED_TEST(fuse_test, create_can_create_file) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
TYPED_TEST(fuse_test, create_can_create_file_ro) { // 2. Create File - O_CREAT | O_WRONLY
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle = open(file_path.c_str(), O_CREAT | O_RDONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, create_can_create_file_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle = open(file_path.c_str(), O_CREAT | O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, create_can_create_file_wo) { TYPED_TEST(fuse_test, create_can_create_file_wo) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
@ -104,17 +84,19 @@ TYPED_TEST(fuse_test, create_can_create_file_wo) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
TYPED_TEST(fuse_test, create_can_create_file_for_append) { // 3. Create File - O_CREAT | O_RDWR
TYPED_TEST(fuse_test, create_can_create_file_rw) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
auto handle = open(file_path.c_str(), O_CREAT | O_APPEND, ACCESSPERMS); auto handle = open(file_path.c_str(), O_CREAT | O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle); EXPECT_LE(1, handle);
close(handle); close(handle);
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
// 4. Create File - O_CREAT | O_TRUNC
TYPED_TEST(fuse_test, create_can_create_with_truncate_file) { TYPED_TEST(fuse_test, create_can_create_with_truncate_file) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name); auto file_path = this->create_file_path(file_name);
@ -130,7 +112,176 @@ TYPED_TEST(fuse_test, create_can_create_with_truncate_file) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
TYPED_TEST(fuse_test, create_can_create_or_open_and_truncate_existing_file) { // 5. Create File - O_CREAT | O_TRUNC | O_WRONLY
TYPED_TEST(fuse_test, create_can_create_with_truncate_file_wo) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle =
open(file_path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
auto size = utils::file::file{file_path}.size();
EXPECT_TRUE(size.has_value());
EXPECT_EQ(0U, *size);
this->unlink_file_and_test(file_path);
}
// 6. Create File - O_CREAT | O_TRUNC | O_RDWR
TYPED_TEST(fuse_test, create_can_create_with_truncate_file_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle =
open(file_path.c_str(), O_CREAT | O_TRUNC | O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
auto size = utils::file::file{file_path}.size();
EXPECT_TRUE(size.has_value());
EXPECT_EQ(0U, *size);
this->unlink_file_and_test(file_path);
}
// 7. Create File - O_CREAT | O_APPEND
TYPED_TEST(fuse_test, create_can_create_file_for_append) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle = open(file_path.c_str(), O_CREAT | O_APPEND, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 8. Create File - O_CREAT | O_APPEND | O_WRONLY
TYPED_TEST(fuse_test, create_can_create_file_for_append_wo) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle =
open(file_path.c_str(), O_CREAT | O_APPEND | O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 9. Create File - O_CREAT | O_EXCL | O_WRONLY (file does not exist)
TYPED_TEST(fuse_test, create_can_create_file_excl_wo) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle =
open(file_path.c_str(), O_CREAT | O_EXCL | O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 10. Create File - O_CREAT | O_EXCL | O_RDWR (file does not exist)
TYPED_TEST(fuse_test, create_can_create_file_excl_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL | O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 11. Create File - O_CREAT | O_EXCL (file does not exist)
TYPED_TEST(fuse_test, create_can_create_file_excl) {
std::string file_name{"create_test"};
auto file_path = this->create_file_path(file_name);
auto handle = open(file_path.c_str(), O_CREAT | O_EXCL, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 1. Open Existing File - O_RDONLY
TYPED_TEST(fuse_test, create_can_open_existing_file_ro) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_RDONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 2. Open Existing File - O_WRONLY
TYPED_TEST(fuse_test, create_can_open_existing_file_wo) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 3. Open Existing File - O_RDWR
TYPED_TEST(fuse_test, create_can_open_existing_file_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 4. Open Existing File - O_APPEND
TYPED_TEST(fuse_test, create_can_open_existing_file_for_append) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_APPEND, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 5. Open Existing File - O_APPEND | O_WRONLY
TYPED_TEST(fuse_test, create_can_open_existing_file_for_append_wo) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_APPEND | O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 6. Open Existing File - O_APPEND | O_RDWR
TYPED_TEST(fuse_test, create_can_open_existing_file_for_append_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_APPEND | O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 7. Open Existing File - O_TRUNC | O_WRONLY
TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file_wo) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
EXPECT_EQ(0, truncate(file_path.c_str(), 24U)); EXPECT_EQ(0, truncate(file_path.c_str(), 24U));
@ -139,7 +290,7 @@ TYPED_TEST(fuse_test, create_can_create_or_open_and_truncate_existing_file) {
EXPECT_TRUE(size.has_value()); EXPECT_TRUE(size.has_value());
EXPECT_EQ(24U, *size); EXPECT_EQ(24U, *size);
auto handle = open(file_path.c_str(), O_CREAT | O_TRUNC, ACCESSPERMS); auto handle = open(file_path.c_str(), O_TRUNC | O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle); EXPECT_LE(1, handle);
close(handle); close(handle);
@ -150,6 +301,28 @@ TYPED_TEST(fuse_test, create_can_create_or_open_and_truncate_existing_file) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
// 8. Open Existing File - O_TRUNC | O_RDWR
TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file_rw) {
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 | O_RDWR, 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);
}
// 9. Open Existing File - O_TRUNC
TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file) { TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
@ -170,6 +343,31 @@ TYPED_TEST(fuse_test, create_can_open_and_truncate_existing_file) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
// 10. Open Existing File - O_EXCL | O_WRONLY (file does not exist)
TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl_wr) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_EXCL | O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 11. Open Existing File - O_EXCL | O_RDWR (file does not exist)
TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_EXCL | O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
// 12. Open Existing File - O_EXCL (file does not exist):
TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) { TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) {
std::string file_name{"create_test"}; std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name); auto file_path = this->create_file_and_test(file_name);
@ -180,50 +378,6 @@ TYPED_TEST(fuse_test, create_can_open_existing_file_with_excl) {
this->unlink_file_and_test(file_path); this->unlink_file_and_test(file_path);
} }
TYPED_TEST(fuse_test, create_can_open_existing_file_ro) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_RDONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, create_can_open_existing_file_rw) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_RDWR, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, create_can_open_existing_file_wo) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_WRONLY, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
TYPED_TEST(fuse_test, create_can_open_existing_file_for_append) {
std::string file_name{"create_test"};
auto file_path = this->create_file_and_test(file_name);
auto handle = open(file_path.c_str(), O_APPEND, ACCESSPERMS);
EXPECT_LE(1, handle);
close(handle);
this->unlink_file_and_test(file_path);
}
} // namespace repertory } // namespace repertory
#endif // !defined(_WIN32) #endif // !defined(_WIN32)