From: Piotrek Zadroga Date: Wed, 17 Apr 2024 20:42:33 +0000 (+0200) Subject: [#3294] adding UTs X-Git-Tag: Kea-2.5.8~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaaae0377db9267a92d8320abf85b4f25756d291;p=thirdparty%2Fkea.git [#3294] adding UTs --- diff --git a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc index 4fbbb1f20e..3f12fd6c43 100644 --- a/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc @@ -1671,6 +1671,13 @@ TEST_F(MySQLHostMgrTest, del) { testDeleteByIDAndAddress(*getCfgHosts(), HostMgr::instance()); } +// This test verifies that the reservation can be deleted from database +// by providing subnet ID and address, and other reservations in the subnet +// remain undeleted. +TEST_F(MySQLHostMgrTest, delOneHost) { + testDeleteOneHostByIDAndAddress(HostMgr::instance()); +} + // This test verifies that the IPv4 reservations can be deleted from a // configuration file and a database by subnet ID and identifier. TEST_F(MySQLHostMgrTest, del4) { diff --git a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc index 10b15f08d9..a0ecc34d46 100644 --- a/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc @@ -1639,6 +1639,13 @@ TEST_F(PgSQLHostMgrTest, del) { testDeleteByIDAndAddress(*getCfgHosts(), HostMgr::instance()); } +// This test verifies that the reservation can be deleted from database +// by providing subnet ID and address, and other reservations in the subnet +// remain undeleted. +TEST_F(PgSQLHostMgrTest, delOneHost) { + testDeleteOneHostByIDAndAddress(HostMgr::instance()); +} + // This test verifies that the IPv4 reservations can be deleted from a // configuration file and a database by subnet ID and identifier. TEST_F(PgSQLHostMgrTest, del4) { 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 e590dbfb41..3b612f4bd0 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -5098,6 +5098,38 @@ HostMgrTest::testDeleteByIDAndAddress(BaseHostDataSource& data_source1, HostMgr::instance().del(SubnetID(1), IOAddress("2001:db8:1::5"), HostMgrOperationTarget::ALL_SOURCES); } +void +HostMgrTest::testDeleteOneHostByIDAndAddress(BaseHostDataSource& data_source) { + ASSERT_TRUE(HostMgr::instance().setIPReservationsUnique(false)); + + // This test expects alternate data source - MySQL or PostgreSQL hosts DB. + EXPECT_FALSE(isPrimaryDataSource(data_source)); + + // Add 3 IPv4 hosts. + addHost4(data_source, hwaddrs_[0], SubnetID(1), IOAddress("192.0.2.4")); + addHost4(data_source, hwaddrs_[1], SubnetID(1), IOAddress("192.0.2.5")); + addHost4(data_source, hwaddrs_[2], SubnetID(1), IOAddress("192.0.2.6")); + + // Add 3 IPv6 hosts. + addHost6(data_source, duids_[0], SubnetID(1), IOAddress("2001:db8:1::4")); + addHost6(data_source, duids_[1], SubnetID(1), IOAddress("2001:db8:1::5")); + addHost6(data_source, duids_[2], SubnetID(1), IOAddress("2001:db8:1::6")); + + CfgMgr::instance().commit(); + + // Delete only one IPv4 host - provide SubnetId and IP address for the host to be deleted. + EXPECT_TRUE(HostMgr::instance().del(SubnetID(1), IOAddress("192.0.2.4"))); + + // Delete only one IPv6 host - provide SubnetId and IP address for the host to be deleted. + EXPECT_TRUE(HostMgr::instance().del(SubnetID(1), IOAddress("2001:db8:1::4"))); + + // Expect other two IPv4 hosts still in reservations. + EXPECT_EQ(4, HostMgr::instance().getAll4(SubnetID(1)).size()); + + // Expect other two IPv6 hosts still in reservations. + EXPECT_EQ(2, HostMgr::instance().getAll6(SubnetID(1)).size()); +} + void HostMgrTest::testDelete4ByIDAndIdentifier(BaseHostDataSource& data_source1, BaseHostDataSource& data_source2) { diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h index 1219d2117b..334a73969f 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h @@ -1048,6 +1048,14 @@ protected: void testDeleteByIDAndAddress(BaseHostDataSource& data_source1, BaseHostDataSource& data_source2); + /// @brief This test verifies that HostMgr deletes only desired + /// reservations by the subnet ID and subnet address in alternate + /// data sources (hosts DB backends). It verifies that other reservations + /// in the subnet remain undeleted. + /// + /// @param data_source alternate host data source + void testDeleteOneHostByIDAndAddress(BaseHostDataSource& data_source); + /// @brief This test verifies that HostMgr deletes the IPv4 reservations by /// the subnet ID and identifier. ///