From: Slawek Figiel Date: Thu, 6 Apr 2023 15:00:23 +0000 (+0200) Subject: [#2815] Add unit test X-Git-Tag: Kea-2.3.8~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=07e39ecb604aa35131e989a5e4f34352bad0fdae;p=thirdparty%2Fkea.git [#2815] Add unit test --- diff --git a/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc b/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc index 62e1a22e3e..0abd18d200 100644 --- a/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc +++ b/src/lib/dhcpsrv/tests/cfg_hosts_unittest.cc @@ -277,6 +277,34 @@ TEST_F(CfgHostsTest, getAll6BySubnet) { } } +// This test checks that hosts with the same reserved address can be retrieved +// from the host configuration. +TEST_F(CfgHostsTest, getAll6ByAddress) { + CfgHosts cfg; + // Add 25 hosts identified by DUID in the same subnet. + for (unsigned i = 0; i < 25; ++i) { + HostPtr host = HostPtr(new Host(duids_[i]->toText(), "duid", + SUBNET_ID_UNUSED, SubnetID(1), + IOAddress("0.0.0.0"))); + host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, + increase(IOAddress("2001:db8:1::1"), + i % 5))); + cfg.add(host); + } + + // Try to retrieve all added reservations with IP equals 2001:db8:1::1. + auto hosts = cfg.getAll6(IOAddress("2001:db8:1::1")); + EXPECT_EQ(5, hosts.size()); + for (unsigned i = 0; i < 5; ++i) { + EXPECT_EQ(1 + 5 * i, hosts[i]->getIPv6SubnetID()); + IPv6ResrvRange reservations = + hosts[i]->getIPv6Reservations(IPv6Resrv::TYPE_NA); + ASSERT_EQ(1, std::distance(reservations.first, reservations.second)); + EXPECT_EQ(IOAddress("2001:db8:1::1"), + reservations.first->second.getPrefix()); + } +} + // This test checks that hosts in the same subnet can be retrieved from // the host configuration by pages. TEST_F(CfgHostsTest, getPage4) {