Browse Source

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

git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1508 e5f2f494-b856-4b98-b285-d166d9295462
Jelte Jansen 15 years ago
parent
commit
84662a2deb
2 changed files with 54 additions and 0 deletions
  1. 53 0
      src/lib/config/tests/ccsession_unittests.cc
  2. 1 0
      src/lib/config/tests/fake_session.cc

+ 53 - 0
src/lib/config/tests/ccsession_unittests.cc

@@ -350,3 +350,56 @@ TEST(CCSession, checkCommand)
 
     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();
+}
+

+ 1 - 0
src/lib/config/tests/fake_session.cc

@@ -77,6 +77,7 @@ listRemove(ElementPtr list, ElementPtr el) {
         if (el == s_el) {
             i = 0;
         }
+        i++;
     }
     if (i >= 0) {
         list->remove(i);