BIND 10 trac1975, updated. 07d1252a747959053f499d03e40e590c21ea0bd5 [1975] Extend a test
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Jun 12 12:45:30 UTC 2012
The branch, trac1975 has been updated
via 07d1252a747959053f499d03e40e590c21ea0bd5 (commit)
via 4cd359475e5426fca0393246badb07ea686e3283 (commit)
via 3800f59cbac8ac2c3adff1387485d2bf4de0f369 (commit)
via 8479ff275b5a09dd94c8c9311219c0385ff685f8 (commit)
via d6b2edc832ea90d2470e953a7b4e034c795ff303 (commit)
via 950d0e317681530727eab631b830280e4890eb96 (commit)
via 29ce263555c5e12a0357fd4bc8b57d5eab070610 (commit)
via c4c3340828ab1232f95562217ca1f98044c20273 (commit)
via 6adafccee8a94c34a4d542a2e42fce0a861dbf40 (commit)
via eb9d328b4bb20f8fe04771e20b045827eb3a8667 (commit)
via abf827ef79067d74865bc4e6da349788e71fca7d (commit)
via a11c2a4ee291fe85a64c059cc94622c05de3c2fa (commit)
via a64c77257ca5c110e408f846286da909e8548b9c (commit)
from 88cbe7028f70266945fe6b53a46e235b4c9eca83 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 07d1252a747959053f499d03e40e590c21ea0bd5
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 14:40:12 2012 +0200
[1975] Extend a test
See that a valid part of invalid configuration is not included.
commit 4cd359475e5426fca0393246badb07ea686e3283
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 14:31:14 2012 +0200
[1975] Style, comments, details
commit 3800f59cbac8ac2c3adff1387485d2bf4de0f369
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 14:28:55 2012 +0200
[1975] Make sure we handle set::iterator correctly
There was a possible problem in mock data source with decreasing a
begin() iterator.
commit 8479ff275b5a09dd94c8c9311219c0385ff685f8
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 14:08:25 2012 +0200
[1975] Rename TestDS -> MockDataSourceClient
commit d6b2edc832ea90d2470e953a7b4e034c795ff303
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:55:16 2012 +0200
[1975] Style
commit 950d0e317681530727eab631b830280e4890eb96
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:47:44 2012 +0200
[1975] Spelling
commit 29ce263555c5e12a0357fd4bc8b57d5eab070610
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:46:44 2012 +0200
[1975] Rename dataSources() to getDataSources()
To fit our naming conventions better.
commit c4c3340828ab1232f95562217ca1f98044c20273
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:45:12 2012 +0200
[1975] Create constructor for DataSourceInfo
commit 6adafccee8a94c34a4d542a2e42fce0a861dbf40
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:26:43 2012 +0200
[1975] Docs: Lifetime and ownership of a pointer
commit eb9d328b4bb20f8fe04771e20b045827eb3a8667
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:24:22 2012 +0200
[1975] Rename search -> find
To have better naming consistency.
commit abf827ef79067d74865bc4e6da349788e71fca7d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:17:43 2012 +0200
[1975] Use reference instead of pointer
As the pointer should never be NULL anyway, it might be better to pass
reference.
commit a11c2a4ee291fe85a64c059cc94622c05de3c2fa
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:13:44 2012 +0200
[1975] Docs: It is for single class only
commit a64c77257ca5c110e408f846286da909e8548b9c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Jun 12 13:06:49 2012 +0200
[1975] Comment about inheriting the ConfigurableContainer
Saying that it should not be done. The data_sources_ variable should be
considered private.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/container.cc | 33 +++--
src/lib/datasrc/container.h | 79 +++++++-----
src/lib/datasrc/tests/container_unittest.cc | 181 ++++++++++++++-------------
3 files changed, 161 insertions(+), 132 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/container.cc b/src/lib/datasrc/container.cc
index 6e0d332..6b73fb1 100644
--- a/src/lib/datasrc/container.cc
+++ b/src/lib/datasrc/container.cc
@@ -26,15 +26,15 @@ namespace isc {
namespace datasrc {
void
-ConfigurableContainer::configure(const ConstElementPtr& config, bool) {
+ConfigurableContainer::configure(const Element& config, bool) {
// TODO: Implement the cache
- // TODO: Implement recyclation from the old configuration.
+ // TODO: Implement recycling from the old configuration.
size_t i(0); // Outside of the try to be able to access it in the catch
try {
vector<DataSourceInfo> new_data_sources;
- for (; i < config->size(); ++i) {
+ for (; i < config.size(); ++i) {
// Extract the parameters
- const ConstElementPtr dconf(config->get(i));
+ const ConstElementPtr dconf(config.get(i));
const ConstElementPtr typeElem(dconf->get("type"));
if (typeElem == ConstElementPtr()) {
isc_throw(ConfigurationError, "Missing the type option in "
@@ -49,10 +49,7 @@ ConfigurableContainer::configure(const ConstElementPtr& config, bool) {
// Ask the factory to create the data source for us
const DataSourcePair ds(this->getDataSource(type, paramConf));
// And put it into the vector
- DataSourceInfo info;
- info.data_src_ = ds.first;
- info.container_ = ds.second;
- new_data_sources.push_back(info);
+ new_data_sources.push_back(DataSourceInfo(ds.first, ds.second));
}
// If everything is OK up until now, we have the new configuration
// ready. So just put it there and let the old one die when we exit
@@ -64,13 +61,13 @@ ConfigurableContainer::configure(const ConstElementPtr& config, bool) {
}
}
-Container::SearchResult
-ConfigurableContainer::search(const dns::Name& name, bool want_exact_match,
- bool) const
+Container::FindResult
+ConfigurableContainer::find(const dns::Name& name, bool want_exact_match,
+ bool) const
{
// Nothing found yet.
- // Pointer is used as the SearchResult can't be assigned.
- auto_ptr<SearchResult> candidate(new SearchResult());
+ // Pointer is used as the FindResult can't be assigned.
+ auto_ptr<FindResult> candidate(new FindResult());
BOOST_FOREACH(const DataSourceInfo& info, data_sources_) {
// TODO: Once we have support for the caches, consider them too here
@@ -88,7 +85,7 @@ ConfigurableContainer::search(const dns::Name& name, bool want_exact_match,
// TODO: In case we have only the datasource and not the finder
// and the need_updater parameter is true, get the zone there.
- return (SearchResult(info.data_src_, result.zone_finder,
+ return (FindResult(info.data_src_, result.zone_finder,
name.getLabelCount(), true));
}
case result::PARTIALMATCH: {
@@ -99,9 +96,9 @@ ConfigurableContainer::search(const dns::Name& name, bool want_exact_match,
result.zone_finder->getOrigin().getLabelCount());
if (labels > candidate->matched_labels_) {
// This one is strictly better. Replace it.
- candidate.reset(new SearchResult(info.data_src_,
- result.zone_finder,
- labels, false));
+ candidate.reset(new FindResult(info.data_src_,
+ result.zone_finder,
+ labels, false));
}
}
break;
@@ -126,7 +123,7 @@ ConfigurableContainer::search(const dns::Name& name, bool want_exact_match,
// replace the call to DataSourceClientContainer constructor in tests.
ConfigurableContainer::DataSourcePair
ConfigurableContainer::getDataSource(const string& type,
- const ::ConstElementPtr& configuration)
+ const ConstElementPtr& configuration)
{
DataSourceClientContainerPtr
container(new DataSourceClientContainer(type, configuration));
diff --git a/src/lib/datasrc/container.h b/src/lib/datasrc/container.h
index f8792e4..2831a39 100644
--- a/src/lib/datasrc/container.h
+++ b/src/lib/datasrc/container.h
@@ -39,6 +39,9 @@ typedef boost::shared_ptr<DataSourceClientContainer>
/// The purpose of this class is to hold several data sources and search
/// through them to find one containing a zone best matching a request.
///
+/// All the data source clients should be for the same class. If you need
+/// to handle multiple classes, you need to create multiple separate containers.
+///
/// This is an abstract base class. It is not expected we would use multiple
/// implementation inside the servers (but it is not forbidden either), we
/// have it to allow easy testing. It is possible to create a mock-up class
@@ -52,19 +55,19 @@ protected:
/// class.
Container() {}
public:
- /// \brief Structure holding the (compound) result of search.
+ /// \brief Structure holding the (compound) result of find.
///
/// As this is read-only structure, we don't bother to create accessors.
/// Instead, all the member variables are defined as const and can be
/// accessed directly.
- struct SearchResult {
+ struct FindResult {
/// \brief Constructor.
///
/// It simply fills in the member variables according to the
/// parameters. See the member descriptions for their meaning.
- SearchResult(DataSourceClient* datasrc,
- const ZoneFinderPtr& finder,
- uint8_t matched_labels, bool exact_match) :
+ FindResult(DataSourceClient* datasrc,
+ const ZoneFinderPtr& finder,
+ uint8_t matched_labels, bool exact_match) :
datasrc_(datasrc),
finder_(finder),
matched_labels_(matched_labels),
@@ -75,7 +78,7 @@ public:
///
/// This conscructs a result for negative answer. Both pointers are
/// NULL, matched_labels_ is 0 and exact_match_ is false.
- SearchResult() :
+ FindResult() :
datasrc_(NULL),
matched_labels_(0),
exact_match_(false)
@@ -85,7 +88,7 @@ public:
///
/// It is needed for tests and it might be of some use elsewhere
/// too.
- bool operator ==(const SearchResult& other) const {
+ bool operator ==(const FindResult& other) const {
return (datasrc_ == other.datasrc_ &&
finder_ == other.finder_ &&
matched_labels_ == other.matched_labels_ &&
@@ -96,15 +99,19 @@ public:
///
/// The data source containing the best matching zone. If no such
/// data source exists, this is NULL pointer.
+ ///
+ /// Note that the pointer is valid only as long the Container which
+ /// returned is alive and was not reconfigured. The ownership is
+ /// preserved within the Container.
DataSourceClient* const datasrc_;
/// \brief The finder for the requested zone.
///
/// This is the finder corresponding to the best matching zone.
/// This may be NULL even in case the datasrc_ is something
- /// else, depending on the search options.
+ /// else, depending on the find options.
///
- /// \see search
+ /// \see find
const ZoneFinderPtr finder_;
/// \brief Number of matching labels.
@@ -126,7 +133,7 @@ public:
/// this case, the zone finder is needed and the best matching superzone
/// of the searched name is needed. Therefore, the call would look like:
///
- /// SearchResult result(container->search(queried_name));
+ /// FindResult result(container->find(queried_name));
/// if (result.datasrc_) {
/// createTheAnswer(result.finder_);
/// } else {
@@ -138,20 +145,20 @@ public:
/// we need an exact match (if we want to manipulate zone data, we must
/// know exactly, which zone we are about to manipulate). Then the call
///
- /// SearchResult result(container->search(zone_name, true, false));
+ /// FindResult result(container->find(zone_name, true, false));
/// if (result.datasrc_) {
/// ZoneUpdaterPtr updater(result.datasrc_->getUpdater(zone_name);
/// ...
/// }
///
- /// \param zone The name of the zone to search.
+ /// \param zone The name of the zone to look for.
/// \param want_exact_match If it is true, it returns only exact matches.
/// If the best possible match is partial, a negative result is
/// returned instead. It is possible the caller could check it and
/// act accordingly if the result would be partial match, but with this
- /// set to true, the search might be actually faster under some
+ /// set to true, the find might be actually faster under some
/// circumstances.
- /// \param want_finder If this is false, the finder_ member of SearchResult
+ /// \param want_finder If this is false, the finder_ member of FindResult
/// might be NULL even if the corresponding data source is found. This
/// is because of performance, in some cases the finder is a side
/// result of the searching algorithm (therefore asking for it again
@@ -161,11 +168,11 @@ public:
/// Other things are never the side effect of searching, therefore the
/// caller can get them explicitly (the updater, journal reader and
/// iterator).
- /// \return A SearchResult describing the data source and zone with the
+ /// \return A FindResult describing the data source and zone with the
/// longest match against the zone parameter.
- virtual SearchResult search(const dns::Name& zone,
- bool want_exact_match = false,
- bool want_finder = true) const = 0;
+ virtual FindResult find(const dns::Name& zone,
+ bool want_exact_match = false,
+ bool want_finder = true) const = 0;
};
/// \brief Shared pointer to the container.
@@ -179,6 +186,9 @@ typedef boost::shared_ptr<const Container> ConstContainerPtr;
/// This is the implementation which is expected to be used in the servers.
/// However, it is expected most of the code will use it as the Container,
/// only the creation is expected to be direct.
+///
+/// While it is possible to inherit this class, it is not expected to be
+/// inherited except for tests.
class ConfigurableContainer : public Container {
public:
/// \brief Exception thrown when there's an error in configuration.
@@ -207,18 +217,29 @@ public:
/// \throw DataSourceError if there's a problem creating a data source.
/// \throw ConfigurationError if the configuration is invalid in some
/// sense.
- void configure(const data::ConstElementPtr& configuration,
- bool allow_cache);
+ void configure(const data::Element& configuration, bool allow_cache);
- /// \brief Implementation of the Container::search.
- virtual SearchResult search(const dns::Name& zone,
- bool want_exact_match = false,
- bool want_finder = true) const;
+ /// \brief Implementation of the Container::find.
+ virtual FindResult find(const dns::Name& zone,
+ bool want_exact_match = false,
+ bool want_finder = true) const;
/// \brief This holds one data source and corresponding information.
///
/// \todo The content yet to be defined.
struct DataSourceInfo {
+ /// \brief Default constructor.
+ ///
+ /// Don't use directly. It is here so the structure can live in
+ /// a vector.
+ DataSourceInfo() :
+ data_src_(NULL)
+ {}
+ DataSourceInfo(DataSourceClient* data_src,
+ const DataSourceClientContainerPtr& container) :
+ data_src_(data_src),
+ container_(container)
+ { }
DataSourceClient* data_src_;
DataSourceClientContainerPtr container_;
};
@@ -229,7 +250,8 @@ protected:
/// \brief The data sources held here.
///
/// All our data sources are stored here. It is protected to let the
- /// tests in.
+ /// tests in. You should consider it private if you ever want to
+ /// derive this class (which is not really recommended anyway).
DataSources data_sources_;
/// \brief Convenience type alias.
@@ -243,8 +265,9 @@ protected:
/// This is a thin wrapper around the DataSourceClientContainer
/// constructor. The function is here to make it possible for tests
/// to replace the DataSourceClientContainer with something else.
- /// Also, derived classes might want to create the data sources
- /// in a different way.
+ /// Also, derived classes couldl want to create the data sources
+ /// in a different way, though inheriting this class is not
+ /// recommended.
///
/// The parameters are the same as of the constructor.
/// \return Pair containing both the data source and the container.
@@ -262,7 +285,7 @@ public:
/// It can be used to examine the loaded list of data sources directly.
/// It is not known if it is of any use other than testing, but it might
/// be, so it is just made public.
- const DataSources& dataSources() const { return (data_sources_); }
+ const DataSources& getDataSources() const { return (data_sources_); }
};
} // namespace datasrc
diff --git a/src/lib/datasrc/tests/container_unittest.cc b/src/lib/datasrc/tests/container_unittest.cc
index a4aec1c..73d46c7 100644
--- a/src/lib/datasrc/tests/container_unittest.cc
+++ b/src/lib/datasrc/tests/container_unittest.cc
@@ -31,7 +31,7 @@ using namespace std;
namespace {
// A test data source. It pretends it has some zones.
-class TestDS : public DataSourceClient {
+class MockDataSourceClient : public DataSourceClient {
public:
class Finder : public ZoneFinder {
public:
@@ -64,14 +64,15 @@ public:
Name origin_;
};
// Constructor from a list of zones.
- TestDS(const char* zone_names[]) {
+ MockDataSourceClient(const char* zone_names[]) {
for (const char** zone(zone_names); *zone; ++ zone) {
zones.insert(Name(*zone));
}
}
// Constructor from configuration. The list of zones will be empty, but
// it will keep the configuration inside for further inspection.
- TestDS(const string& type, const ConstElementPtr& configuration) :
+ MockDataSourceClient(const string& type,
+ const ConstElementPtr& configuration) :
type_(type),
configuration_(configuration)
{ }
@@ -80,6 +81,9 @@ public:
return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
}
set<Name>::const_iterator it(zones.upper_bound(name));
+ if (it == zones.begin()) {
+ return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
+ }
-- it;
NameComparisonResult compar(it->compare(name));
const ZoneFinderPtr finder(new Finder(*it));
@@ -113,7 +117,7 @@ private:
// some methods to dig directly in the internals, for the tests.
class TestedContainer : public ConfigurableContainer {
public:
- DataSources& dataSources() { return (data_sources_); }
+ DataSources& getDataSources() { return (data_sources_); }
// Overwrite the containers method to get a data source with given type
// and configuration. We mock the data source and don't create the
// container. This is just to avoid some complexity in the tests.
@@ -123,7 +127,8 @@ public:
if (type == "error") {
isc_throw(DataSourceError, "The error data source type");
}
- shared_ptr<TestDS> ds(new TestDS(type, configuration));
+ shared_ptr<MockDataSourceClient>
+ ds(new MockDataSourceClient(type, configuration));
// Make sure it is deleted when the test container is deleted.
to_delete_.push_back(ds);
return (DataSourcePair(ds.get(), DataSourceClientContainerPtr()));
@@ -131,11 +136,10 @@ public:
private:
// Hold list of data sources created internally, so they are preserved
// until the end of the test and then deleted.
- vector<shared_ptr<TestDS> > to_delete_;
+ vector<shared_ptr<MockDataSourceClient> > to_delete_;
};
-const size_t ds_count = 4;
-const char* ds_zones[ds_count][3] = {
+const char* ds_zones[][3] = {
{
"example.org.",
"example.com.",
@@ -154,6 +158,8 @@ const char* ds_zones[ds_count][3] = {
}
};
+const size_t ds_count = (sizeof (ds_zones) / sizeof (*ds_zones));
+
class ContainerTest : public ::testing::Test {
public:
ContainerTest() :
@@ -167,16 +173,16 @@ public:
"}]"))
{
for (size_t i(0); i < ds_count; ++ i) {
- shared_ptr<TestDS> ds(new TestDS(ds_zones[i]));
- ConfigurableContainer::DataSourceInfo info;
- info.data_src_ = ds.get();
+ shared_ptr<MockDataSourceClient>
+ ds(new MockDataSourceClient(ds_zones[i]));
ds_.push_back(ds);
- ds_info_.push_back(info);
+ ds_info_.push_back(ConfigurableContainer::DataSourceInfo(ds.get(),
+ DataSourceClientContainerPtr()));
}
}
// Check the positive result is as we expect it.
- void positiveResult(const Container::SearchResult& result,
- const shared_ptr<TestDS>& dsrc,
+ void positiveResult(const Container::FindResult& result,
+ const shared_ptr<MockDataSourceClient>& dsrc,
const Name& name, bool exact,
const char* test)
{
@@ -191,44 +197,44 @@ public:
// some configuration. It uses the index as parameter, to be able to
// loop through the configurations.
void multiConfiguration(size_t index) {
- container_->dataSources().clear();
+ container_->getDataSources().clear();
switch (index) {
case 2:
- container_->dataSources().push_back(ds_info_[2]);
- // The ds3 is empty. We just check that it doesn't confuse
+ container_->getDataSources().push_back(ds_info_[2]);
+ // The ds_[2] is empty. We just check that it doesn't confuse
// us. Fall through to the case 0.
case 0:
- container_->dataSources().push_back(ds_info_[0]);
- container_->dataSources().push_back(ds_info_[1]);
+ container_->getDataSources().push_back(ds_info_[0]);
+ container_->getDataSources().push_back(ds_info_[1]);
break;
case 1:
// The other order
- container_->dataSources().push_back(ds_info_[1]);
- container_->dataSources().push_back(ds_info_[0]);
+ container_->getDataSources().push_back(ds_info_[1]);
+ container_->getDataSources().push_back(ds_info_[0]);
break;
case 3:
- container_->dataSources().push_back(ds_info_[1]);
- container_->dataSources().push_back(ds_info_[0]);
- // It is the same as 2, but we take from the first one.
+ container_->getDataSources().push_back(ds_info_[1]);
+ container_->getDataSources().push_back(ds_info_[0]);
+ // It is the same as ds_[1], but we take from the first one.
// The first one to match is the correct one.
- container_->dataSources().push_back(ds_info_[3]);
+ container_->getDataSources().push_back(ds_info_[3]);
break;
default:
FAIL() << "Unknown configuration index " << index;
}
}
void checkDS(size_t index, const string& type, const string& params) {
- ASSERT_GT(container_->dataSources().size(), index);
- TestDS* ds(dynamic_cast<TestDS*>(
- container_->dataSources()[index].data_src_));
+ ASSERT_GT(container_->getDataSources().size(), index);
+ MockDataSourceClient* ds(dynamic_cast<MockDataSourceClient*>(
+ container_->getDataSources()[index].data_src_));
// Comparing with NULL does not work
- ASSERT_TRUE(ds);
+ ASSERT_NE(ds, static_cast<const MockDataSourceClient*>(NULL));
EXPECT_EQ(type, ds->type_);
EXPECT_TRUE(Element::fromJSON(params)->equals(*ds->configuration_));
}
shared_ptr<TestedContainer> container_;
- const Container::SearchResult negativeResult_;
- vector<shared_ptr<TestDS> > ds_;
+ const Container::FindResult negativeResult_;
+ vector<shared_ptr<MockDataSourceClient> > ds_;
vector<ConfigurableContainer::DataSourceInfo> ds_info_;
const ConstElementPtr config_elem_;
};
@@ -240,14 +246,16 @@ TEST_F(ContainerTest, selfTest) {
ds_[0]->findZone(Name("sub.example.org")).code);
EXPECT_EQ(result::NOTFOUND, ds_[0]->findZone(Name("org")).code);
EXPECT_EQ(result::NOTFOUND, ds_[1]->findZone(Name("example.org")).code);
+ EXPECT_EQ(result::NOTFOUND, ds_[0]->findZone(Name("aaa")).code);
+ EXPECT_EQ(result::NOTFOUND, ds_[0]->findZone(Name("zzz")).code);
}
// Test the container we create with empty configuration is, in fact, empty
TEST_F(ContainerTest, emptyContainer) {
- EXPECT_TRUE(container_->dataSources().empty());
+ EXPECT_TRUE(container_->getDataSources().empty());
}
-// Check the values returned by a search on an empty container. It should be
+// Check the values returned by a find on an empty container. It should be
// a negative answer (nothing found) no matter if we want an exact or inexact
// match.
TEST_F(ContainerTest, emptySearch) {
@@ -255,42 +263,42 @@ TEST_F(ContainerTest, emptySearch) {
// Note: we don't have operator<< for the result class, so we cannot use
// EXPECT_EQ. Same for other similar cases.
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"),
- false, false));
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"),
- false, true));
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"), true,
- false));
- EXPECT_TRUE(negativeResult_ == container_->search(Name("example.org"), true,
- true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"),
+ false, false));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"),
+ false, true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("example.org"), true,
+ false));
+ EXPECT_TRUE(negativeResult_ == container_->find(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(ds_info_[0]);
+ container_->getDataSources().push_back(ds_info_[0]);
// This zone is not there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org."), true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org."), true));
// But this one is, so check it.
- positiveResult(container_->search(Name("example.org"), true),
+ positiveResult(container_->find(Name("example.org"), true),
ds_[0], Name("example.org"), true, "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_TRUE(negativeResult_ == container_->search(Name("sub.example.org."),
- true));
+ EXPECT_TRUE(negativeResult_ == container_->find(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(ds_info_[0]);
+ container_->getDataSources().push_back(ds_info_[0]);
// This zone is not there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org.")));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org.")));
// But this one is, so check it.
- positiveResult(container_->search(Name("example.org")),
+ positiveResult(container_->find(Name("example.org")),
ds_[0], Name("example.org"), true, "Exact match");
- // When asking for a sub zone of a zone there, we get nothing
- // (we want exact match, this would be partial one)
- positiveResult(container_->search(Name("sub.example.org.")),
+ // When asking for a sub zone of a zone there, we get the parent
+ // one.
+ positiveResult(container_->find(Name("sub.example.org.")),
ds_[0], Name("example.org"), false, "Subdomain match");
}
@@ -303,21 +311,21 @@ const char* test_names[] = {
TEST_F(ContainerTest, multiExactMatch) {
// Run through all the multi-configurations
- for (size_t i(0); i < 4; ++ i) {
+ for (size_t i(0); i < sizeof(test_names) / sizeof(*test_names); ++ i) {
SCOPED_TRACE(test_names[i]);
multiConfiguration(i);
// Something that is nowhere there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org."), true));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org."), true));
// This one is there exactly.
- positiveResult(container_->search(Name("example.org"), true),
+ positiveResult(container_->find(Name("example.org"), true),
ds_[0], Name("example.org"), true, "Exact match");
// This one too, but in a different data source.
- positiveResult(container_->search(Name("sub.example.org."), true),
+ positiveResult(container_->find(Name("sub.example.org."), true),
ds_[1], Name("sub.example.org"), true,
"Subdomain match");
// But this one is in neither data source.
EXPECT_TRUE(negativeResult_ ==
- container_->search(Name("sub.example.com."), true));
+ container_->find(Name("sub.example.com."), true));
}
}
@@ -327,17 +335,17 @@ TEST_F(ContainerTest, multiBestMatch) {
SCOPED_TRACE(test_names[i]);
multiConfiguration(i);
// Something that is nowhere there
- EXPECT_TRUE(negativeResult_ == container_->search(Name("org.")));
+ EXPECT_TRUE(negativeResult_ == container_->find(Name("org.")));
// This one is there exactly.
- positiveResult(container_->search(Name("example.org")),
+ positiveResult(container_->find(Name("example.org")),
ds_[0], Name("example.org"), true, "Exact match");
// This one too, but in a different data source.
- positiveResult(container_->search(Name("sub.example.org.")),
+ positiveResult(container_->find(Name("sub.example.org.")),
ds_[1], Name("sub.example.org"), true,
"Subdomain match");
// But this one is in neither data source. But it is a subdomain
// of one of the zones in the first data source.
- positiveResult(container_->search(Name("sub.example.com.")),
+ positiveResult(container_->find(Name("sub.example.com.")),
ds_[0], Name("example.com."), false,
"Subdomain in com");
}
@@ -346,8 +354,8 @@ TEST_F(ContainerTest, multiBestMatch) {
// Check the configuration is empty when the list is empty
TEST_F(ContainerTest, configureEmpty) {
ConstElementPtr elem(new ListElement);
- container_->configure(elem, true);
- EXPECT_TRUE(container_->dataSources().empty());
+ container_->configure(*elem, true);
+ EXPECT_TRUE(container_->getDataSources().empty());
}
// Check we can get multiple data sources and they are in the right order.
@@ -364,8 +372,8 @@ TEST_F(ContainerTest, configureMulti) {
" \"params\": {}"
"}]"
));
- container_->configure(elem, true);
- EXPECT_EQ(2, container_->dataSources().size());
+ container_->configure(*elem, true);
+ EXPECT_EQ(2, container_->getDataSources().size());
checkDS(0, "type1", "{}");
checkDS(1, "type2", "{}");
}
@@ -390,8 +398,8 @@ TEST_F(ContainerTest, configureParams) {
" \"cache\": \"off\","
" \"params\": ") + *param +
"}]"));
- container_->configure(elem, true);
- EXPECT_EQ(1, container_->dataSources().size());
+ container_->configure(*elem, true);
+ EXPECT_EQ(1, container_->getDataSources().size());
checkDS(0, "t", *param);
}
}
@@ -399,34 +407,35 @@ TEST_F(ContainerTest, configureParams) {
TEST_F(ContainerTest, wrongConfig) {
const char* configs[] = {
// A lot of stuff missing from there
- "[{}]",
+ "[{\"type\": \"test_type\", \"params\": 13}, {}]",
// Some bad types completely
"{}",
"true",
"42",
"null",
- "[true]",
- "[[]]",
- "[42]",
+ "[{\"type\": \"test_type\", \"params\": 13}, true]",
+ "[{\"type\": \"test_type\", \"params\": 13}, []]",
+ "[{\"type\": \"test_type\", \"params\": 13}, 42]",
// Bad type of type
- "[{\"type\": 42}]",
- "[{\"type\": true}]",
- "[{\"type\": null}]",
- "[{\"type\": []}]",
- "[{\"type\": {}}]",
+ "[{\"type\": \"test_type\", \"params\": 13}, {\"type\": 42}]",
+ "[{\"type\": \"test_type\", \"params\": 13}, {\"type\": true}]",
+ "[{\"type\": \"test_type\", \"params\": 13}, {\"type\": null}]",
+ "[{\"type\": \"test_type\", \"params\": 13}, {\"type\": []}]",
+ "[{\"type\": \"test_type\", \"params\": 13}, {\"type\": {}}]",
// TODO: Once cache is supported, add some invalid cache values
NULL
};
// Put something inside to see it survives the exception
- container_->configure(config_elem_, true);
+ container_->configure(*config_elem_, true);
checkDS(0, "test_type", "{}");
for (const char** config(configs); *config; ++config) {
SCOPED_TRACE(*config);
ConstElementPtr elem(Element::fromJSON(*config));
- EXPECT_THROW(container_->configure(elem, true),
+ EXPECT_THROW(container_->configure(*elem, true),
ConfigurableContainer::ConfigurationError);
// Still untouched
checkDS(0, "test_type", "{}");
+ EXPECT_EQ(1, container_->getDataSources().size());
}
}
@@ -436,19 +445,19 @@ TEST_F(ContainerTest, defaults) {
"{"
" \"type\": \"type1\""
"}]"));
- container_->configure(elem, true);
- EXPECT_EQ(1, container_->dataSources().size());
+ container_->configure(*elem, true);
+ EXPECT_EQ(1, container_->getDataSources().size());
checkDS(0, "type1", "null");
}
// Check we can call the configure multiple times, to change the configuration
TEST_F(ContainerTest, reconfigure) {
ConstElementPtr empty(new ListElement);
- container_->configure(config_elem_, true);
+ container_->configure(*config_elem_, true);
checkDS(0, "test_type", "{}");
- container_->configure(empty, true);
- EXPECT_TRUE(container_->dataSources().empty());
- container_->configure(config_elem_, true);
+ container_->configure(*empty, true);
+ EXPECT_TRUE(container_->getDataSources().empty());
+ container_->configure(*config_elem_, true);
checkDS(0, "test_type", "{}");
}
@@ -458,9 +467,9 @@ TEST_F(ContainerTest, dataSrcError) {
"{"
" \"type\": \"error\""
"}]"));
- container_->configure(config_elem_, true);
+ container_->configure(*config_elem_, true);
checkDS(0, "test_type", "{}");
- EXPECT_THROW(container_->configure(elem, true), DataSourceError);
+ EXPECT_THROW(container_->configure(*elem, true), DataSourceError);
checkDS(0, "test_type", "{}");
}
More information about the bind10-changes
mailing list