From: Francis Dupont Date: Wed, 17 Dec 2025 20:32:31 +0000 (+0100) Subject: [#4232] Removed more test files in host cache X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acdcb86058bb4741eba27d6c8ffad4e6522676c3;p=thirdparty%2Fkea.git [#4232] Removed more test files in host cache --- diff --git a/src/hooks/dhcp/host_cache/tests/command_unittests.cc b/src/hooks/dhcp/host_cache/tests/command_unittests.cc index dfa08029af..c84efb92d3 100644 --- a/src/hooks/dhcp/host_cache/tests/command_unittests.cc +++ b/src/hooks/dhcp/host_cache/tests/command_unittests.cc @@ -19,6 +19,7 @@ #include #include #include +#include using namespace isc; using namespace isc::asiolink; @@ -48,12 +49,16 @@ public: hcptr_.reset(new HostCache()); MultiThreadingMgr::instance().setMode(false); + remove_on_exit_.push_back("dump.json"); + remove_on_exit_.push_back("source.json"); } /// @brief Destructor virtual ~CommandTest() { - ::remove("dump.json"); - ::remove("source.json"); + // Remove test files. + for (auto const& file : remove_on_exit_) { + ::remove(file.c_str()); + } // Revert to original data directory. CfgMgr::instance().getDataDir(true, original_datadir_); @@ -310,6 +315,9 @@ public: /// @brief Stores the pre-test DHCP data directory. std::string original_datadir_; + + /// @brief List of test files to remove in the destructor. + std::list remove_on_exit_; }; /// @brief Size handler function @@ -707,6 +715,7 @@ CommandTest::testWriteCommand() { handlerType write_handler = std::bind(&writeHandler, hcptr_, ph::_1); string file_txt = "dump.json"; string full_file_txt = CfgMgr::instance().getDataDir() + "/" + file_txt; + remove_on_exit_.push_back(full_file_txt); string write_cmd = "{ \"command\": \"cache-write\", \"arguments\": \"" + file_txt + "\" }"; @@ -763,7 +772,6 @@ CommandTest::testWriteCommand() { exp_error += CfgMgr::instance().getDataDir(); exp_error += "'"; checkCommand(write_handler, badpath_cmd, 1, 1, exp_error); - ::remove(full_file_txt.c_str()); } // Verifies that cache-write really writes the expected file. @@ -773,6 +781,7 @@ CommandTest::testWriteCommandSecurityWarning() { handlerType write_handler = std::bind(&writeHandler, hcptr_, ph::_1); file::PathChecker::enableEnforcement(false); string badpath = "/tmp/kea-host-cache-test.txt"; + remove_on_exit_.push_back(badpath); string write_cmd = "{ \"command\": \"cache-write\", \"arguments\": \"" + badpath + "\" }"; @@ -789,7 +798,6 @@ CommandTest::testWriteCommandSecurityWarning() { << " is NOT SECURE: invalid path specified: '/tmp', supported path is '" << CfgMgr::instance().getDataDir() << "'"; EXPECT_EQ(1, countFile(oss.str())); - ::remove(badpath.c_str()); } // Verifies that cache-load can load a dump file.