BIND 10 trac1975, updated. 453e7ac4d32888e5aca1363048afb4ada7611279 [1975] Check that data source error exception is propagated
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jun 6 13:56:02 UTC 2012
The branch, trac1975 has been updated
via 453e7ac4d32888e5aca1363048afb4ada7611279 (commit)
via dc2fb18aebbf5d72e7e40517c21cc43d5c7e5b0f (commit)
from 2bedd44b4a58222083dc72a85bed101804ee7858 (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 453e7ac4d32888e5aca1363048afb4ada7611279
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jun 6 15:55:44 2012 +0200
[1975] Check that data source error exception is propagated
commit dc2fb18aebbf5d72e7e40517c21cc43d5c7e5b0f
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Wed Jun 6 15:31:56 2012 +0200
[1965] Tests for configuration
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/tests/container_unittest.cc | 115 +++++++++++++++++++++++++++
1 file changed, 115 insertions(+)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/tests/container_unittest.cc b/src/lib/datasrc/tests/container_unittest.cc
index 398ab30..1fa2718 100644
--- a/src/lib/datasrc/tests/container_unittest.cc
+++ b/src/lib/datasrc/tests/container_unittest.cc
@@ -14,6 +14,7 @@
#include <datasrc/container.h>
#include <datasrc/client.h>
+#include <datasrc/data_source.h>
#include <dns/rrclass.h>
@@ -123,6 +124,9 @@ public:
virtual DataSourcePair getDataSource(const string& type,
const ConstElementPtr& configuration)
{
+ if (type == "error") {
+ isc_throw(DataSourceError, "The error data source type");
+ }
shared_ptr<TestDS> ds(new TestDS(type, configuration));
// Make sure it is deleted when the test container is deleted.
to_delete_.push_back(ds);
@@ -212,6 +216,15 @@ public:
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_));
+ // Comparing with NULL does not work
+ ASSERT_TRUE(ds);
+ 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_;
@@ -325,4 +338,106 @@ TEST_F(ContainerTest, multiBestMatch) {
}
}
+// Check the configuration is empty when the list is empty
+TEST_F(ContainerTest, configureEmpty) {
+ ConstElementPtr elem(new ListElement);
+ container_.reset(new TestedContainer(elem, true));
+ EXPECT_TRUE(container_->dataSources().empty());
+}
+
+// Check we can get multiple data sources and they are in the right order.
+TEST_F(ContainerTest, configureMulti) {
+ ConstElementPtr elem(Element::fromJSON("["
+ "{"
+ " \"type\": \"type1\","
+ " \"cache\": \"off\","
+ " \"params\": {}"
+ "},"
+ "{"
+ " \"type\": \"type2\","
+ " \"cache\": \"off\","
+ " \"params\": {}"
+ "}]"
+ ));
+ container_.reset(new TestedContainer(elem, true));
+ EXPECT_EQ(2, container_->dataSources().size());
+ checkDS(0, "type1", "{}");
+ checkDS(1, "type2", "{}");
+}
+
+// Check we can pass whatever we want to the params
+TEST_F(ContainerTest, configureParams) {
+ const char* params[] = {
+ "true",
+ "false",
+ "null",
+ "\"hello\"",
+ "42",
+ "[]",
+ "{}",
+ NULL
+ };
+ for (const char** param(params); *param; ++param) {
+ SCOPED_TRACE(*param);
+ ConstElementPtr elem(Element::fromJSON(string("["
+ "{"
+ " \"type\": \"t\","
+ " \"cache\": \"off\","
+ " \"params\": ") + *param +
+ "}]"));
+ container_.reset(new TestedContainer(elem, true));
+ EXPECT_EQ(1, container_->dataSources().size());
+ checkDS(0, "t", *param);
+ }
+}
+
+TEST_F(ContainerTest, wrongConfig) {
+ const char* configs[] = {
+ // A lot of stuff missing from there
+ "[{}]",
+ // Some bad types completely
+ "{}",
+ "true",
+ "42",
+ "null",
+ "[true]",
+ "[[]]",
+ "[42]",
+ // Bad type of type
+ "[{\"type\": 42}]",
+ "[{\"type\": true}]",
+ "[{\"type\": null}]",
+ "[{\"type\": []}]",
+ "[{\"type\": {}}]",
+ // TODO: Once cache is supported, add some invalid cache values
+ NULL
+ };
+ for (const char** config(configs); *config; ++config) {
+ SCOPED_TRACE(*config);
+ ConstElementPtr elem(Element::fromJSON(*config));
+ EXPECT_THROW(TestedContainer(elem, true),
+ ConfigurableContainer::ConfigurationError);
+ }
+}
+
+// The param thing defaults to null. Cache is not used yet.
+TEST_F(ContainerTest, defaults) {
+ ConstElementPtr elem(Element::fromJSON("["
+ "{"
+ " \"type\": \"type1\""
+ "}]"));
+ container_.reset(new TestedContainer(elem, true));
+ EXPECT_EQ(1, container_->dataSources().size());
+ checkDS(0, "type1", "null");
+}
+
+// Make sure the data source error exception from the factory is propagated
+TEST_F(ContainerTest, dataSrcError) {
+ ConstElementPtr elem(Element::fromJSON("["
+ "{"
+ " \"type\": \"error\""
+ "}]"));
+ EXPECT_THROW(TestedContainer(elem, true), DataSourceError);
+}
+
}
More information about the bind10-changes
mailing list