From: Michal 'vorner' Vaner Date: Mon, 4 Jun 2012 14:36:51 +0000 (+0200) Subject: [1975] Tests for container of one data source X-Git-Tag: trac2351_base~97^2~9^2~4^2~20 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d95ff3f155636aa484dbba780ed5264335387905;p=thirdparty%2Fkea.git [1975] Tests for container of one data source Checks it can find zones if there's only one data source inside. Caches are not considered yet at all. The fake data source needs some implementation. --- diff --git a/src/lib/datasrc/container.h b/src/lib/datasrc/container.h index e19bbcaca2..d612e1ffd1 100644 --- a/src/lib/datasrc/container.h +++ b/src/lib/datasrc/container.h @@ -208,7 +208,9 @@ public: /// \brief This holds one data source and corresponding information. /// /// \todo The content yet to be defined. - struct DataSourceInfo {}; + struct DataSourceInfo { + DataSourceClientPtr data_src_; + }; /// \brief The collection of data sources. typedef std::vector DataSources; protected: diff --git a/src/lib/datasrc/tests/container_unittest.cc b/src/lib/datasrc/tests/container_unittest.cc index da03adfa45..5131f14da3 100644 --- a/src/lib/datasrc/tests/container_unittest.cc +++ b/src/lib/datasrc/tests/container_unittest.cc @@ -13,13 +13,17 @@ // PERFORMANCE OF THIS SOFTWARE. #include +#include #include +#include + using namespace isc::datasrc; using namespace isc::data; using namespace isc::dns; using namespace boost; +using namespace std; namespace { @@ -31,6 +35,37 @@ public: bool allow_cache) : ConfigurableContainer(configuration, allow_cache) { } + DataSources& dataSources() { return (data_sources_); } +}; + +// A test data source. It pretends it has some zones. +class TestDS : public DataSourceClient { +public: + TestDS(const char* zone_names[]) { + for (const char** zone(zone_names); *zone; ++ zone) { + zones.insert(Name(*zone)); + } + } + virtual FindResult findZone(const Name& ) const { + isc_throw(isc::NotImplemented, "Not implemented"); + } + // These methods are not used. They just need to be there to have + // complete vtable. + virtual ZoneUpdaterPtr getUpdater(const Name&, bool, bool) const { + isc_throw(isc::NotImplemented, "Not implemented"); + } + virtual pair + getJournalReader(const Name&, uint32_t, uint32_t) const + { + isc_throw(isc::NotImplemented, "Not implemented"); + } +private: + set zones; +}; + +const char* ds1_zones[] = { + "example.org.", + "example.com." }; class ContainerTest : public ::testing::Test { @@ -38,9 +73,15 @@ public: ContainerTest() : // The empty list corresponds to a container with no elements inside container_(new TestedContainer(ConstElementPtr(new ListElement()), - true)) - { } + true)), + ds1_(new TestDS(ds1_zones)) + { + ds1_info_.data_src_ = ds1_; + } shared_ptr container_; + const Container::SearchResult negativeResult_; + shared_ptr ds1_; + ConfigurableContainer::DataSourceInfo ds1_info_; }; // Test the container we create with empty configuration is, in fact, empty @@ -52,16 +93,59 @@ TEST_F(ContainerTest, emptyContainer) { // a negative answer (nothing found) no matter if we want an exact or inexact // match. TEST_F(ContainerTest, emptySearch) { - Container::SearchResult negativeResult; // No matter what we try, we don't get an answer. - EXPECT_EQ(negativeResult, container_->search(Name("example.org"), false, + EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), false, false)); - EXPECT_EQ(negativeResult, container_->search(Name("example.org"), false, + EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), false, true)); - EXPECT_EQ(negativeResult, container_->search(Name("example.org"), true, + EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), true, false)); - EXPECT_EQ(negativeResult, container_->search(Name("example.org"), true, + EXPECT_EQ(negativeResult_, container_->search(Name("example.org"), true, true)); } +// Put a single data source inside the container and check it can find an +// exact match if there's one. +TEST_F(ContainerTest, singleDSExactMatch) { + container_->dataSources().push_back(ds1_info_); + // This zone is not there + EXPECT_EQ(negativeResult_, container_->search(Name("org."), true)); + // But this one is, so check it. + const Container::SearchResult + result(container_->search(Name("example.org"), true)); + EXPECT_EQ(ds1_, result.datasrc_); + ASSERT_NE(ZoneFinderPtr(), result.finder_); + EXPECT_EQ(Name("example.org"), result.finder_->getOrigin()); + EXPECT_EQ(2, result.matched_labels_); + EXPECT_TRUE(result.exact_match_); + // When asking for a sub zone of a zone there, we get nothing + // (we want exact match, this would be partial one) + EXPECT_EQ(negativeResult_, container_->search(Name("sub.example.org."), + true)); +} + +// When asking for a partial match, we get all that the exact one, but more. +TEST_F(ContainerTest, singleDSBestMatch) { + container_->dataSources().push_back(ds1_info_); + // This zone is not there + EXPECT_EQ(negativeResult_, container_->search(Name("org."))); + // But this one is, so check it. + const Container::SearchResult + result(container_->search(Name("example.org"))); + EXPECT_EQ(ds1_, result.datasrc_); + ASSERT_NE(ZoneFinderPtr(), result.finder_); + EXPECT_EQ(Name("example.org"), result.finder_->getOrigin()); + EXPECT_EQ(2, result.matched_labels_); + EXPECT_TRUE(result.exact_match_); + // When asking for a sub zone of a zone there, we get nothing + // (we want exact match, this would be partial one) + const Container::SearchResult + partialResult(container_->search(Name("sub.example.org."))); + EXPECT_EQ(ds1_, partialResult.datasrc_); + ASSERT_NE(ZoneFinderPtr(), partialResult.finder_); + EXPECT_EQ(Name("example.org"), partialResult.finder_->getOrigin()); + EXPECT_EQ(2, partialResult.matched_labels_); + EXPECT_FALSE(partialResult.exact_match_); +} + }