Browse Source

[2851] added a new test case for reloading a zone added to the datasrc later

JINMEI Tatuya 12 years ago
parent
commit
2cb8975382
2 changed files with 33 additions and 0 deletions
  1. 26 0
      src/lib/datasrc/tests/client_list_unittest.cc
  2. 7 0
      src/lib/datasrc/tests/mock_client.h

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

@@ -988,6 +988,32 @@ TEST_F(ListTest, reloadZoneGone) {
               list_->find(name).finder_->find(name, RRType::SOA())->code);
 }
 
+TEST_F(ListTest, reloadNewZone) {
+    // Test the case where a zone to be cached originally doesn't exist
+    // in the underlying data source and is added later.  reload() will
+    // succeed once it's available in the data source.
+    const ConstElementPtr elem(Element::fromJSON("["
+        "{"
+        "   \"type\": \"test_type\","
+        "   \"cache-enable\": true,"
+        "   \"cache-zones\": [\"example.org\", \"example.com\"],"
+        "   \"params\": [\"example.org\"]"
+        "}]"));
+    list_->configure(elem, true);
+    checkDS(0, "test_type", "[\"example.org\"]", true); // no example.com
+
+    // We can't reload it either
+    EXPECT_EQ(ConfigurableClientList::ZONE_NOT_FOUND,
+              doReload(Name("example.com")));
+
+    // If we add the zone, we can now reload it
+    static_cast<MockDataSourceClient*>(
+        list_->getDataSources()[0].data_src_client_)->
+        insertZone(Name("example.com"));
+    EXPECT_EQ(ConfigurableClientList::ZONE_SUCCESS,
+              doReload(Name("example.com")));
+}
+
 // The underlying data source throws. Check we don't modify the state.
 TEST_F(ListTest, reloadZoneThrow) {
     list_->configure(config_elem_zones_, true);

+ 7 - 0
src/lib/datasrc/tests/mock_client.h

@@ -58,6 +58,13 @@ public:
     void eraseZone(const dns::Name& zone_name) {
         zones.erase(zone_name);
     }
+
+    /// \brief Dynamically add a zone to the data source.
+    ///
+    /// \return true if the zone is newly added; false if it already exists.
+    bool insertZone(const dns::Name& zone_name) {
+        return (zones.insert(zone_name).second);
+    }
     const std::string type_;
     const data::ConstElementPtr configuration_;