diff options
author | Slawek Figiel <slawek@isc.org> | 2023-04-11 20:23:25 +0200 |
---|---|---|
committer | Slawek Figiel <slawek@isc.org> | 2023-05-25 13:29:29 +0200 |
commit | c6491b3276baeb5f79f1a30436eae8eda3b1732e (patch) | |
tree | 69a4e3b1b3dae09217a496ece9a0f70e74088e6e /src/lib/dhcpsrv/testutils | |
parent | [#2815] Extend unit test (diff) | |
download | kea-c6491b3276baeb5f79f1a30436eae8eda3b1732e.tar.xz kea-c6491b3276baeb5f79f1a30436eae8eda3b1732e.zip |
[#2815] Extend unit tests
Diffstat (limited to 'src/lib/dhcpsrv/testutils')
-rw-r--r-- | src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index ca51d73eb4..36cd198705 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -4195,14 +4195,16 @@ HostMgrTest::testGet6ByPrefix(BaseHostDataSource& data_source1, // Select host only from the primary source. host = HostMgr::instance().get6(IOAddress("2001:db8:1::"), 64, HostMgrOperationTarget::PRIMARY_SOURCE); if (is_first_source_primary) { + EXPECT_TRUE(host); EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1::"), 64))); } else { EXPECT_FALSE(host); } - host = HostMgr::instance().get6(IOAddress("2001:db8:1:0:6::"), 64, HostMgrOperationTarget::PRIMARY_SOURCE); + host = HostMgr::instance().get6(IOAddress("2001:db8:1:0:6::"), 72, HostMgrOperationTarget::PRIMARY_SOURCE); if (is_second_source_primary) { + EXPECT_TRUE(host); EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1:0:6::"), 72))); } else { @@ -4212,14 +4214,16 @@ HostMgrTest::testGet6ByPrefix(BaseHostDataSource& data_source1, // Select hosts only from the alternate sources. host = HostMgr::instance().get6(IOAddress("2001:db8:1::"), 64, HostMgrOperationTarget::ALTERNATE_SOURCES); if (!is_first_source_primary) { + EXPECT_TRUE(host); EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1::"), 64))); } else { EXPECT_FALSE(host); } - host = HostMgr::instance().get6(IOAddress("2001:db8:1:0:6::"), 64, HostMgrOperationTarget::ALTERNATE_SOURCES); + host = HostMgr::instance().get6(IOAddress("2001:db8:1:0:6::"), 72, HostMgrOperationTarget::ALTERNATE_SOURCES); if (!is_second_source_primary) { + EXPECT_TRUE(host); EXPECT_TRUE(host->hasReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, IOAddress("2001:db8:1:0:6::"), 72))); } else { @@ -4227,7 +4231,7 @@ HostMgrTest::testGet6ByPrefix(BaseHostDataSource& data_source1, } // Select hosts for an unspecified source. - host = HostMgr::instance().get6(IOAddress("2001:db8:1:0:6::"), 64, HostMgrOperationTarget::UNSPECIFIED_SOURCE); + host = HostMgr::instance().get6(IOAddress("2001:db8:1:0:6::"), 72, HostMgrOperationTarget::UNSPECIFIED_SOURCE); EXPECT_FALSE(host); } @@ -4336,6 +4340,39 @@ HostMgrTest::testGetAll6BySubnetIP(BaseHostDataSource& data_source1, IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5")))); EXPECT_TRUE(hosts[1]->hasReservation( IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5")))); + + // Make sure that the operation target is supported. + bool is_first_source_primary = isPrimaryDataSource(data_source1); + bool is_second_source_primary = isPrimaryDataSource(data_source2); + size_t hosts_in_primary_source = is_first_source_primary + is_second_source_primary; + + // Select hosts only from the primary source. + hosts = HostMgr::instance().getAll6(SubnetID(1), IOAddress("2001:db8:1::5"), HostMgrOperationTarget::PRIMARY_SOURCE); + EXPECT_EQ(hosts_in_primary_source, hosts.size()); + if (is_first_source_primary) { + EXPECT_TRUE(hosts[0]->hasReservation( + IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5")))); + } + if (is_second_source_primary) { + EXPECT_TRUE(hosts[hosts_in_primary_source - 1]->hasReservation( + IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5")))); + } + + // Select hosts only from the alternate sources. + hosts = HostMgr::instance().getAll6(SubnetID(1), IOAddress("2001:db8:1::5"), HostMgrOperationTarget::ALTERNATE_SOURCES); + EXPECT_EQ(2 - hosts_in_primary_source, hosts.size()); + if (!is_first_source_primary) { + EXPECT_TRUE(hosts[0]->hasReservation( + IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5")))); + } + if (!is_second_source_primary) { + EXPECT_TRUE(hosts[2 - hosts_in_primary_source - 1]->hasReservation( + IPv6Resrv(IPv6Resrv::TYPE_NA, IOAddress("2001:db8:1::5")))); + } + + // Select hosts for an unspecified source. + hosts = HostMgr::instance().getAll4(SubnetID(1), IOAddress("2001:db8:1::5"), HostMgrOperationTarget::UNSPECIFIED_SOURCE); + EXPECT_EQ(0, hosts.size()); } bool HostMgrTest::isPrimaryDataSource(const BaseHostDataSource& data_source) const { |