|
@@ -712,6 +712,84 @@ TEST_F(MySqlLeaseMgrTest, basicLease4) {
|
|
|
detailCompareLease(leases[2], l_returned);
|
|
|
}
|
|
|
|
|
|
+/// @brief Basic Lease4 Checks
|
|
|
+///
|
|
|
+/// Checks that the addLease, getLease4(by address), getLease4(hwaddr,subnet_id),
|
|
|
+/// updateLease4() and deleteLease (IPv4 address) can handle NULL client-id.
|
|
|
+/// (client-id is optional and may not be present)
|
|
|
+TEST_F(MySqlLeaseMgrTest, lease4NullClientId) {
|
|
|
+ // Get the leases to be used for the test.
|
|
|
+ vector<Lease4Ptr> leases = createLeases4();
|
|
|
+
|
|
|
+ // Let's clear client-id pointers
|
|
|
+ leases[1]->client_id_ = ClientIdPtr();
|
|
|
+ leases[2]->client_id_ = ClientIdPtr();
|
|
|
+ leases[3]->client_id_ = ClientIdPtr();
|
|
|
+
|
|
|
+ // Start the tests. Add three leases to the database, read them back and
|
|
|
+ // check they are what we think they are.
|
|
|
+ EXPECT_TRUE(lmptr_->addLease(leases[1]));
|
|
|
+ EXPECT_TRUE(lmptr_->addLease(leases[2]));
|
|
|
+ EXPECT_TRUE(lmptr_->addLease(leases[3]));
|
|
|
+ lmptr_->commit();
|
|
|
+
|
|
|
+ // Reopen the database to ensure that they actually got stored.
|
|
|
+ reopen();
|
|
|
+
|
|
|
+ Lease4Ptr l_returned = lmptr_->getLease4(ioaddress4_[1]);
|
|
|
+ ASSERT_TRUE(l_returned);
|
|
|
+ detailCompareLease(leases[1], l_returned);
|
|
|
+
|
|
|
+ l_returned = lmptr_->getLease4(ioaddress4_[2]);
|
|
|
+ ASSERT_TRUE(l_returned);
|
|
|
+ detailCompareLease(leases[2], l_returned);
|
|
|
+
|
|
|
+ l_returned = lmptr_->getLease4(ioaddress4_[3]);
|
|
|
+ ASSERT_TRUE(l_returned);
|
|
|
+ detailCompareLease(leases[3], l_returned);
|
|
|
+
|
|
|
+ // Check that we can't add a second lease with the same address
|
|
|
+ EXPECT_FALSE(lmptr_->addLease(leases[1]));
|
|
|
+
|
|
|
+
|
|
|
+ // Check that we can get the lease by HWAddr
|
|
|
+ Lease4Collection returned = lmptr_->getLease4(leases[2]->hwaddr_);
|
|
|
+
|
|
|
+ ASSERT_EQ(1, returned.size());
|
|
|
+ detailCompareLease(leases[2], *returned.begin());
|
|
|
+
|
|
|
+ l_returned = lmptr_->getLease4(leases[2]->hwaddr_, leases[2]->subnet_id_);
|
|
|
+ ASSERT_TRUE(l_returned);
|
|
|
+ detailCompareLease(leases[2], l_returned);
|
|
|
+
|
|
|
+
|
|
|
+ // Check that we can update the lease
|
|
|
+ // Modify some fields in lease 1 (not the address) and update it.
|
|
|
+ ++leases[1]->subnet_id_;
|
|
|
+ leases[1]->valid_lft_ *= 2;
|
|
|
+ lmptr_->updateLease4(leases[1]);
|
|
|
+
|
|
|
+ // ... and check that the lease is indeed updated
|
|
|
+ l_returned = lmptr_->getLease4(ioaddress4_[1]);
|
|
|
+ ASSERT_TRUE(l_returned);
|
|
|
+ detailCompareLease(leases[1], l_returned);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Delete a lease, check that it's gone, and that we can't delete it
|
|
|
+ // a second time.
|
|
|
+ EXPECT_TRUE(lmptr_->deleteLease(ioaddress4_[1]));
|
|
|
+ l_returned = lmptr_->getLease4(ioaddress4_[1]);
|
|
|
+ EXPECT_FALSE(l_returned);
|
|
|
+ EXPECT_FALSE(lmptr_->deleteLease(ioaddress4_[1]));
|
|
|
+
|
|
|
+ // Check that the second address is still there.
|
|
|
+ l_returned = lmptr_->getLease4(ioaddress4_[2]);
|
|
|
+ ASSERT_TRUE(l_returned);
|
|
|
+ detailCompareLease(leases[2], l_returned);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
/// @brief Basic Lease6 Checks
|
|
|
///
|
|
|
/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
|
|
@@ -791,14 +869,14 @@ TEST_F(MySqlLeaseMgrTest, getLease4Hwaddr) {
|
|
|
// Repeat test with just one expected match
|
|
|
// @todo: Simply use HWAddr directly once 2589 is implemented
|
|
|
returned = lmptr_->getLease4(HWAddr(leases[2]->hwaddr_, HTYPE_ETHER));
|
|
|
- EXPECT_EQ(1, returned.size());
|
|
|
+ ASSERT_EQ(1, returned.size());
|
|
|
detailCompareLease(leases[2], *returned.begin());
|
|
|
|
|
|
// Check that an empty vector is valid
|
|
|
EXPECT_TRUE(leases[7]->hwaddr_.empty());
|
|
|
// @todo: Simply use HWAddr directly once 2589 is implemented
|
|
|
returned = lmptr_->getLease4(HWAddr(leases[7]->hwaddr_, HTYPE_ETHER));
|
|
|
- EXPECT_EQ(1, returned.size());
|
|
|
+ ASSERT_EQ(1, returned.size());
|
|
|
detailCompareLease(leases[7], *returned.begin());
|
|
|
|
|
|
// Try to get something with invalid hardware address
|
|
@@ -968,13 +1046,13 @@ TEST_F(MySqlLeaseMgrTest, getLease4ClientId) {
|
|
|
|
|
|
// Repeat test with just one expected match
|
|
|
returned = lmptr_->getLease4(*leases[3]->client_id_);
|
|
|
- EXPECT_EQ(1, returned.size());
|
|
|
+ ASSERT_EQ(1, returned.size());
|
|
|
detailCompareLease(leases[3], *returned.begin());
|
|
|
|
|
|
// Check that an empty vector is valid
|
|
|
EXPECT_TRUE(leases[7]->client_id_->getClientId().empty());
|
|
|
returned = lmptr_->getLease4(leases[7]->hwaddr_);
|
|
|
- EXPECT_EQ(1, returned.size());
|
|
|
+ ASSERT_EQ(1, returned.size());
|
|
|
detailCompareLease(leases[7], *returned.begin());
|
|
|
|
|
|
// Try to get something with invalid client ID
|
|
@@ -1113,7 +1191,7 @@ TEST_F(MySqlLeaseMgrTest, getLease6DuidIaidSize) {
|
|
|
EXPECT_TRUE(lmptr_->addLease(leases[1]));
|
|
|
Lease6Collection returned = lmptr_->getLease6(*leases[1]->duid_,
|
|
|
leases[1]->iaid_);
|
|
|
- EXPECT_EQ(1, returned.size());
|
|
|
+ ASSERT_EQ(1, returned.size());
|
|
|
detailCompareLease(leases[1], *returned.begin());
|
|
|
(void) lmptr_->deleteLease(leases[1]->addr_);
|
|
|
}
|