From da60c392160b8c2c28516d7009bed8c0be87ebb0 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 30 Oct 2024 11:25:08 -0500 Subject: [PATCH] winfsp unit tests and fixes --- .../include/fixtures/fuse_fixture.hpp | 5 --- .../include/fixtures/winfsp_fixture.hpp | 4 --- repertory/repertory_test/main.cpp | 6 ++-- .../repertory_test/src/file_manager_test.cpp | 5 +-- .../repertory_test/src/providers_test.cpp | 3 -- .../repertory_test/src/remote_fuse_test.cpp | 9 +++--- .../repertory_test/src/remote_winfsp_test.cpp | 1 - support/test/src/test.cpp | 32 +++++++++++-------- 8 files changed, 27 insertions(+), 38 deletions(-) diff --git a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp index 3b8b5b00..d796b2f1 100644 --- a/repertory/repertory_test/include/fixtures/fuse_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/fuse_fixture.hpp @@ -71,8 +71,6 @@ protected: std::to_string(static_cast(provider_t::type)), }); - ASSERT_TRUE(utils::file::directory(test_directory).remove_recursively()); - mount_location = utils::path::combine(test_directory, {"mount"}); ASSERT_TRUE(utils::file::directory(mount_location).create_directory()); @@ -145,9 +143,6 @@ protected: static void TearDownTestCase() { execute_unmount(); std::filesystem::current_path(current_directory); - - [[maybe_unused]] auto ret = - utils::file::directory(test_directory).remove_recursively(); } public: diff --git a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp index 12390d95..277691f6 100644 --- a/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp +++ b/repertory/repertory_test/include/fixtures/winfsp_fixture.hpp @@ -65,8 +65,6 @@ protected: std::to_string(static_cast(provider_t::type)), }); - ASSERT_TRUE(utils::file::directory(test_directory).remove_recursively()); - mount_location = "U:"; cfg_directory = utils::path::combine(test_directory, {"cfg"}); @@ -136,8 +134,6 @@ protected: static void TearDownTestCase() { execute_unmount(); std::filesystem::current_path(current_directory); - [[maybe_unused]] auto ret = - utils::file::directory(test_directory).remove_recursively(); } public: diff --git a/repertory/repertory_test/main.cpp b/repertory/repertory_test/main.cpp index c4b04dfb..37820cbe 100644 --- a/repertory/repertory_test/main.cpp +++ b/repertory/repertory_test/main.cpp @@ -28,6 +28,8 @@ using namespace repertory; +int PROJECT_TEST_RESULT{0}; + auto main(int argc, char **argv) -> int { #if defined(PROJECT_ENABLE_BACKWARD_CPP) static backward::SignalHandling sh; @@ -39,9 +41,9 @@ auto main(int argc, char **argv) -> int { } ::testing::InitGoogleTest(&argc, argv); - auto ret = RUN_ALL_TESTS(); + PROJECT_TEST_RESULT = RUN_ALL_TESTS(); repertory::project_cleanup(); - return ret; + return PROJECT_TEST_RESULT; } diff --git a/repertory/repertory_test/src/file_manager_test.cpp b/repertory/repertory_test/src/file_manager_test.cpp index c7c01c95..076e4a1d 100644 --- a/repertory/repertory_test/src/file_manager_test.cpp +++ b/repertory/repertory_test/src/file_manager_test.cpp @@ -67,10 +67,7 @@ protected: cfg->set_enable_chunk_downloader_timeout(false); } - void TearDown() override { - // EXPECT_TRUE(utils::file::directory(file_manager_dir).remove_recursively()); - event_system::instance().stop(); - } + void TearDown() override { event_system::instance().stop(); } }; std::atomic file_manager_test::inst{0U}; diff --git a/repertory/repertory_test/src/providers_test.cpp b/repertory/repertory_test/src/providers_test.cpp index ad79ff9b..33fb737b 100644 --- a/repertory/repertory_test/src/providers_test.cpp +++ b/repertory/repertory_test/src/providers_test.cpp @@ -631,7 +631,6 @@ static void run_tests(const app_config &cfg, i_provider &provider) { TEST(providers, encrypt_provider) { const auto config_path = utils::path::combine(test::get_test_output_dir(), {"encrypt_provider"}); - ASSERT_TRUE(utils::file::directory(config_path).remove_recursively()); console_consumer consumer{}; event_system::instance().start(); @@ -674,7 +673,6 @@ TEST(providers, encrypt_provider) { TEST(providers, s3_provider) { const auto config_path = utils::path::combine(test::get_test_output_dir(), {"s3_provider"}); - ASSERT_TRUE(utils::file::directory(config_path).remove_recursively()); console_consumer consumer{}; event_system::instance().start(); @@ -713,7 +711,6 @@ TEST(providers, s3_provider) { TEST(providers, sia_provider) { const auto config_path = utils::path::combine(test::get_test_output_dir(), {"sia_provider"}); - ASSERT_TRUE(utils::file::directory(config_path).remove_recursively()); console_consumer consumer{}; event_system::instance().start(); diff --git a/repertory/repertory_test/src/remote_fuse_test.cpp b/repertory/repertory_test/src/remote_fuse_test.cpp index c66c3909..27fa6f97 100644 --- a/repertory/repertory_test/src/remote_fuse_test.cpp +++ b/repertory/repertory_test/src/remote_fuse_test.cpp @@ -206,10 +206,10 @@ static void fgetattr_test(repertory::remote_fuse::remote_client &client) { EXPECT_FALSE(directory); #if defined(_WIN32) - struct _stat64 st1 {}; + struct _stat64 st1{}; _stat64(&test_file[0], &st1); #else - struct stat st1 {}; + struct stat st1{}; stat(&test_file[0], &st1); #endif @@ -318,10 +318,10 @@ static void getattr_test(repertory::remote_fuse::remote_client &client) { EXPECT_EQ(0, client.fuse_getattr(api_path.c_str(), st, directory)); EXPECT_FALSE(directory); #if defined(_WIN32) - struct _stat64 st1 {}; + struct _stat64 st1{}; _stat64(&test_file[0], &st1); #else - struct stat st1 {}; + struct stat st1{}; stat(&test_file[0], &st1); #endif EXPECT_EQ(11u, st.st_gid); @@ -990,6 +990,5 @@ TEST(remote_fuse, all_tests) { } event_system::instance().stop(); - EXPECT_TRUE(utils::file::directory(fuse_remote_dir).remove_recursively()); } } // namespace fuse_test diff --git a/repertory/repertory_test/src/remote_winfsp_test.cpp b/repertory/repertory_test/src/remote_winfsp_test.cpp index f756daee..f4dea81e 100644 --- a/repertory/repertory_test/src/remote_winfsp_test.cpp +++ b/repertory/repertory_test/src/remote_winfsp_test.cpp @@ -538,6 +538,5 @@ TEST(remote_winfsp, all_tests) { } event_system::instance().stop(); - EXPECT_TRUE(utils::file::directory(win_remote_dir).remove_recursively()); } } // namespace winfsp_test diff --git a/support/test/src/test.cpp b/support/test/src/test.cpp index 7fb89eb3..bf751bd6 100644 --- a/support/test/src/test.cpp +++ b/support/test/src/test.cpp @@ -21,6 +21,8 @@ */ #include "test.hpp" +extern int PROJECT_TEST_RESULT; + namespace { static std::recursive_mutex file_mtx{}; @@ -28,22 +30,24 @@ static std::vector> generated_files{}; static void delete_generated_files() { - repertory::recur_mutex_lock lock{file_mtx}; - std::map parent_paths; - for (auto &&path : generated_files) { - parent_paths[repertory::utils::path::get_parent_path(path->get_path())] = - true; - } - generated_files.clear(); + if (PROJECT_TEST_RESULT == 0) { + repertory::recur_mutex_lock lock{file_mtx}; + std::map parent_paths; + for (auto &&path : generated_files) { + parent_paths[repertory::utils::path::get_parent_path(path->get_path())] = + true; + } + generated_files.clear(); - for (auto &&entry : parent_paths) { - EXPECT_TRUE( - repertory::utils::file::directory(entry.first).remove_recursively()); - } + for (auto &&entry : parent_paths) { + EXPECT_TRUE( + repertory::utils::file::directory(entry.first).remove_recursively()); + } - EXPECT_TRUE( - repertory::utils::file::directory(repertory::test::get_test_output_dir()) - .remove_recursively()); + EXPECT_TRUE(repertory::utils::file::directory( + repertory::test::get_test_output_dir()) + .remove_recursively()); + } } struct file_deleter final {