]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3831] Fix UTs
authorThomas Markwalder <tmark@isc.org>
Fri, 16 May 2025 11:58:17 +0000 (07:58 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 19 May 2025 12:12:55 +0000 (12:12 +0000)
modified:   src/bin/dhcp4/tests/config_parser_unittest.cc
modified:   src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
modified:   src/bin/dhcp4/tests/dhcp4_test_utils.h
modified:   src/bin/dhcp4/tests/get_config_unittest.cc
modified:   src/bin/dhcp6/tests/dhcp6_test_utils.h
modified:   src/bin/dhcp6/tests/get_config_unittest.cc

src/bin/dhcp4/tests/config_parser_unittest.cc
src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc
src/bin/dhcp4/tests/dhcp4_test_utils.h
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp6/tests/dhcp6_test_utils.h
src/bin/dhcp6/tests/get_config_unittest.cc

index 067c589366f75c286ed32f8a7f27bfa8183855ed..51d66ec35ecdcd533961475f9e4b2466b0a40c1a 100644 (file)
@@ -339,7 +339,7 @@ public:
         resetConfiguration();
 
         resetHooksPath();
-        resetSocketPath();
+        Dhcpv4SrvTest::resetSocketPath();
     }
 
     ~Dhcp4ParserTest() {
@@ -351,7 +351,7 @@ public:
         static_cast<void>(remove(UNLOAD_MARKER_FILE));
 
         resetHooksPath();
-        resetSocketPath();
+        Dhcpv4SrvTest::resetSocketPath();
     };
 
     /// @brief Sets the Hooks path from which hooks can be loaded.
@@ -367,22 +367,6 @@ public:
         HooksLibrariesParser::getHooksPath(true);
     }
 
-    /// @brief Sets the path in which the socket can be created.
-    /// @param explicit_path path to use as the socket path.
-    void setSocketTestPath(const std::string explicit_path = "") {
-        UnixCommandConfig::getSocketPath(true, (!explicit_path.empty() ?
-                                         explicit_path : TEST_DATA_BUILDDIR));
-
-        auto path = UnixCommandConfig::getSocketPath();
-        UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
-    }
-
-    /// @brief Resets the socket path to the default.
-    void resetSocketPath() {
-        UnixCommandConfig::getSocketPath(true);
-        UnixCommandConfig::setSocketPathPerms();
-    }
-
     // Checks if the result of DHCP server configuration has
     // expected code (0 for success, other for failures).
     // Also stores result in rcode_ and comment_.
