From b171bbe77b50bd89846f3d8f68d2441f74831574 Mon Sep 17 00:00:00 2001 From: Thomas Markwalder Date: Fri, 24 Mar 2023 09:37:57 -0400 Subject: [PATCH] [#225] Adding a UT modified: src/lib/dhcpsrv/tests/ncr_generator_unittest.cc --- .../dhcpsrv/tests/ncr_generator_unittest.cc | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/dhcpsrv/tests/ncr_generator_unittest.cc b/src/lib/dhcpsrv/tests/ncr_generator_unittest.cc index ae1e0348d5..4cbe1d7707 100644 --- a/src/lib/dhcpsrv/tests/ncr_generator_unittest.cc +++ b/src/lib/dhcpsrv/tests/ncr_generator_unittest.cc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,7 @@ using namespace isc; using namespace isc::asiolink; using namespace isc::dhcp; using namespace isc::dhcp_ddns; +using namespace isc::util; namespace ph = std::placeholders; namespace { @@ -226,13 +228,15 @@ public: /// @param exp_use_cr expected value of conflict resolution flag void testNCR(const NameChangeType chg_type, const bool fwd, const bool rev, const std::string& fqdn, const std::string exp_dhcid, - const bool exp_use_cr = true) { + const bool exp_use_cr = true, + const Optional ttl_percent = Optional()) { // Queue NCR. ASSERT_NO_FATAL_FAILURE(sendNCR(chg_type, fwd, rev, fqdn)); // Expecting one NCR be generated. ASSERT_EQ(1, d2_mgr_.getQueueSize()); - uint32_t ttl = calculateDdnsTtl(lease_->valid_lft_); + // Calculate expected ttl. + uint32_t ttl = calculateDdnsTtl(lease_->valid_lft_, ttl_percent); // Check the details of the NCR. verifyNameChangeRequest(chg_type, rev, fwd, lease_->addr_.toText(), exp_dhcid, @@ -710,4 +714,25 @@ TEST_F(NCRGenerator4Test, calculateDdnsTtl) { EXPECT_EQ(2705, calculateDdnsTtl(1803, ddns_ttl_percent)); } +// Verify that ddns-ttl-percent is used correctly by v4 queueNCR() +TEST_F(NCRGenerator4Test, withTtlPercent) { + { + SCOPED_TRACE("Ttl percent of 0"); + Optional ttl_percent(0); + subnet_->setDdnsTtlPercent(ttl_percent); + testNCR(CHG_REMOVE, true, true, "MYHOST.example.com.", + "000001E356D43E5F0A496D65BCA24D982D646140813E3" + "B03AB370BFF46BFA309AE7BFD", true, ttl_percent); + } + { + SCOPED_TRACE("Ttl percent of 1.5"); + Optional ttl_percent(1.5); + subnet_->setDdnsTtlPercent(ttl_percent); + testNCR(CHG_REMOVE, true, true, "MYHOST.example.com.", + "000001E356D43E5F0A496D65BCA24D982D646140813E3" + "B03AB370BFF46BFA309AE7BFD", true, ttl_percent); + } +} + + } // end of anonymous namespace -- 2.47.3