Commit ae241216 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3359] getLease4HWAddr tests moved to common framework.

parent 44267f77
......@@ -99,8 +99,16 @@ TEST_F(MemfileLeaseMgrTest, getLease4NullClientId) {
}
// Checks lease4 retrieval through HWAddr
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr) {
testGetLease4HWAddr();
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr1) {
testGetLease4HWAddr1();
}
/// @brief Check GetLease4 methods - access by Hardware Address
///
/// Adds leases to the database and checks that they can be accessed via
/// a combination of DUID and IAID.
TEST_F(MemfileLeaseMgrTest, getLease4HWAddr2) {
testGetLease4HWAddr2();
}
// Checks lease4 retrieval with clientId, HWAddr and subnet_id
......
......@@ -370,45 +370,7 @@ TEST_F(MySqlLeaseMgrTest, lease4InvalidHostname) {
/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
/// IPv6 address) works.
TEST_F(MySqlLeaseMgrTest, basicLease6) {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
// 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();
Lease6Ptr l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[2], l_returned);
l_returned = lmptr_->getLease6(leasetype6_[3], ioaddress6_[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]));
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
EXPECT_TRUE(lmptr_->deleteLease(ioaddress6_[1]));
l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]);
EXPECT_FALSE(l_returned);
EXPECT_FALSE(lmptr_->deleteLease(ioaddress6_[1]));
// Check that the second address is still there.
l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[2], l_returned);
testBasicLease6();
}
/// @brief Verify that too long hostname for Lease6 is not accepted.
......@@ -437,52 +399,13 @@ TEST_F(MySqlLeaseMgrTest, lease6InvalidHostname) {
}
/// @brief Check GetLease4 methods - access by Hardware Address
///
/// Adds leases to the database and checks that they can be accessed via
/// a combination of DIUID and IAID.
TEST_F(MySqlLeaseMgrTest, getLease4Hwaddr) {
// Get the leases to be used for the test and add to the database
vector<Lease4Ptr> leases = createLeases4();
for (int i = 0; i < leases.size(); ++i) {
EXPECT_TRUE(lmptr_->addLease(leases[i]));
}
// Get the leases matching the hardware address of lease 1
/// @todo: Simply use HWAddr directly once 2589 is implemented
HWAddr tmp(leases[1]->hwaddr_, HTYPE_ETHER);
Lease4Collection returned = lmptr_->getLease4(tmp);
// Should be three leases, matching leases[1], [3] and [5].
ASSERT_EQ(3, returned.size());
// Easiest way to check is to look at the addresses.
vector<string> addresses;
for (Lease4Collection::const_iterator i = returned.begin();
i != returned.end(); ++i) {
addresses.push_back((*i)->addr_.toText());
}
sort(addresses.begin(), addresses.end());
EXPECT_EQ(straddress4_[1], addresses[0]);
EXPECT_EQ(straddress4_[3], addresses[1]);
EXPECT_EQ(straddress4_[5], addresses[2]);
// 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));
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));
ASSERT_EQ(1, returned.size());
detailCompareLease(leases[7], *returned.begin());
TEST_F(MySqlLeaseMgrTest, getLease4HWAddr1) {
testGetLease4HWAddr1();
}
// Try to get something with invalid hardware address
vector<uint8_t> invalid(6, 0);
returned = lmptr_->getLease4(invalid);
EXPECT_EQ(0, returned.size());
/// @brief Check GetLease4 methods - access by Hardware Address
TEST_F(MySqlLeaseMgrTest, getLease4HWAddr2) {
testGetLease4HWAddr2();
}
// @brief Get lease4 by hardware address (2)
......
......@@ -595,7 +595,7 @@ GenericLeaseMgrTest::testLease4NullClientId() {
}
void
GenericLeaseMgrTest::testGetLease4HWAddr() {
GenericLeaseMgrTest::testGetLease4HWAddr1() {
// Let's initialize two different leases 4 and just add the first ...
Lease4Ptr leaseA = initializeLease4(straddress4_[5]);
HWAddr hwaddrA(leaseA->hwaddr_, HTYPE_ETHER);
......@@ -612,6 +612,52 @@ GenericLeaseMgrTest::testGetLease4HWAddr() {
ASSERT_EQ(1, returned.size());
}
void
GenericLeaseMgrTest::testGetLease4HWAddr2() {
// Get the leases to be used for the test and add to the database
vector<Lease4Ptr> leases = createLeases4();
for (int i = 0; i < leases.size(); ++i) {
EXPECT_TRUE(lmptr_->addLease(leases[i]));
}
// Get the leases matching the hardware address of lease 1
/// @todo: Simply use HWAddr directly once 2589 is implemented
HWAddr tmp(leases[1]->hwaddr_, HTYPE_ETHER);
Lease4Collection returned = lmptr_->getLease4(tmp);
// Should be three leases, matching leases[1], [3] and [5].
ASSERT_EQ(3, returned.size());
// Easiest way to check is to look at the addresses.
vector<string> addresses;
for (Lease4Collection::const_iterator i = returned.begin();
i != returned.end(); ++i) {
addresses.push_back((*i)->addr_.toText());
}
sort(addresses.begin(), addresses.end());
EXPECT_EQ(straddress4_[1], addresses[0]);
EXPECT_EQ(straddress4_[3], addresses[1]);
EXPECT_EQ(straddress4_[5], addresses[2]);
// 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));
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));
ASSERT_EQ(1, returned.size());
detailCompareLease(leases[7], *returned.begin());
// Try to get something with invalid hardware address
vector<uint8_t> invalid(6, 0);
returned = lmptr_->getLease4(invalid);
EXPECT_EQ(0, returned.size());
}
void
GenericLeaseMgrTest::testGetLease4ClientIdHWAddrSubnetId() {
Lease4Ptr leaseA = initializeLease4(straddress4_[4]);
......@@ -771,6 +817,50 @@ GenericLeaseMgrTest::testBasicLease4() {
}
void
GenericLeaseMgrTest::testBasicLease6() {
// Get the leases to be used for the test.
vector<Lease6Ptr> leases = createLeases6();
// 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();
Lease6Ptr l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[1], l_returned);
l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[2], l_returned);
l_returned = lmptr_->getLease6(leasetype6_[3], ioaddress6_[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]));
// Delete a lease, check that it's gone, and that we can't delete it
// a second time.
EXPECT_TRUE(lmptr_->deleteLease(ioaddress6_[1]));
l_returned = lmptr_->getLease6(leasetype6_[1], ioaddress6_[1]);
EXPECT_FALSE(l_returned);
EXPECT_FALSE(lmptr_->deleteLease(ioaddress6_[1]));
// Check that the second address is still there.
l_returned = lmptr_->getLease6(leasetype6_[2], ioaddress6_[2]);
ASSERT_TRUE(l_returned);
detailCompareLease(leases[2], l_returned);
}
};
};
};
......@@ -122,7 +122,13 @@ public:
void testGetLease4NullClientId();
/// @brief Test lease retrieval using HW address.
void testGetLease4HWAddr();
void testGetLease4HWAddr1();
/// @brief Check GetLease4 methods - access by Hardware Address
///
/// Adds leases to the database and checks that they can be accessed using
/// HWAddr information.
void testGetLease4HWAddr2();
/// @brief Test lease retrieval using client id, HW address and subnet id.
void testGetLease4ClientIdHWAddrSubnetId();
......@@ -136,6 +142,12 @@ public:
/// @todo: check if it does overlap with @ref testGetLease4NullClientId()
void testLease4NullClientId();
/// @brief Basic Lease6 Checks
///
/// Checks that the addLease, getLease6 (by address) and deleteLease (with an
/// IPv6 address) works.
void testBasicLease6();
/// @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