2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-09-01 22:45:18 +00:00

[2679] complete conversion to param tests.

it also fixed some intermediate regression: accessor creation and some
other setups that depend on the accessor should be more carefully
customized.
This commit is contained in:
JINMEI Tatuya
2013-02-06 22:42:36 -08:00
parent b20cc153bc
commit f866170c9a

View File

@@ -1165,14 +1165,6 @@ public:
qclass_(RRClass::IN()), qtype_(RRType::A()), qclass_(RRClass::IN()), qtype_(RRType::A()),
rrttl_(3600) rrttl_(3600)
{ {
createClient();
// set up the commonly used finder.
DataSourceClient::FindResult zone(client_->findZone(zname_));
assert(zone.code == result::SUCCESS);
finder_ = dynamic_pointer_cast<DatabaseClient::Finder>(
zone.zone_finder);
// Test IN/A RDATA to be added in update tests. Intentionally using // Test IN/A RDATA to be added in update tests. Intentionally using
// different data than the initial data configured in the MockAccessor. // different data than the initial data configured in the MockAccessor.
rrset_.reset(new RRset(qname_, qclass_, qtype_, rrttl_)); rrset_.reset(new RRset(qname_, qclass_, qtype_, rrttl_));
@@ -1193,6 +1185,12 @@ public:
"FAKEFAKEFAKE")); "FAKEFAKEFAKE"));
} }
// We create accessor and other objects that depend on it in SetUp, not
// in the constructor, so derived test classes can override the behavior.
virtual void SetUp() {
createClient(GetParam());
}
~DatabaseClientTest() { ~DatabaseClientTest() {
// Make sure we return the default creator no matter if we set it or // Make sure we return the default creator no matter if we set it or
// not // not
@@ -1203,7 +1201,7 @@ public:
* We initialize the client from a function, so we can call it multiple * We initialize the client from a function, so we can call it multiple
* times per test. * times per test.
*/ */
void createClient() { void createClient(const DatabaseClientTestParam* test_param) {
// To make sure we always have empty diffs table at the beginning of // To make sure we always have empty diffs table at the beginning of
// each test, we re-install the writable data source here. // each test, we re-install the writable data source here.
// Note: this is SQLite3 specific and a waste (though otherwise // Note: this is SQLite3 specific and a waste (though otherwise
@@ -1222,10 +1220,16 @@ public:
"Error setting up; command failed: " << install_cmd); "Error setting up; command failed: " << install_cmd);
} }
current_accessor_ = (GetParam()->accessor_creator)(); current_accessor_ = test_param->accessor_creator();
is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_.get()) != is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_.get()) !=
NULL); NULL);
client_.reset(new DatabaseClient(qclass_, current_accessor_)); client_.reset(new DatabaseClient(qclass_, current_accessor_));
// set up the commonly used finder.
const DataSourceClient::FindResult result(client_->findZone(zname_));
assert(result.code == result::SUCCESS);
finder_ = dynamic_pointer_cast<DatabaseClient::Finder>(
result.zone_finder);
} }
/** /**
@@ -1459,9 +1463,7 @@ class MockDatabaseClientTest : public DatabaseClientTest {
protected: protected:
// Override SetUp() to avoid parameterized setup // Override SetUp() to avoid parameterized setup
virtual void SetUp() { virtual void SetUp() {
current_accessor_ = createMockAccessor(); createClient(&mock_param);
is_mock_ = true;
client_.reset(new DatabaseClient(qclass_, current_accessor_));
} }
}; };
@@ -4315,29 +4317,29 @@ TEST_P(DatabaseClientTest, deleteZoneRollbackOnNotFind) {
EXPECT_TRUE(client_->deleteZone(zname_)); EXPECT_TRUE(client_->deleteZone(zname_));
} }
#if 0 // This test fixture is parameterized so that we can share (most of) the test
TEST_P_CASE(RRsetCollectionTest, TestAccessorTypes); // cases with different types of data sources.
class RRsetCollectionTest : public DatabaseClientTest {
protected:
RRsetCollectionTest() : collection(NULL) {}
// This test fixture is templated so that we can share (most of) the test virtual void SetUp() {
// cases with different types of data sources. Note that in test cases DatabaseClientTest::SetUp();
// we need to use 'this' to refer to member variables of the test class. updater = client_->getUpdater(zname_, false);
template <typename ACCESSOR_TYPE> collection = &updater->getRRsetCollection();
class RRsetCollectionTest : public DatabaseClientTest<ACCESSOR_TYPE> { }
public:
RRsetCollectionTest() :
DatabaseClientTest<ACCESSOR_TYPE>(),
updater(client_->getUpdater(zname_, false)),
collection(updater->getRRsetCollection())
{}
ZoneUpdaterPtr updater; ZoneUpdaterPtr updater;
isc::dns::RRsetCollectionBase& collection; isc::dns::RRsetCollectionBase* collection;
}; };
INSTANTIATE_TEST_CASE_P(, RRsetCollectionTest,
::testing::Values(&mock_param, &sqlite3_param));
TEST_P(RRsetCollectionTest, find) { TEST_P(RRsetCollectionTest, find) {
// Test the find() that returns ConstRRsetPtr // Test the find() that returns ConstRRsetPtr
ConstRRsetPtr rrset = collection.find(Name("www.example.org."), ConstRRsetPtr rrset = collection->find(Name("www.example.org."),
RRClass::IN(), RRType::A()); RRClass::IN(), RRType::A());
ASSERT_TRUE(rrset); ASSERT_TRUE(rrset);
EXPECT_EQ(RRType::A(), rrset->getType()); EXPECT_EQ(RRType::A(), rrset->getType());
EXPECT_EQ(RRTTL(3600), rrset->getTTL()); EXPECT_EQ(RRTTL(3600), rrset->getTTL());
@@ -4345,59 +4347,55 @@ TEST_P(RRsetCollectionTest, find) {
EXPECT_EQ(Name("www.example.org"), rrset->getName()); EXPECT_EQ(Name("www.example.org"), rrset->getName());
// foo.example.org doesn't exist // foo.example.org doesn't exist
rrset = collection.find(Name("foo.example.org"), qclass_, rrset = collection->find(Name("foo.example.org"), qclass_,
RRType::A()); RRType::A());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// www.example.org exists, but not with MX // www.example.org exists, but not with MX
rrset = collection.find(Name("www.example.org"), qclass_, rrset = collection->find(Name("www.example.org"), qclass_, RRType::MX());
RRType::MX());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// www.example.org exists, with AAAA // www.example.org exists, with AAAA
rrset = collection.find(Name("www.example.org"), qclass_, rrset = collection->find(Name("www.example.org"), qclass_, RRType::AAAA());
RRType::AAAA());
EXPECT_TRUE(rrset); EXPECT_TRUE(rrset);
// www.example.org with AAAA does not exist in RRClass::CH() // www.example.org with AAAA does not exist in RRClass::CH()
rrset = collection.find(Name("www.example.org"), RRClass::CH(), rrset = collection->find(Name("www.example.org"), RRClass::CH(),
RRType::AAAA()); RRType::AAAA());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// Out-of-zone find()s must not throw. // Out-of-zone find()s must not throw.
rrset = collection.find(Name("www.example.com"), qclass_, rrset = collection->find(Name("www.example.com"), qclass_, RRType::A());
RRType::A());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// "cname.example.org." with type CNAME should return the CNAME RRset // "cname.example.org." with type CNAME should return the CNAME RRset
rrset = collection.find(Name("cname.example.org"), qclass_, rrset = collection->find(Name("cname.example.org"), qclass_,
RRType::CNAME()); RRType::CNAME());
ASSERT_TRUE(rrset); ASSERT_TRUE(rrset);
EXPECT_EQ(RRType::CNAME(), rrset->getType()); EXPECT_EQ(RRType::CNAME(), rrset->getType());
EXPECT_EQ(Name("cname.example.org"), rrset->getName()); EXPECT_EQ(Name("cname.example.org"), rrset->getName());
// "cname.example.org." with type A should return nothing // "cname.example.org." with type A should return nothing
rrset = collection.find(Name("cname.example.org"), qclass_, rrset = collection->find(Name("cname.example.org"), qclass_, RRType::A());
RRType::A());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// "dname.example.org." with type DNAME should return the DNAME RRset // "dname.example.org." with type DNAME should return the DNAME RRset
rrset = collection.find(Name("dname.example.org"), qclass_, rrset = collection->find(Name("dname.example.org"), qclass_,
RRType::DNAME()); RRType::DNAME());
ASSERT_TRUE(rrset); ASSERT_TRUE(rrset);
EXPECT_EQ(RRType::DNAME(), rrset->getType()); EXPECT_EQ(RRType::DNAME(), rrset->getType());
EXPECT_EQ(Name("dname.example.org"), rrset->getName()); EXPECT_EQ(Name("dname.example.org"), rrset->getName());
// "below.dname.example.org." with type AAAA should return nothing // "below.dname.example.org." with type AAAA should return nothing
rrset = collection.find(Name("below.dname.example.org"), rrset = collection->find(Name("below.dname.example.org"),
qclass_, RRType::AAAA()); qclass_, RRType::AAAA());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// "below.dname.example.org." with type A does not return the record // "below.dname.example.org." with type A does not return the record
// (see top of file). See \c isc::datasrc::RRsetCollectionBase::find() // (see top of file). See \c isc::datasrc::RRsetCollectionBase::find()
// documentation for details. // documentation for details.
rrset = collection.find(Name("below.dname.example.org"), rrset = collection->find(Name("below.dname.example.org"), qclass_,
qclass_, RRType::A()); RRType::A());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// With the FIND_GLUE_OK option passed to ZoneFinder's find(), // With the FIND_GLUE_OK option passed to ZoneFinder's find(),
@@ -4405,8 +4403,8 @@ TEST_P(RRsetCollectionTest, find) {
// return the NS record. Without FIND_GLUE_OK, ZoneFinder's find() // return the NS record. Without FIND_GLUE_OK, ZoneFinder's find()
// would return DELEGATION and the find() below would return // would return DELEGATION and the find() below would return
// nothing. // nothing.
rrset = collection.find(Name("delegation.example.org"), rrset = collection->find(Name("delegation.example.org"), qclass_,
qclass_, RRType::NS()); RRType::NS());
ASSERT_TRUE(rrset); ASSERT_TRUE(rrset);
EXPECT_EQ(RRType::NS(), rrset->getType()); EXPECT_EQ(RRType::NS(), rrset->getType());
EXPECT_EQ(Name("delegation.example.org"), rrset->getName()); EXPECT_EQ(Name("delegation.example.org"), rrset->getName());
@@ -4415,14 +4413,14 @@ TEST_P(RRsetCollectionTest, find) {
// searching for some "foo.wildcard.example.org." would make // searching for some "foo.wildcard.example.org." would make
// ZoneFinder's find() return NXDOMAIN, and the find() below should // ZoneFinder's find() return NXDOMAIN, and the find() below should
// return nothing. // return nothing.
rrset = collection.find(Name("foo.wild.example.org"), rrset = collection->find(Name("foo.wild.example.org"), qclass_,
qclass_, RRType::A()); RRType::A());
EXPECT_FALSE(rrset); EXPECT_FALSE(rrset);
// Searching directly for "*.wild.example.org." should return the // Searching directly for "*.wild.example.org." should return the
// record. // record.
rrset = collection.find(Name("*.wild.example.org"), rrset = collection->find(Name("*.wild.example.org"), qclass_,
qclass_, RRType::A()); RRType::A());
ASSERT_TRUE(rrset); ASSERT_TRUE(rrset);
EXPECT_EQ(RRType::A(), rrset->getType()); EXPECT_EQ(RRType::A(), rrset->getType());
EXPECT_EQ(Name("*.wild.example.org"), rrset->getName()); EXPECT_EQ(Name("*.wild.example.org"), rrset->getName());
@@ -4430,11 +4428,21 @@ TEST_P(RRsetCollectionTest, find) {
TEST_P(RRsetCollectionTest, iteratorTest) { TEST_P(RRsetCollectionTest, iteratorTest) {
// Iterators are currently not implemented. // Iterators are currently not implemented.
EXPECT_THROW(collection.begin(), isc::NotImplemented); EXPECT_THROW(collection->begin(), isc::NotImplemented);
EXPECT_THROW(collection.end(), isc::NotImplemented); EXPECT_THROW(collection->end(), isc::NotImplemented);
} }
typedef RRsetCollectionTest<MockAccessor> MockRRsetCollectionTest; // This inherit the RRsetCollectionTest cases except for the parameterized
// setup; it's intended to be used selected test cases that only work for mock
// data sources.
class MockRRsetCollectionTest : public RRsetCollectionTest {
protected:
virtual void SetUp() {
createClient(&mock_param);
updater = client_->getUpdater(zname_, false);
collection = &updater->getRRsetCollection();
}
};
TEST_F(MockRRsetCollectionTest, findError) { TEST_F(MockRRsetCollectionTest, findError) {
// A test using the MockAccessor for checking that FindError is // A test using the MockAccessor for checking that FindError is
@@ -4444,27 +4452,26 @@ TEST_F(MockRRsetCollectionTest, findError) {
// The "dsexception.example.org." name is rigged by the MockAccessor // The "dsexception.example.org." name is rigged by the MockAccessor
// to throw a DataSourceError. // to throw a DataSourceError.
EXPECT_THROW({ EXPECT_THROW({
collection.find(Name("dsexception.example.org"), qclass_, collection->find(Name("dsexception.example.org"), qclass_,
RRType::A()); RRType::A());
}, RRsetCollectionError); }, RRsetCollectionError);
} }
TEST_P_CASE(RRsetCollectionAndUpdaterTest, TestAccessorTypes); // This test fixture is parameterized so that we can share (most of) the test
// cases with different types of data sources.
// This test fixture is templated so that we can share (most of) the test class RRsetCollectionAndUpdaterTest : public DatabaseClientTest {
// cases with different types of data sources. Note that in test cases protected:
// we need to use 'this' to refer to member variables of the test class. virtual void SetUp() {
template <typename ACCESSOR_TYPE> DatabaseClientTest::SetUp();
class RRsetCollectionAndUpdaterTest : public DatabaseClientTest<ACCESSOR_TYPE> { updater_ = client_->getUpdater(zname_, false);
public: }
RRsetCollectionAndUpdaterTest() :
DatabaseClientTest<ACCESSOR_TYPE>(),
updater_(client_->getUpdater(zname_, false))
{}
ZoneUpdaterPtr updater_; ZoneUpdaterPtr updater_;
}; };
INSTANTIATE_TEST_CASE_P(, RRsetCollectionAndUpdaterTest,
::testing::Values(&mock_param, &sqlite3_param));
// Test that using addRRset() or deleteRRset() on the ZoneUpdater throws // Test that using addRRset() or deleteRRset() on the ZoneUpdater throws
// after an RRsetCollection is created. // after an RRsetCollection is created.
TEST_P(RRsetCollectionAndUpdaterTest, updateThrows) { TEST_P(RRsetCollectionAndUpdaterTest, updateThrows) {
@@ -4486,8 +4493,7 @@ TEST_P(RRsetCollectionAndUpdaterTest, updateThrows) {
find(Name("www.example.org"), RRClass::IN(), RRType::MX())); find(Name("www.example.org"), RRClass::IN(), RRType::MX()));
// addRRset() must throw isc::InvalidOperation here. // addRRset() must throw isc::InvalidOperation here.
EXPECT_THROW(updater_->addRRset(*rrset_), EXPECT_THROW(updater_->addRRset(*rrset_), isc::InvalidOperation);
isc::InvalidOperation);
// 2. Deletion test // 2. Deletion test
@@ -4505,12 +4511,10 @@ TEST_P(RRsetCollectionAndUpdaterTest, updateThrows) {
// Just call getRRsetCollection() here. The .find() is unnecessary, // Just call getRRsetCollection() here. The .find() is unnecessary,
// but we have it to use the result of getRRsetCollection(). // but we have it to use the result of getRRsetCollection().
updater_->getRRsetCollection().find(Name("www.example.org"), updater_->getRRsetCollection().find(Name("www.example.org"),
RRClass::IN(), RRClass::IN(), RRType::MX());
RRType::MX());
// deleteRRset() must throw isc::InvalidOperation here. // deleteRRset() must throw isc::InvalidOperation here.
EXPECT_THROW(updater_->deleteRRset(*rrset_), EXPECT_THROW(updater_->deleteRRset(*rrset_), isc::InvalidOperation);
isc::InvalidOperation);
} }
// Test that using an RRsetCollection after calling commit() on the // Test that using an RRsetCollection after calling commit() on the
@@ -4526,10 +4530,8 @@ TEST_P(RRsetCollectionAndUpdaterTest, useAfterCommitThrows) {
// find() must throw RRsetCollectionError here, as the // find() must throw RRsetCollectionError here, as the
// RRsetCollection is disabled. // RRsetCollection is disabled.
EXPECT_THROW(collection.find(Name("foo.wild.example.org"), EXPECT_THROW(collection.find(Name("foo.wild.example.org"), qclass_,
qclass_, RRType::A()), RRType::A()), RRsetCollectionError);
RRsetCollectionError);
} }
#endif // 0
} }