From d8f3f877604f04dc425f42090faecfcd375b4dd8 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 2 Aug 2025 20:43:31 -0500 Subject: [PATCH] fix macos unit tests --- .../include/fixtures/fuse_fixture.hpp | 24 +++++++++++-------- .../src/fuse_drive_chmod_test.cpp | 20 +++++++++++++++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp index 5442beb6..b48ab876 100644 --- a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp @@ -133,7 +133,6 @@ protected: "-s3", "-na", "s3", - mount_location, }); } @@ -179,7 +178,6 @@ protected: config->get_data_directory(), "-na", "sia", - mount_location, }); } @@ -218,11 +216,10 @@ protected: config2->get_data_directory(), "-rm", fmt::format("localhost:{}", port), - mount_location, }); } - execute_mount(drive_args2, mount_location); + execute_mount(drive_args2, mount_location2); }; switch (provider_t::type) { @@ -264,10 +261,10 @@ protected: static void TearDownTestCase() { if (provider_t::type == provider_type::remote) { - execute_unmount(mount_location); - execute_unmount(mount_location2); + execute_unmount(drive_args); + execute_unmount(drive_args2); } else { - execute_unmount(mount_location); + execute_unmount(drive_args); } meta.reset(); @@ -353,19 +350,26 @@ public: } static void execute_mount(auto args, auto location) { + args.emplace_back(location); auto mount_cmd = "./repertory " + utils::string::join(args, ' '); std::cout << "mount command: " << mount_cmd << std::endl; + ASSERT_EQ(0, system(mount_cmd.c_str())); std::this_thread::sleep_for(5s); ASSERT_TRUE(utils::file::directory{location}.exists()); } - static void execute_unmount(auto location) { + static void execute_unmount(auto args) { auto unmounted{false}; + + args.emplace_back("-unmount"); + auto unmount_cmd = "./repertory " + utils::string::join(args, ' '); + std::cout << "unmount command: " << unmount_cmd << std::endl; + for (int i = 0; not unmounted && (i < 50); i++) { - auto res = fuse_base::unmount(location); + auto res = system(unmount_cmd.c_str()); unmounted = res == 0; - ASSERT_EQ(0, res); + EXPECT_EQ(0, res); if (not unmounted) { std::this_thread::sleep_for(5s); } diff --git a/repertory/repertory_test/src/fuse_drive_chmod_test.cpp b/repertory/repertory_test/src/fuse_drive_chmod_test.cpp index bf38ec37..0659da62 100644 --- a/repertory/repertory_test/src/fuse_drive_chmod_test.cpp +++ b/repertory/repertory_test/src/fuse_drive_chmod_test.cpp @@ -43,7 +43,7 @@ TYPED_TEST(fuse_test, chmod_can_chmod_if_owner) { EXPECT_EQ(0, chmod(file_path.c_str(), S_IRUSR | S_IWUSR)); std::this_thread::sleep_for(SLEEP_SECONDS); - struct stat64 unix_st {}; + struct stat64 unix_st{}; stat64(file_path.c_str(), &unix_st); EXPECT_EQ(static_cast(S_IRUSR | S_IWUSR), ACCESSPERMS & unix_st.st_mode); @@ -65,8 +65,17 @@ TYPED_TEST(fuse_test, chmod_can_not_chmod_setgid_if_not_root) { std::string file_name{"chmod_test"}; auto file_path = this->create_file_and_test(file_name); +#if defined(__APPLE__) + EXPECT_EQ(0, chmod(file_path.c_str(), S_IRUSR | S_IWUSR | S_ISGID)); + std::this_thread::sleep_for(SLEEP_SECONDS); + + struct stat64 unix_st{}; + stat64(file_path.c_str(), &unix_st); + EXPECT_EQ(0, S_ISGID & unix_st.st_mode); +#else // !defined(__APPLE__) EXPECT_EQ(-1, chmod(file_path.c_str(), S_IRUSR | S_IWUSR | S_ISGID)); EXPECT_EQ(EPERM, errno); +#endif // defined(__APPLE__) this->unlink_file_and_test(file_path); } @@ -75,8 +84,17 @@ TYPED_TEST(fuse_test, chmod_can_not_chmod_setuid_if_not_root) { std::string file_name{"chmod_test"}; auto file_path = this->create_file_and_test(file_name); +#if defined(__APPLE__) + EXPECT_EQ(0, chmod(file_path.c_str(), S_IRUSR | S_IWUSR | S_ISUID)); + std::this_thread::sleep_for(SLEEP_SECONDS); + + struct stat64 unix_st{}; + stat64(file_path.c_str(), &unix_st); + EXPECT_EQ(0, S_ISUID & unix_st.st_mode); +#else // !defined(__APPLE__) EXPECT_EQ(-1, chmod(file_path.c_str(), S_IRUSR | S_IWUSR | S_ISUID)); EXPECT_EQ(EPERM, errno); +#endif // defined(__APPLE__) this->unlink_file_and_test(file_path); }