Browse Source

[2209] Tests for the getCachedZoneWriter

They are the reload() tests reused for this purpose. They fail, since
the method is temporary and contains almost no code.
Michal 'vorner' Vaner 12 years ago
parent
commit
1eda789420

+ 6 - 0
src/lib/datasrc/client_list.cc

@@ -376,6 +376,12 @@ ConfigurableClientList::reload(const Name& name) {
     return (ZONE_RELOADED);
 }
 
+ConfigurableClientList::ZoneWriterPair
+ConfigurableClientList::getCachedZoneWriter(const Name& ) {
+    // TODO: Just for now.
+    return (ZoneWriterPair(CACHE_DISABLED, ZoneWriterPtr()));
+}
+
 // NOTE: This function is not tested, it would be complicated. However, the
 // purpose of the function is to provide a very thin wrapper to be able to
 // replace the call to DataSourceClientContainer constructor in tests.

+ 4 - 2
src/lib/datasrc/client_list.h

@@ -290,12 +290,14 @@ public:
     ///      the original data source no longer contains the cached zone.
     ReloadResult reload(const dns::Name& zone);
 
+    /// \brief Convenience type shortcut
+    typedef boost::shared_ptr<memory::ZoneWriter> ZoneWriterPtr;
+
     /// \brief Return value of getCachedZoneWriter()
     ///
     /// A pair containing status and the zone writer, for the
     /// getCachedZoneWriter() method.
-    typedef std::pair<ReloadResult, boost::shared_ptr<memory::ZoneWriter> >
-        ZoneWriterPair;
+    typedef std::pair<ReloadResult, ZoneWriterPtr> ZoneWriterPair;
 
     /// \brief Return a zone writer that can be used to reload a zone.
     ///

+ 28 - 3
src/lib/datasrc/tests/client_list_unittest.cc

@@ -20,6 +20,7 @@
 #include <datasrc/data_source.h>
 #include <datasrc/memory/memory_client.h>
 #include <datasrc/memory/zone_finder.h>
+#include <datasrc/memory/zone_writer.h>
 
 #include <dns/rrclass.h>
 #include <dns/rrttl.h>
@@ -862,10 +863,34 @@ ReloadTest<ReloadUpdateType>::doReload(const Name& origin) {
     return (list_->reload(origin));
 };
 
-// TODO: Version with ZoneWriter
+// Version with the ZoneWriter
+class WriterUpdateType {};
+template<>
+ConfigurableClientList::ReloadResult
+ReloadTest<WriterUpdateType>::doReload(const Name& origin) {
+    ConfigurableClientList::ZoneWriterPair
+        result(list_->getCachedZoneWriter(origin));
+    if (result.first == ConfigurableClientList::ZONE_RELOADED) {
+        // Can't use ASSERT_NE here, it would wan't to return(), which
+        // it can't in non-void function.
+        if (result.second) {
+            result.second->load();
+            result.second->install();
+            result.second->cleanup();
+        } else {
+            ADD_FAILURE() << "getCachedZoneWriter returned ZONE_RELOADED, "
+                "but the writer is NULL";
+        }
+    } else {
+        EXPECT_EQ(static_cast<memory::ZoneWriter*>(NULL),
+                  result.second.get());
+    }
+    return (result.first);
+}
 
-typedef ::testing::Types<ReloadUpdateType> UpdateTypes;
-TYPED_TEST_CASE(ReloadTest, ReloadUpdateType);
+// Typedefs for the GTEST guts to make it work
+typedef ::testing::Types<ReloadUpdateType, WriterUpdateType> UpdateTypes;
+TYPED_TEST_CASE(ReloadTest, UpdateTypes);
 
 // Test we can reload a zone
 TYPED_TEST(ReloadTest, reloadSuccess) {