summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2024-12-19 15:50:20 +0100
committerFrancis Dupont <fdupont@isc.org>2024-12-24 14:03:04 +0100
commitdf3f1a9164fd6498648fbfc46591918bbda119d6 (patch)
tree8fdb51726381c12d31f6eabe5afca41427284574 /src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
parent[#3698] Install gtest sources on FreeBSD (diff)
downloadkea-df3f1a9164fd6498648fbfc46591918bbda119d6.tar.xz
kea-df3f1a9164fd6498648fbfc46591918bbda119d6.zip
[#2101] load hooks using name only
Diffstat (limited to 'src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc')
-rw-r--r--src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
index 9ea17057c3..af1ef3daca 100644
--- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
+++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
@@ -34,6 +34,7 @@
#include <exceptions/exceptions.h>
#include <hooks/hooks_parser.h>
#include <hooks/hooks_manager.h>
+#include <util/filesystem.h>
#include <testutils/gtest_utils.h>
#include <testutils/test_to_element.h>
@@ -52,6 +53,7 @@ using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::hooks;
using namespace isc::test;
+using namespace isc::util::file;
namespace {
@@ -327,11 +329,13 @@ public:
ParseConfigTest()
:family_(AF_INET6) {
reset_context();
+ HooksLibrariesParser::default_hooks_path_ = string(DEFAULT_HOOKS_PATH);
}
~ParseConfigTest() {
reset_context();
CfgMgr::instance().clear();
+ HooksLibrariesParser::default_hooks_path_ = string(DEFAULT_HOOKS_PATH);
}
/// @brief Parses a configuration.
@@ -2277,6 +2281,45 @@ TEST_F(ParseConfigTest, oneHooksLibrary) {
EXPECT_EQ(CALLOUT_LIBRARY_1, hooks_libraries[0]);
}
+// hooks-libraries element that contains a single library with relative path.
+TEST_F(ParseConfigTest, oneHooksLibraryRelativePath) {
+ // Check that no libraries are currently loaded
+ vector<string> hooks_libraries = HooksManager::getLibraryNames();
+ EXPECT_TRUE(hooks_libraries.empty());
+
+ Path path(CALLOUT_LIBRARY_1);
+
+ HooksLibrariesParser::default_hooks_path_ = path.parentPath();
+
+ // Configuration with hooks-libraries set to a single library.
+ string config = setHooksLibrariesConfig(path.filename().c_str());
+
+ // Verify that the configuration string parses.
+ const int rcode = parseConfiguration(config);
+ ASSERT_TRUE(rcode == 0) << error_text_;
+
+ config = setHooksLibrariesConfig(CALLOUT_LIBRARY_1);
+
+ // Verify that the configuration object unparses.
+ ConstElementPtr expected;
+ ASSERT_NO_THROW(expected =
+ Element::fromJSON(config)->get("hooks-libraries"));
+ ASSERT_TRUE(expected);
+ const HooksConfig& cfg =
+ CfgMgr::instance().getStagingCfg()->getHooksConfig();
+ runToElementTest<HooksConfig>(expected, cfg);
+
+ // Check that the parser recorded a single library.
+ isc::hooks::HookLibsCollection libraries = getLibraries();
+ ASSERT_EQ(1, libraries.size());
+ EXPECT_EQ(CALLOUT_LIBRARY_1, libraries[0].first);
+
+ // Check that the change was propagated to the hooks manager.
+ hooks_libraries = HooksManager::getLibraryNames();
+ ASSERT_EQ(1, hooks_libraries.size());
+ EXPECT_EQ(CALLOUT_LIBRARY_1, hooks_libraries[0]);
+}
+
// hooks-libraries element that contains two libraries
TEST_F(ParseConfigTest, twoHooksLibraries) {
// Check that no libraries are currently loaded