Browse Source

[2378] Test throwing when missing zone

Michal 'vorner' Vaner 12 years ago
parent
commit
c9825a5714
1 changed files with 21 additions and 1 deletions
  1. 21 1
      src/lib/datasrc/tests/zone_loader_unittest.cc

+ 21 - 1
src/lib/datasrc/tests/zone_loader_unittest.cc

@@ -41,7 +41,8 @@ namespace {
 class MockClient : public DataSourceClient {
 class MockClient : public DataSourceClient {
 public:
 public:
     MockClient() :
     MockClient() :
-        commit_called_(false)
+        commit_called_(false),
+        missing_zone_(false)
     {}
     {}
     virtual FindResult findZone(const Name&) const {
     virtual FindResult findZone(const Name&) const {
         isc_throw(isc::NotImplemented, "Method not used in tests");
         isc_throw(isc::NotImplemented, "Method not used in tests");
@@ -64,6 +65,8 @@ public:
     // we get them as references.
     // we get them as references.
     vector<string> rrsets_;
     vector<string> rrsets_;
     bool commit_called_;
     bool commit_called_;
+    // If set to true, getUpdater returns NULL
+    bool missing_zone_;
 };
 };
 
 
 // The updater isn't really correct according to the API. For example,
 // The updater isn't really correct according to the API. For example,
@@ -97,6 +100,9 @@ private:
 
 
 ZoneUpdaterPtr
 ZoneUpdaterPtr
 MockClient::getUpdater(const Name& name, bool replace, bool journaling) const {
 MockClient::getUpdater(const Name& name, bool replace, bool journaling) const {
+    if (missing_zone_) {
+        return (ZoneUpdaterPtr());
+    }
     EXPECT_TRUE(replace);
     EXPECT_TRUE(replace);
     EXPECT_FALSE(journaling);
     EXPECT_FALSE(journaling);
     provided_updaters_.push_back(name);
     provided_updaters_.push_back(name);
@@ -222,4 +228,18 @@ TEST_F(ZoneLoaderTest, copySigned) {
               destination_client_.rrsets_[1]);
               destination_client_.rrsets_[1]);
 }
 }
 
 
+// If the destination zone does not exist, it throws
+TEST_F(ZoneLoaderTest, copyMissingDestination) {
+    destination_client_.missing_zone_ = true;
+    prepareSource(Name::ROOT_NAME(), "root.zone");
+    EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
+                            source_client_), DataSourceError);
+}
+
+// If the source zone does not exist, it throws
+TEST_F(ZoneLoaderTest, copyMissingSource) {
+    EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
+                            source_client_), DataSourceError);
+}
+
 }
 }