]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3682] Unit-tests for IPv4 reservations are now complete.
authorTomek Mrugalski <tomasz@isc.org>
Fri, 13 Nov 2015 11:32:06 +0000 (12:32 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Fri, 13 Nov 2015 11:32:06 +0000 (12:32 +0100)
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.cc
src/lib/dhcpsrv/tests/generic_host_data_source_unittest.h
src/lib/dhcpsrv/tests/mysql_host_data_source_unittest.cc

index 2d9933757235d6a837c752225e98df3985d47d8c..132590a41e7821846751599ddba18dde38863e95 100644 (file)
@@ -459,6 +459,57 @@ void GenericHostDataSourceTest::testClientIdNotHWAddr() {
     EXPECT_FALSE(by_hwaddr);
 }
 
+void
+GenericHostDataSourceTest::testHostname(std::string name, int num) {
+
+    // Make sure we have a pointer to the host data source.
+    ASSERT_TRUE(hdsptr_);
+
+    // Initialize the address to 192.0.2.0 (this will be bumped
+    // up to 192.0.2.1 in the first iteration)
+    IOAddress addr("192.0.2.0");
+
+    vector<HostPtr> hosts;
+
+    // Prepare a vector of hosts with unique hostnames
+    for (int i = 0; i < num; ++i) {
+
+        addr = IOAddress::increase(addr);
+
+        HostPtr host = initializeHost4(addr.toText(), false);
+
+        stringstream hostname;
+        hostname.str("");
+        if (num > 1) {
+            hostname << i;
+        }
+        hostname << name;
+        host->setHostname(hostname.str());
+
+        hosts.push_back(host);
+    }
+
+    // Now add them all to the host data source.
+    for (vector<HostPtr>::const_iterator it = hosts.begin();
+         it != hosts.end(); ++it) {
+        // Try to add both of the to the host data source.
+        ASSERT_NO_THROW(hdsptr_->add(*it));
+    }
+
+    // And finally retrieve them one by one and check
+    // if the hostname was preserved.
+    for (vector<HostPtr>::const_iterator it = hosts.begin();
+         it != hosts.end(); ++it) {
+
+        ConstHostPtr from_hds;
+        ASSERT_NO_THROW(from_hds = hdsptr_->get4(
+                            (*it)->getIPv4SubnetID(),
+                            (*it)->getIPv4Reservation()));
+        ASSERT_TRUE(from_hds);
+
+        EXPECT_EQ((*it)->getHostname(), from_hds->getHostname());
+    }
+}
 
 }; // namespace test
 }; // namespace dhcp
index 9ec22fffa4efc5f43deb0aeab5dc8710c85bfe08..7455d9023ec7338c4067eefa61aa336112917f20 100644 (file)
@@ -153,15 +153,31 @@ public:
     /// @brief Test that clients with stored HW address can't be retrieved
     ///        by DUID with the same value.
     ///
+    /// Test procedure: add host reservation with hardware address X, try to retrieve
+    /// host by client-identifier X, verify that the reservation is not returned.
+    ///
     /// Uses gtest macros to report failures.
     void testHWAddrNotClientId();
 
     /// @brief Test that clients with stored DUID can't be retrieved
     ///        by HW address of the same value.
     ///
+    /// Test procedure: add host reservation with client identifier X, try to
+    /// retrieve host by hardware address X, verify that the reservation is not
+    /// returned.
+    ///
     /// Uses gtest macros to report failures.
     void testClientIdNotHWAddr();
 
+    /// @brief Test adds specified number of hosts with unique hostnames, then
+    /// retrives them and checks that the hostnames are set properly.
+    ///
+    /// Uses gtest macros to report failures.
+    ///
+    /// @param name hostname to be used (if n>1, numbers will be appended)
+    /// @param num number of hostnames to be added.
+    void testHostname(std::string name, int num);
+
     /// @brief Returns DUID with identical content as specified HW address
     ///
     /// This method does not have any sense in real life and is only useful
index 32e5f94610df535b59c4afd952a32b006b58db6d..77862345b14ff8a6310367749404be79adec2999 100644 (file)
@@ -337,26 +337,45 @@ TEST_F(MySqlHostDataSourceTest, getByClientId) {
 // Test verifies if hardware address and client identifier are not confused.
 TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId1) {
     testHWAddrNotClientId();
-    /// @todo: add host reservation with hardware address X, try to retrieve
-    /// host by client-identifier X, verify that the reservation is not returned.
 }
 
 // Test verifies if hardware address and client identifier are not confused.
 TEST_F(MySqlHostDataSourceTest, hwaddrNotClientId2) {
     testClientIdNotHWAddr();
-    /// @todo: add host reservation with client identifier X, try to retrieve host
-    /// by hardware address X, verify that the reservation is not returned.
+}
+
+// Test verifies if a host with FQDN hostname can be stored and later retrieved.
+TEST_F(MySqlHostDataSourceTest, hostnameFQDN) {
+    testHostname("foo.example.org", 1);
+}
+
+// Test verifies if 100 hosts with unique FQDN hostnames can be stored and later
+// retrieved.
+TEST_F(MySqlHostDataSourceTest, hostnameFQDN100) {
+    testHostname("foo.example.org", 1);
+}
+
+// Test verifies if a host without any hostname specified can be stored and later
+// retrieved.
+TEST_F(MySqlHostDataSourceTest, noHostname) {
+    testHostname("", 1);
 }
 
 // Test verifies if the hardware or client-id query can match hardware address.
-TEST_F(MySqlHostDataSourceTest, hwaddrOrClientId1) {
+TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId1) {
+    /// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
+    /// be discussed.
+    ///
     /// @todo: Add host reservation with hardware address X, try to retrieve
     /// host for hardware address X or client identifier Y, verify that the
     /// reservation is returned.
 }
 
 // Test verifies if the hardware or client-id query can match client-id.
-TEST_F(MySqlHostDataSourceTest, hwaddrOrClientId2) {
+TEST_F(MySqlHostDataSourceTest, DISABLED_hwaddrOrClientId2) {
+    /// @todo: The logic behind ::get4(subnet_id, hwaddr, duid) call needs to
+    /// be discussed.
+    ///
     /// @todo: Add host reservation with client identifier Y, try to retrieve
     /// host for hardware address X or client identifier Y, verify that the
     /// reservation is returned.