diff options
author | Michal Nowikowski <godfryd@isc.org> | 2019-03-05 06:40:15 +0100 |
---|---|---|
committer | Michal Nowikowski <godfryd@isc.org> | 2019-03-07 10:57:33 +0100 |
commit | a45e2f68d7d1848adb0cf755954a3d76c9dff338 (patch) | |
tree | 9aac1afd5040a2085209ff23bf56d136f8b86c8e /src/bin/netconf | |
parent | [478-improve-error-message-database-backend-mysql] Reviewed changes and addre... (diff) | |
download | kea-a45e2f68d7d1848adb0cf755954a3d76c9dff338.tar.xz kea-a45e2f68d7d1848adb0cf755954a3d76c9dff338.zip |
Changed location of unit socket in unit tests
Previously it was stored in TEST_DATA_BUILDDIR which resides inside repo sources.
Due to the fact that when repo was located in deep patch creating socket was
failing as max socket patch is about 100 characters. Now it is located
in temp folder managed by Sandbox class. The sandbox directory is created
in test constructor and deleted in destructor. As the temp directory
is in form /tmp/kea-XXXXXX the lnegth is always lower than 1000, so running
the unit tests never fails.
Diffstat (limited to 'src/bin/netconf')
-rw-r--r-- | src/bin/netconf/tests/control_socket_unittests.cc | 18 | ||||
-rw-r--r-- | src/bin/netconf/tests/netconf_unittests.cc | 15 |
2 files changed, 16 insertions, 17 deletions
diff --git a/src/bin/netconf/tests/control_socket_unittests.cc b/src/bin/netconf/tests/control_socket_unittests.cc index dec968aba0..0d55e25be5 100644 --- a/src/bin/netconf/tests/control_socket_unittests.cc +++ b/src/bin/netconf/tests/control_socket_unittests.cc @@ -19,6 +19,7 @@ #include <http/response_json.h> #include <http/tests/response_test.h> #include <testutils/threaded_test.h> +#include <testutils/sandbox.h> #include <util/threads/thread.h> #include <util/threads/sync.h> #include <gtest/gtest.h> @@ -131,15 +132,14 @@ TEST(StdoutControlSocketTest, configSet) { //////////////////////////////// UNIX //////////////////////////////// -/// @brief Test unix socket file name. -const string TEST_SOCKET = "test-socket"; - /// @brief Test timeout in ms. const long TEST_TIMEOUT = 10000; /// @brief Test fixture class for unix control sockets. class UnixControlSocketTest : public ThreadedTest { public: + isc::test::Sandbox sandbox; + /// @brief Constructor. UnixControlSocketTest() : ThreadedTest(), io_service_() { @@ -164,17 +164,15 @@ public: /// If the KEA_SOCKET_TEST_DIR environment variable is specified, the /// socket file is created in the location pointed to by this variable. /// Otherwise, it is created in the build directory. - static string unixSocketFilePath() { - ostringstream s; + string unixSocketFilePath() { + std::string socket_path; const char* env = getenv("KEA_SOCKET_TEST_DIR"); if (env) { - s << string(env); + socket_path = std::string(env) + "/test-socket"; } else { - s << TEST_DATA_BUILDDIR; + socket_path = sandbox.join("test-socket"); } - - s << "/" << TEST_SOCKET; - return (s.str()); + return (socket_path); } /// @brief Removes unix socket descriptor. diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc index d1f24a58b5..b85a4589ee 100644 --- a/src/bin/netconf/tests/netconf_unittests.cc +++ b/src/bin/netconf/tests/netconf_unittests.cc @@ -21,6 +21,7 @@ #include <yang/testutils/translator_test.h> #include <testutils/log_utils.h> #include <testutils/threaded_test.h> +#include <testutils/sandbox.h> #include <gtest/gtest.h> #include <sstream> @@ -89,6 +90,8 @@ void clearYang(NakedNetconfAgentPtr agent) { /// @brief Test fixture class for netconf agent. class NetconfAgentTest : public ThreadedTest { public: + isc::test::Sandbox sandbox; + /// @brief Constructor. NetconfAgentTest() : ThreadedTest(), @@ -127,17 +130,15 @@ public: /// If the KEA_SOCKET_TEST_DIR environment variable is specified, the /// socket file is created in the location pointed to by this variable. /// Otherwise, it is created in the build directory. - static string unixSocketFilePath() { - ostringstream s; + string unixSocketFilePath() { + std::string socket_path; const char* env = getenv("KEA_SOCKET_TEST_DIR"); if (env) { - s << string(env); + socket_path = std::string(env) + "/test-socket"; } else { - s << TEST_DATA_BUILDDIR; + socket_path = sandbox.join("test-socket"); } - - s << "/" << TEST_SOCKET; - return (s.str()); + return (socket_path); } /// @brief Removes unix socket descriptor. |