// 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]);
// 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
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 {
/// \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?