@@ -6939,7 +6923,7 @@ TEST_F(Dhcp4ParserTest, hostsDatabases) {
 
 // This test checks comments. Please keep it last.
 TEST_F(Dhcp4ParserTest, comments) {
-    setSocketTestPath();
+    Dhcpv4SrvTest::setSocketTestPath();
 
     string config = PARSER_CONFIGS[6];
     extractConfig(config);
index f949bbd13d0eed597438bec01ed57de96f23f2d0..d0f717b9969ed812ef77a1f841e1fd9726c95f9d 100644 (file)
@@ -133,7 +133,7 @@ public:
     /// @brief Destructor
     ~CtrlChannelDhcpv4SrvTest() {
         resetLogPath();
-        resetSocketPath();
+        Dhcpv4SrvTest::resetSocketPath();
         if (test_timer_) {
             test_timer_->cancel();
             getIOService()->stopAndPoll();
@@ -169,22 +169,10 @@ public:
     /// @brief Sets the path in which the socket can be created.
     /// @param explicit_path path to use as the socket path.
     void setSocketTestPath(const std::string explicit_path = "") {
-        UnixCommandConfig::getSocketPath(true,
-                                         (!explicit_path.empty() ?
-                                          explicit_path : TEST_DATA_BUILDDIR));
-
-        auto path = UnixCommandConfig::getSocketPath();
-        UnixCommandConfig::setSocketPathPerms(file::getPermissions(path));
-        socket_path_ = path + "/kea4.sock";
-    }
-
-    /// @brief Resets the socket path to the default.
-    void resetSocketPath() {
-        UnixCommandConfig::getSocketPath(true);
-        UnixCommandConfig::setSocketPathPerms();
+        Dhcpv4SrvTest::setSocketTestPath(explicit_path);
+        socket_path_ = UnixCommandConfig::getSocketPath() + "/kea4.sock";
     }
 
-
     /// @brief Returns pointer to the server's IO service.
     ///
     /// @return Pointer to the server's IO service or null pointer if the server
index 3cdf73216fe90ec3c96ddbf8285c5b93e26ef0e9..c4867adcd10f2a08141936d354a2e0b06b485093 100644 (file)
@@ -387,10 +387,10 @@ public:
 
     /// @brief Sets the path in which the socket can be created.
     /// @param explicit_path path to use as the socket path.
-    void setSocketTestPath(const std::string explicit_path = "");
+    static void setSocketTestPath(const std::string explicit_path = "");
 
     /// @brief Resets the socket path to the default.
-    void resetSocketPath();
+    static void resetSocketPath();
 
     /// @brief Add 'Parameter Request List' option to the packet.
     ///
index 8dfec9edaad008e0d3ca6ac58d2b8c4d2edc244f..6de2ed5fb415def94860211aa5c731daebb2e2b3 100644 (file)
@@ -2091,7 +2091,7 @@ const char* EXTRACTED_CONFIGS[] = {
 "        ],\n"
 "        \"control-sockets\": [\n"
 "            {\n"
-"                \"socket-name\": \"/tmp/kea4-ctrl-socket\",\n"
+"                \"socket-name\": \"kea4-ctrl-socket\",\n"
 "                \"socket-type\": \"unix\",\n"
 "                \"user-context\": {\n"
 "                    \"comment\": \"Indirect comment\"\n"
@@ -11592,7 +11592,7 @@ const char* UNPARSED_CONFIGS[] = {
 "        ],\n"
 "        \"control-sockets\": [\n"
 "            {\n"
-"                \"socket-name\": \"/tmp/kea4-ctrl-socket\",\n"
+"                \"socket-name\": \"kea4-ctrl-socket\",\n"
 "                \"socket-type\": \"unix\",\n"
 "                \"user-context\": {\n"
 "                    \"comment\": \"Indirect comment\"\n"
@@ -14378,10 +14378,12 @@ public:
         srv_.reset(new ControlledDhcpv4Srv(0));
         // Create fresh context.
         resetConfiguration();
+        Dhcpv4SrvTest::setSocketTestPath();
     }
 
     ~Dhcp4GetConfigTest() {
         resetConfiguration();
+        Dhcpv4SrvTest::resetSocketPath();
     };
 
     /// @brief Parse and Execute configuration
index c612add7e0bbbd5f86fa5cc96d4ea99d19dbade9..e739e2af4c687fef052ba6fe9e845e493b74b204 100644 (file)
@@ -135,10 +135,10 @@ public:
 
     /// @brief Sets the path in which the socket can be created.
     /// @param explicit_path path to use as the socket path.
-    void setSocketTestPath(const std::string explicit_path = "");
+    static void setSocketTestPath(const std::string explicit_path = "");
 
     /// @brief Resets the socket path to the default.
-    void resetSocketPath();
+    static void resetSocketPath();
 
 private:
     /// @brief Holds the original data directory.
index 1824def5667163c2e0154308a8ac43a0a5da6c67..6bfd64465ad35060aba5cd13819bbe8d2b3f5011 100644 (file)
@@ -9,6 +9,7 @@
 #include <cc/command_interpreter.h>
 #include <cc/data.h>
 #include <cc/simple_parser.h>
+#include <config/unix_command_config.h>
 #include <dhcp/testutils/iface_mgr_test_config.h>
 #include <dhcp6/ctrl_dhcp6_srv.h>
 #include <dhcp6/dhcp6_srv.h>
@@ -16,6 +17,7 @@
 #include <dhcp6/tests/dhcp6_test_utils.h>
 #include <dhcp6/tests/get_config_unittest.h>
 #include <dhcpsrv/cfgmgr.h>
+#include <util/filesystem.h>
 #include <testutils/gtest_utils.h>
 #include <testutils/user_context_utils.h>
 
@@ -33,6 +35,7 @@ using namespace isc::data;
 using namespace isc::dhcp;
 using namespace isc::dhcp::test;
 using namespace isc::test;
+using namespace isc::util;
 
 namespace {
 
@@ -1985,7 +1988,7 @@ const char* EXTRACTED_CONFIGS[] = {
 "        ],\n"
 "        \"control-sockets\": [\n"
 "            {\n"
-"                \"socket-name\": \"/tmp/kea6-ctrl-socket\",\n"
+"                \"socket-name\": \"kea6-ctrl-socket\",\n"
 "                \"socket-type\": \"unix\",\n"
 "                \"user-context\": {\n"
 "                    \"comment\": \"Indirect comment\"\n"
@@ -11388,7 +11391,7 @@ const char* UNPARSED_CONFIGS[] = {
 "        ],\n"
 "        \"control-sockets\": [\n"
 "            {\n"
-"                \"socket-name\": \"/tmp/kea6-ctrl-socket\",\n"
+"                \"socket-name\": \"kea6-ctrl-socket\",\n"
 "                \"socket-type\": \"unix\",\n"
 "                \"user-context\": {\n"
 "                    \"comment\": \"Indirect comment\"\n"
@@ -14618,11 +14621,13 @@ public:
 
         // Reset configuration for each test.
         resetConfiguration();
+        BaseServerTest::setSocketTestPath();
     }
 
     ~Dhcp6GetConfigTest() {
         // Reset configuration database after each test.
         resetConfiguration();
+        BaseServerTest::resetSocketPath();
     };
 
     /// @brief Parse and Execute configuration