Commit 44267f77 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3359] Basic lease4 test moved to common lease test suite.

parent c62714b4
......@@ -108,4 +108,17 @@ TEST_F(MemfileLeaseMgrTest, getLease4ClientIdHWAddrSubnetId) {
testGetLease4ClientIdHWAddrSubnetId();
}
/// @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(MemfileLeaseMgrTest, DISABLED_lease4NullClientId) {
/// @todo Test is disabled, because memfile does not support disk storage, so
/// all leases are lost after reopen()
testLease4NullClientId();
}
}; // end of anonymous namespace
......@@ -330,81 +330,14 @@ TEST_F(MySqlLeaseMgrTest, testAddGetDelete6) {
testAddGetDelete6(false);
}
/// @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
HWAddr tmp(leases[2]->hwaddr_, HTYPE_ETHER);
Lease4Collection returned = lmptr_->getLease4(tmp);
ASSERT_EQ(1, returned.size());
detailCompareLease(leases[2], *returned.begin());
l_returned = lmptr_->getLease4(tmp, 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);
testLease4NullClientId();
}
/// @brief Verify that too long hostname for Lease4 is not accepted.
......
......@@ -525,6 +525,75 @@ GenericLeaseMgrTest::testGetLease4NullClientId() {
ASSERT_EQ(1, returned.size());
}
void
GenericLeaseMgrTest::testLease4NullClientId() {
// 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
HWAddr tmp(leases[2]->hwaddr_, HTYPE_ETHER);
Lease4Collection returned = lmptr_->getLease4(tmp);
ASSERT_EQ(1, returned.size());
detailCompareLease(leases[2], *returned.begin());
l_returned = lmptr_->getLease4(tmp, 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);
}
void
GenericLeaseMgrTest::testGetLease4HWAddr() {
// Let's initialize two different leases 4 and just add the first ...
......
......@@ -127,6 +127,15 @@ public:
/// @brief Test lease retrieval using client id, HW address and subnet id.
void testGetLease4ClientIdHWAddrSubnetId();
/// @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)
///
/// @todo: check if it does overlap with @ref testGetLease4NullClientId()
void testLease4NullClientId();
/// @brief Test that IPv6 lease can be added, retrieved and deleted.
///
/// This method checks basic IPv6 lease operations. There's check_t1_t2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment