[svn] commit: r1508 - in /trunk/src/lib/config/tests: ccsession_unittests.cc fake_session.cc

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Mar 18 10:06:37 UTC 2010


Author: jelte
Date: Thu Mar 18 10:06:37 2010
New Revision: 1508

Log:
unit tests for add/removeRemoteConfig in lib/config/ccsession

Modified:
    trunk/src/lib/config/tests/ccsession_unittests.cc
    trunk/src/lib/config/tests/fake_session.cc

Modified: trunk/src/lib/config/tests/ccsession_unittests.cc
==============================================================================
--- trunk/src/lib/config/tests/ccsession_unittests.cc (original)
+++ trunk/src/lib/config/tests/ccsession_unittests.cc Thu Mar 18 10:06:37 2010
@@ -350,3 +350,56 @@
 
     endFakeSession();
 }
+
+TEST(CCSession, remoteConfig)
+{
+    std::string module_name;
+    int item1;
+    
+    initFakeSession();
+    ModuleCCSession mccs(ccspecfile("spec1.spec"), NULL, NULL);
+    EXPECT_EQ(true, haveSubscription("Spec1", "*"));
+    
+    // first simply connect, with no config values, and see we get
+    // the default
+    initial_messages->add(createAnswer(0, el("{}")));
+
+    EXPECT_EQ(false, haveSubscription("Spec2", "*"));
+    module_name = mccs.addRemoteConfig(ccspecfile("spec2.spec"));
+    EXPECT_EQ("Spec2", module_name);
+    EXPECT_EQ(true, haveSubscription("Spec2", "*"));
+
+    item1 = mccs.getRemoteConfigValue(module_name, "item1")->intValue();
+    EXPECT_EQ(1, item1);
+
+    // Remove it and see we get an error asking for a config value
+    mccs.removeRemoteConfig(module_name);
+    EXPECT_EQ(false, haveSubscription("Spec2", "*"));
+    EXPECT_THROW(mccs.getRemoteConfigValue(module_name, "item1"), CCSessionError);
+
+    // Now re-add it, with a specific config value, and see we get that
+    initial_messages->add(createAnswer(0, el("{ \"item1\": 2 }")));
+    module_name = mccs.addRemoteConfig(ccspecfile("spec2.spec"));
+    item1 = mccs.getRemoteConfigValue(module_name, "item1")->intValue();
+    EXPECT_EQ(2, item1);
+
+    // Try a config_update command
+    addMessage(el("{ \"command\": [ \"config_update\", { \"item1\": 3 } ] }"), module_name, "*");
+    mccs.checkCommand();
+    item1 = mccs.getRemoteConfigValue(module_name, "item1")->intValue();
+    EXPECT_EQ(3, item1);
+
+    // remove, re-add, now with a *bad* config request answer
+    mccs.removeRemoteConfig(module_name);
+    initial_messages->add(el("{}"));
+    EXPECT_THROW(mccs.addRemoteConfig(ccspecfile("spec2.spec")), CCSessionError);
+    
+    initial_messages->add(createAnswer(1, "my_error"));
+    EXPECT_THROW(mccs.addRemoteConfig(ccspecfile("spec2.spec")), CCSessionError);
+    
+    initial_messages->add(createAnswer());
+    mccs.addRemoteConfig(ccspecfile("spec2.spec"));
+    
+    endFakeSession();
+}
+

Modified: trunk/src/lib/config/tests/fake_session.cc
==============================================================================
--- trunk/src/lib/config/tests/fake_session.cc (original)
+++ trunk/src/lib/config/tests/fake_session.cc Thu Mar 18 10:06:37 2010
@@ -77,6 +77,7 @@
         if (el == s_el) {
             i = 0;
         }
+        i++;
     }
     if (i >= 0) {
         list->remove(i);




More information about the bind10-changes mailing list