]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3436] Added check to verify error messages contain position info
authorThomas Markwalder <tmark@isc.org>
Tue, 1 Jul 2014 20:37:58 +0000 (16:37 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 1 Jul 2014 20:37:58 +0000 (16:37 -0400)
Modifiedl D2CfgMgr.configPermutations test to verify that
parsing error messages contain position information.
Fixed format of one error message in D2CfgMgr that didn't
match. Hopefully, Marcin is happy now.

src/bin/d2/d2_cfg_mgr.cc
src/bin/d2/tests/Makefile.am
src/bin/d2/tests/d2_cfg_mgr_unittests.cc

index ad21aadac68982462bcca140ebc33daa8243e5c7..3759207700cbb45ed907a54ae34bfc31ded409dd 100644 (file)
@@ -326,8 +326,8 @@ D2CfgMgr::createConfigParser(const std::string& config_id,
                                                context->getKeys()));
     } else {
         isc_throw(NotImplemented,
-                  "parser error: D2CfgMgr parameter not supported: "
-                  << config_id << pos);
+                  "parser error: D2CfgMgr parameter not supported : "
+                  " (" << config_id << pos << ")");
     }
 
     return (parser);
index 629ed798972432c04bfa23d4d12a8d2f3eb1bedc..ed510a536a1510dd5db84953dbd3e3fb349cd4bc 100644 (file)
@@ -131,6 +131,7 @@ d2_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libkea-dhcp++.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
+d2_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
 d2_unittests_LDADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
index 0a54dff2a1a136d8c5ac647d5efb1e0a832ccbbf..a20f372d81dc8794562ce94aea6cfec023690f16 100644 (file)
@@ -18,6 +18,7 @@
 #include <d_test_stubs.h>
 #include <test_data_files_config.h>
 #include <util/encode/base64.h>
+#include <dhcpsrv/testutils/config_result_check.h>
 
 #include <boost/foreach.hpp>
 #include <gtest/gtest.h>
@@ -98,7 +99,6 @@ public:
 
         return (config.str());
     }
-
     /// @brief Enumeration to select between expected configuration outcomes
     enum RunConfigMode {
        SHOULD_PASS,
@@ -135,6 +135,50 @@ public:
         ASSERT_TRUE(d2_params_);
     }
 
+    /// @brief Check parse result against expected outcome and position info
+    ///
+    /// This method analyzes the given parsing result against an expected outcome
+    /// of SHOULD_PASS or SHOULD_FAIL.  If it is expected to fail, the comment
+    /// contained within the result is searched for Element::Position information
+    /// which should contain the given file name.  It does not attempt to verify
+    /// the numerical values for line number and col.
+    ///
+    /// @param answer Element set containing an integer result code and string
+    /// comment.
+    /// @param mode indicator if the parsing should fail or not.
+    /// @param file_name name of the file containing the configuration text
+    /// parsed. It defaults to "<string>" which is the value present if the
+    /// configuration text did not originate from a file. (i.e. one did not use
+    /// isc::data::Element::fromJSONFile() to read the JSON text).
+    void
+    checkAnswerWithError(isc::data::ConstElementPtr answer,
+                         RunConfigMode mode, std::string file_name="<string>") {
+        int rcode = 0;
+        isc::data::ConstElementPtr comment;
+        comment = isc::config::parseAnswer(rcode, answer);
+
+        if (mode == SHOULD_PASS) {
+            if (rcode == 0) {
+                return;
+            }
+
+            FAIL() << "Parsing was expected to pass but failed : " << rcode
+                   << " comment: " << *comment;
+        }
+
+        if (rcode == 0) {
+            FAIL() << "Parsing was expected to fail but passed : "
+                   << " comment: " << *comment;
+        }
+
+        // Parsing was expected to fail, test for position info.
+        if (isc::dhcp::test::errorContainsPosition(answer, file_name)) {
+            return;
+        }
+
+        FAIL() << "Parsing failed as expected but lacks position : " << *comment;
+    }
+
     /// @brief Pointer the D2Params most recently parsed.
     D2ParamsPtr d2_params_;
 };
@@ -1666,14 +1710,12 @@ TEST_F(D2CfgMgrTest, configPermutations) {
         ASSERT_TRUE(data) << "No data for test: "
                           << " : " << test->getPosition();
 
-        // Verify that we can parse the configuration.
-        answer_ = cfg_mgr_->parseConfig(data);
-        if (checkAnswer(!should_fail)) {
-            ADD_FAILURE() << "Parsing should have "
-                          << (should_fail ? "failed" : "passed")
-                          << " for : " << description
-                          << " : "  << test->getPosition();
-        }
+        // Attempt to parse the configuration. We verify that we get the expected
+        // outcome, and if it was supposed to fail if the explanation contains
+        // position information.
+        checkAnswerWithError(cfg_mgr_->parseConfig(data),
+                             (should_fail ? SHOULD_FAIL : SHOULD_PASS),
+                             test_file);
     }
 }