]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3294] adding UTs
authorPiotrek Zadroga <piotrek@isc.org>
Wed, 17 Apr 2024 20:42:33 +0000 (22:42 +0200)
committerPiotrek Zadroga <piotrek@isc.org>
Tue, 23 Apr 2024 07:27:35 +0000 (09:27 +0200)
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/pgsql_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.h

index 4fbbb1f20e9894418adef0ff1e06b60550849da1..3f12fd6c4330eb493ea3c0ac7098088405290b60 100644 (file)
@@ -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) {
index 10b15f08d9a90ab878dcb9acbc521942fb754f15..a0ecc34d46a13d1c06e3b7652b367c352a9814a0 100644 (file)
@@ -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) {
index e590dbfb415e6561a238b43858aceb5f631ce74c..3b612f4bd06b3064dba1152c0bed010269fbfa86 100644 (file)
@@ -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) {
index 1219d2117bfe008cbd654956f149a6b1abb8d378..334a73969fa7a22ce07ffed6b3a00c40b211d628 100644 (file)
@@ -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.
     ///