]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2084] Added log checking
authorFrancis Dupont <fdupont@isc.org>
Thu, 16 Dec 2021 21:38:03 +0000 (22:38 +0100)
committerAndrei Pavel <andrei@isc.org>
Fri, 17 Dec 2021 15:21:22 +0000 (17:21 +0200)
src/bin/agent/tests/parser_unittests.cc
src/bin/d2/tests/parser_unittest.cc
src/bin/dhcp4/tests/parser_unittest.cc
src/bin/dhcp6/tests/parser_unittest.cc
src/bin/netconf/tests/parser_unittests.cc

index 756760fa640f71b2afd015e851cfd650f922ffa5..a896549f9f40a1b3c5dfa5fbf9e7f289cac75869 100644 (file)
@@ -10,6 +10,7 @@
 #include <cc/data.h>
 #include <cc/dhcp_config_error.h>
 #include <testutils/io_utils.h>
+#include <testutils/log_utils.h>
 #include <testutils/user_context_utils.h>
 
 #include <gtest/gtest.h>
@@ -857,8 +858,23 @@ TEST(ParserTest, duplicateMapEntries) {
     cout << "checked " << cnt << " duplicated map entries\n";
 }
 
+/// @brief Test fixture for trailing commas.
+class TrailingCommasTest : public isc::dhcp::test::LogContentTest {
+public:
+    /// @brief Add a log entry.
+    ///
+    /// @param loc Location of the trailing comma.
+    void addLog(const string& loc) {
+      string log = "CTRL_AGENT_CONFIG_SYNTAX_WARNING Control Agent ";
+        log += "configuration syntax warning: " + loc;
+        log += ": Extraneous comma. ";
+        log += "A piece of configuration may have been omitted.";
+        addString(log);
+    }
+};
+
 // Test that trailing commas are allowed.
-TEST(ParserTest, trailingCommas) {
+TEST_F(TrailingCommasTest, tests) {
     string txt(R"({
   "Control-agent": {
     "control-sockets": {
@@ -893,6 +909,18 @@ TEST(ParserTest, trailingCommas) {
 })");
     testParser(txt, ParserContext::PARSER_AGENT, false);
 
+    addLog("<string>:6.30");
+    addLog("<string>:10.30");
+    addLog("<string>:14.30");
+    addLog("<string>:15.8");
+    addLog("<string>:25.31");
+    addLog("<string>:26.12");
+    addLog("<string>:28.28");
+    addLog("<string>:29.8");
+    addLog("<string>:30.6");
+    addLog("<string>:31.4");
+    EXPECT_TRUE(checkFile());
+
     // Test with many consecutive commas.
     boost::replace_all(txt, ",", ",,,,");
     testParser(txt, ParserContext::PARSER_AGENT, false);
index 2e122c4a2fba1a490b8c84401634d7b6e1540c5e..5ad96bc66ddd629d0bac4ebad28e264ef85be52a 100644 (file)
@@ -9,6 +9,7 @@
 #include <d2/parser_context.h>
 #include <d2/tests/parser_unittest.h>
 #include <testutils/io_utils.h>
+#include <testutils/log_utils.h>
 #include <testutils/user_context_utils.h>
 
 #include <gtest/gtest.h>
@@ -807,8 +808,23 @@ TEST(ParserTest, duplicateMapEntries) {
     cout << "checked " << cnt << " duplicated map entries\n";
 }
 
+/// @brief Test fixture for trailing commas.
+class TrailingCommasTest : public isc::dhcp::test::LogContentTest {
+public:
+    /// @brief Add a log entry.
+    ///
+    /// @param loc Location of the trailing comma.
+    void addLog(const string& loc) {
+      string log = "DHCP_DDNS_CONFIG_SYNTAX_WARNING DHCP-DDNS server ";
+        log += "configuration syntax warning: " + loc;
+        log += ": Extraneous comma. ";
+        log += "A piece of configuration may have been omitted.";
+        addString(log);
+    }
+};
+
 // Test that trailing commas are allowed.
-TEST(ParserTest, trailingCommas) {
+TEST_F(TrailingCommasTest, tests) {
     string txt(R"({
   "DhcpDdns": {
     "forward-ddns": {},
@@ -837,6 +853,14 @@ TEST(ParserTest, trailingCommas) {
 })");
     testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
 
+    addLog("<string>:11.12");
+    addLog("<string>:13.28");
+    addLog("<string>:14.8");
+    addLog("<string>:22.45");
+    addLog("<string>:23.8");
+    addLog("<string>:25.4");
+    EXPECT_TRUE(checkFile());
+
     // Test with many consecutive commas.
     boost::replace_all(txt, ",", ",,,,");
     testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
index bbed9e3ed850f33e890402e5890062ed7ee6497e..03fa55d7ec01213c1146134922e5ca4ab206ec22 100644 (file)
@@ -10,6 +10,7 @@
 #include <dhcpsrv/parsers/simple_parser4.h>
 #include <testutils/gtest_utils.h>
 #include <testutils/io_utils.h>
+#include <testutils/log_utils.h>
 #include <testutils/user_context_utils.h>
 
 #include <gtest/gtest.h>
@@ -876,8 +877,23 @@ TEST(ParserTest, duplicateMapEntries) {
     cout << "checked " << cnt << " duplicated map entries\n";
 }
 
+/// @brief Test fixture for trailing commas.
+class TrailingCommasTest : public isc::dhcp::test::LogContentTest {
+public:
+    /// @brief Add a log entry.
+    ///
+    /// @param loc Location of the trailing comma.
+    void addLog(const string& loc) {
+        string log = "DHCP4_CONFIG_SYNTAX_WARNING configuration syntax ";
+        log += "warning: " + loc;
+        log += ": Extraneous comma. ";
+        log += "A piece of configuration may have been omitted.";
+        addString(log);
+    }
+};      
+
 // Test that trailing commas are allowed.
-TEST(ParserTest, trailingCommas) {
+TEST_F(TrailingCommasTest, tests) {
     string txt(R"({
   "Dhcp4": {
     "control-socket": {
@@ -930,6 +946,24 @@ TEST(ParserTest, trailingCommas) {
 })");
     testParser(txt, Parser4Context::PARSER_DHCP4, false);
 
+    addLog("<string>:5.28");
+    addLog("<string>:9.63");
+    addLog("<string>:10.8");
+    addLog("<string>:14.15");
+    addLog("<string>:15.8");
+    addLog("<string>:20.24");
+    addLog("<string>:28.31");
+    addLog("<string>:29.12");
+    addLog("<string>:31.28");
+    addLog("<string>:32.8");
+    addLog("<string>:43.37");
+    addLog("<string>:44.12");
+    addLog("<string>:46.35");
+    addLog("<string>:47.8");
+    addLog("<string>:48.6");
+    addLog("<string>:49.4");
+    EXPECT_TRUE(checkFile());
+
     // Test with many consecutive commas.
     boost::replace_all(txt, ",", ",,,,");
     testParser(txt, Parser4Context::PARSER_DHCP4, false);
index d1783b27b8b9932263ec52b97835584afe8f0598..927f70a5afc1c1c82f33f2ebae19bbbc490b378a 100644 (file)
@@ -9,6 +9,7 @@
 #include <dhcp6/parser_context.h>
 #include <dhcpsrv/parsers/simple_parser6.h>
 #include <testutils/io_utils.h>
+#include <testutils/log_utils.h>
 #include <testutils/user_context_utils.h>
 #include <testutils/gtest_utils.h>
 
@@ -866,8 +867,23 @@ TEST(ParserTest, duplicateMapEntries) {
     cout << "checked " << cnt << " duplicated map entries\n";
 }
 
+/// @brief Test fixture for trailing commas.
+class TrailingCommasTest : public isc::dhcp::test::LogContentTest {
+public:
+    /// @brief Add a log entry.
+    ///
+    /// @param loc Location of the trailing comma.
+    void addLog(const string& loc) {
+        string log = "DHCP6_CONFIG_SYNTAX_WARNING configuration syntax ";
+        log += "warning: " + loc;
+        log += ": Extraneous comma. ";
+        log += "A piece of configuration may have been omitted.";
+        addString(log);
+    }
+};
+
 // Test that trailing commas are allowed.
-TEST(ParserTest, trailingCommas) {
+TEST_F(TrailingCommasTest, tests) {
     string txt(R"({
   "Dhcp6": {
     "control-socket": {
@@ -920,6 +936,24 @@ TEST(ParserTest, trailingCommas) {
 })");
     testParser(txt, Parser6Context::PARSER_DHCP6, false);
 
+    addLog("<string>:5.28");
+    addLog("<string>:9.63");
+    addLog("<string>:10.8");
+    addLog("<string>:14.15");
+    addLog("<string>:15.8");
+    addLog("<string>:20.24");
+    addLog("<string>:28.31");
+    addLog("<string>:29.12");
+    addLog("<string>:31.28");
+    addLog("<string>:32.8");
+    addLog("<string>:43.38");
+    addLog("<string>:44.12");
+    addLog("<string>:46.36");
+    addLog("<string>:47.8");
+    addLog("<string>:48.6");
+    addLog("<string>:49.4");
+    EXPECT_TRUE(checkFile());
+
     // Test with many consecutive commas.
     boost::replace_all(txt, ",", ",,,,");
     testParser(txt, Parser6Context::PARSER_DHCP6, false);
index f8a372f4eabd8c842ab08f2321294eff704d7919..da953a09b7e898b89248372d4e8804655998ee3b 100644 (file)
@@ -11,6 +11,7 @@
 #include <netconf/parser_context.h>
 #include <testutils/gtest_utils.h>
 #include <testutils/io_utils.h>
+#include <testutils/log_utils.h>
 #include <testutils/user_context_utils.h>
 
 #include <gtest/gtest.h>
@@ -917,8 +918,23 @@ TEST(ParserTest, duplicateMapEntries) {
     cout << "checked " << cnt << " duplicated map entries\n";
 }
 
+/// @brief Test fixture for trailing commas.
+class TrailingCommasTest : public isc::dhcp::test::LogContentTest {
+public:
+    /// @brief Add a log entry.
+    ///
+    /// @param loc Location of the trailing comma.
+    void addLog(const string& loc) {
+      string log = "NETCONF_CONFIG_SYNTAX_WARNING Netconf ";
+        log += "configuration syntax warning: " + loc;
+        log += ": Extraneous comma. ";
+        log += "A piece of configuration may have been omitted.";
+        addString(log);
+    }
+};
+
 // Test that trailing commas are allowed.
-TEST(ParserTest, trailingCommas) {
+TEST_F(TrailingCommasTest, tests) {
     string txt(R"({
   "Netconf": {
     "boot-update": true,
@@ -951,6 +967,10 @@ TEST(ParserTest, trailingCommas) {
 })");
     testParser(txt, ParserContext::PARSER_NETCONF, false);
 
+    addLog("<string>:7.16");
+    /// @todo
+    EXPECT_TRUE(checkFile());
+
     // Test with many consecutive commas.
     boost::replace_all(txt, ",", ",,,,");
     testParser(txt, ParserContext::PARSER_NETCONF, false);