BIND 10 trac3146, updated. abd29c04e21cac8115834506c2d9e44f69a4d716 [3146] Test for LeaseMgr::getLease6() implemented.

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Sep 6 16:55:25 UTC 2013


The branch, trac3146 has been updated
       via  abd29c04e21cac8115834506c2d9e44f69a4d716 (commit)
      from  681def2806a3296aacab813882712da9109ba72d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit abd29c04e21cac8115834506c2d9e44f69a4d716
Author: Tomek Mrugalski <tomasz at isc.org>
Date:   Fri Sep 6 18:55:09 2013 +0200

    [3146] Test for LeaseMgr::getLease6() implemented.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dhcpsrv/tests/lease_mgr_unittest.cc |   74 +++++++++++++++++++++++----
 1 file changed, 63 insertions(+), 11 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
index 06c9bad..79d5253 100644
--- a/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/lease_mgr_unittest.cc
@@ -16,6 +16,8 @@
 
 #include <asiolink/io_address.h>
 #include <dhcpsrv/lease_mgr.h>
+#include <dhcpsrv/memfile_lease_mgr.h>
+#include <dhcpsrv/tests/test_utils.h>
 
 #include <gtest/gtest.h>
 
@@ -28,6 +30,7 @@ using namespace std;
 using namespace isc;
 using namespace isc::asiolink;
 using namespace isc::dhcp;
+using namespace isc::dhcp::test;
 
 // This is a concrete implementation of a Lease database.  It does not do
 // anything useful and is used for abstract LeaseMgr class testing.
@@ -135,25 +138,25 @@ public:
 
     /// @brief Returns existing IPv6 lease for a given DUID+IA combination
     ///
-    /// @param duid client DUID
-    /// @param iaid IA identifier
+    /// @param duid ignored
+    /// @param iaid ignored
     ///
-    /// @return collection of IPv6 leases
+    /// @return whatever is set in leases6_ field
     virtual Lease6Collection getLease6(Lease6::LeaseType /* not used yet */,
                                        const DUID&, uint32_t) const {
-        return (Lease6Collection());
+        return (leases6_);
     }
 
-    /// @brief Returns existing IPv6 lease for a given DUID+IA combination
+    /// @brief Returns existing IPv6 lease for a given DUID+IA+subnet-id combination
     ///
-    /// @param duid client DUID
-    /// @param iaid IA identifier
-    /// @param subnet_id identifier of the subnet the lease must belong to
+    /// @param duid ignored
+    /// @param iaid ignored
+    /// @param subnet_id ignored
     ///
-    /// @return smart pointer to the lease (or NULL if a lease is not found)
+    /// @return whatever is set in leases6_ field
     virtual Lease6Collection getLeases6(Lease6::LeaseType /* not used yet */,
                                         const DUID&, uint32_t, SubnetID) const {
-        return (Lease6Collection());
+        return (leases6_);
     }
 
     /// @brief Updates IPv4 lease.
@@ -220,6 +223,17 @@ public:
     /// @brief Rollback transactions
     virtual void rollback() {
     }
+
+    // We need to use it in ConcreteLeaseMgr
+    using LeaseMgr::getLease6;
+
+    Lease6Collection leases6_; ///< getLease6 methods return this as is
+};
+
+class LeaseMgrTest : public GenericLeaseMgrTest {
+public:
+    LeaseMgrTest() {
+    }
 };
 
 namespace {
@@ -228,7 +242,7 @@ namespace {
 ///
 /// This test checks if the LeaseMgr can be instantiated and that it
 /// parses parameters string properly.
-TEST(LeaseMgr, getParameter) {
+TEST_F(LeaseMgrTest, getParameter) {
 
     LeaseMgr::ParameterMap pmap;
     pmap[std::string("param1")] = std::string("value1");
@@ -240,6 +254,44 @@ TEST(LeaseMgr, getParameter) {
     EXPECT_THROW(leasemgr.getParameter("param3"), BadValue);
 }
 
+// This test checks if getLease6() method is working properly for 0 (NULL),
+// 1 (return the lease) and more than 1 leases (throw).
+TEST_F(LeaseMgrTest, getLease6) {
+
+    LeaseMgr::ParameterMap pmap;
+    boost::scoped_ptr<ConcreteLeaseMgr> mgr(new ConcreteLeaseMgr(pmap));
+
+    vector<Lease6Ptr> leases = createLeases6();
+
+    mgr->leases6_.clear();
+    // For no leases, the function should return NULL pointer
+    Lease6Ptr lease;
+
+    // the getLease6() is calling getLeases6(), which is a dummy. It returns
+    // whatever is there in leases6_ field.
+    EXPECT_NO_THROW(lease = mgr->getLease6(leasetype6_[1], *leases[1]->duid_,
+                                           leases[1]->iaid_,
+                                           leases[1]->subnet_id_));
+    EXPECT_TRUE(Lease6Ptr() == lease);
+
+    // For a single lease, the function should return that lease
+    mgr->leases6_.push_back(leases[1]);
+    EXPECT_NO_THROW(lease = mgr->getLease6(leasetype6_[1], *leases[1]->duid_,
+                                           leases[1]->iaid_,
+                                           leases[1]->subnet_id_));
+    EXPECT_TRUE(lease);
+
+    EXPECT_NO_THROW(detailCompareLease(lease, leases[1]));
+
+    // Add one more lease. There are 2 now. It should throw
+    mgr->leases6_.push_back(leases[2]);
+
+    EXPECT_THROW(lease = mgr->getLease6(leasetype6_[1], *leases[1]->duid_,
+                                        leases[1]->iaid_,
+                                        leases[1]->subnet_id_),
+                 MultipleRecords);
+}
+
 // There's no point in calling any other methods in LeaseMgr, as they
 // are purely virtual, so we would only call ConcreteLeaseMgr methods.
 // Those methods are just stubs that do not return anything.



More information about the bind10-changes mailing list