]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2378] Fixes of ZoneLoader and tests
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 4 Dec 2012 12:57:50 +0000 (13:57 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 13 Dec 2012 10:33:57 +0000 (11:33 +0100)
After the rebase on top of working 2377. The most significant - don't
access updater if it doesn't exist.

src/lib/datasrc/tests/zone_loader_unittest.cc
src/lib/datasrc/zone_loader.cc
src/lib/datasrc/zone_loader.h

index ccc5b9d28d544bb0436e18196ca2f3dcacbd15dd..c71c1e3572a06455e6f2ecc6036c664380891c89 100644 (file)
@@ -288,7 +288,7 @@ TEST_F(ZoneLoaderTest, classMismatch) {
 // Load an unsigned zone, all at once
 TEST_F(ZoneLoaderTest, loadUnsigned) {
     ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
-                      TEST_DATA_DIR "root.zone");
+                      TEST_DATA_DIR "/root.zone");
     // It gets the updater directly in the constructor
     ASSERT_EQ(1, destination_client_.provided_updaters_.size());
     EXPECT_EQ(Name::ROOT_NAME(), destination_client_.provided_updaters_[0]);
@@ -377,8 +377,10 @@ TEST_F(ZoneLoaderTest, loadSigned) {
 
 // Test it throws when there's no such file
 TEST_F(ZoneLoaderTest, loadNoSuchFile) {
-    EXPECT_THROW(ZoneLoader(destination_client_, Name::ROOT_NAME(),
-                            "This file does not exist"), MasterFileError);
+    ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
+                      "This file does not exist");
+    EXPECT_THROW(loader.load(), MasterFileError);
+    EXPECT_FALSE(destination_client_.commit_called_);
 }
 
 // And it also throws when there's a syntax error in the master file
index b77f6b8619fb3bd7acbd90d3bbd2a970c11053ac..1d06740c3c574087713c015981109ac6d156d3fe 100644 (file)
@@ -59,18 +59,23 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
 ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
                        const char* filename) :
     updater_(destination.getUpdater(zone_name, true, false)),
-    loader_(new MasterLoader(filename, zone_name,
-                             // TODO: Maybe we should have getClass() on the
-                             // data source?
-                             updater_->getFinder().getClass(),
-                             createMasterLoaderCallbacks(zone_name,
-                                             updater_->getFinder().getClass(),
-                                             &loaded_ok_),
-                             createMasterLoaderAddCallback(*updater_))),
     complete_(false),
     loaded_ok_(true)
 {
-
+    if (updater_ == ZoneUpdaterPtr()) {
+        isc_throw(DataSourceError, "Zone " << zone_name << " not found in "
+                  "destination data source, can't fill it with data");
+    } else {
+        loader_.reset(new
+                      MasterLoader(filename, zone_name,
+                                   // TODO: Maybe we should have getClass()
+                                   // on the data source?
+                                   updater_->getFinder().getClass(),
+                                   createMasterLoaderCallbacks(zone_name,
+                                       updater_->getFinder().getClass(),
+                                       &loaded_ok_),
+                                   createMasterLoaderAddCallback(*updater_)));
+    }
 }
 
 namespace {
index 65be733fd61210bbf3c80a9ad173017bc0e6f1bd..5f5ddfd399477194c597121ff2e5d552f23cff31 100644 (file)
@@ -140,7 +140,7 @@ private:
     /// \brief The destination zone updater
     const ZoneUpdaterPtr updater_;
     /// \brief The master loader (for the loader mode)
-    const boost::scoped_ptr<isc::dns::MasterLoader> loader_;
+    boost::scoped_ptr<isc::dns::MasterLoader> loader_;
     /// \brief Indicator if loading was completed
     bool complete_;
     /// \brief Was the loading successful?