Parcourir la source

[2993] Add unittest for the case where ZoneWriter encounters a bad zone and must throw

Mukund Sivaraman il y a 12 ans
Parent
commit
b4f1cd645e
1 fichiers modifiés avec 27 ajouts et 0 suppressions
  1. 27 0
      src/lib/datasrc/tests/client_list_unittest.cc

+ 27 - 0
src/lib/datasrc/tests/client_list_unittest.cc

@@ -1067,6 +1067,33 @@ TEST_P(ListTest, checkZoneWriterCatchesExceptions) {
     result.second->cleanup();
 }
 
+// Check that ZoneWriter throws when asked to
+TEST_P(ListTest, checkZoneWriterThrows) {
+    const ConstElementPtr config_elem_zones_(Element::fromJSON("["
+        "{"
+        "   \"type\": \"MasterFiles\","
+        "   \"params\": {"
+        "       \"example.edu\": \"" TEST_DATA_DIR "example.edu-broken\""
+        "    },"
+        "   \"cache-enable\": true"
+        "}]"));
+
+    list_->configure(config_elem_zones_, true);
+    ConfigurableClientList::ZoneWriterPair
+        result(list_->getCachedZoneWriter(Name("example.edu"), false));
+    ASSERT_EQ(ConfigurableClientList::ZONE_SUCCESS, result.first);
+    ASSERT_TRUE(result.second);
+
+    std::string error_msg;
+    // Because of the way we called getCachedZoneWriter() with
+    // catch_load_error=false, the following should throw and must not
+    // modify error_msg.
+    EXPECT_THROW(result.second->load(&error_msg),
+                 isc::datasrc::ZoneLoaderException);
+    EXPECT_TRUE(error_msg.empty());
+    result.second->cleanup();
+}
+
 // Test we can reload a zone
 TEST_P(ListTest, reloadSuccess) {
     list_->configure(config_elem_zones_, true);