diff options
author | Andrei Pavel <andrei@isc.org> | 2021-11-03 14:14:24 +0100 |
---|---|---|
committer | Andrei Pavel <andrei@isc.org> | 2021-12-17 16:18:28 +0100 |
commit | 446ead1e545757c05d762c224547bf376a383ac7 (patch) | |
tree | 0333a0157e2eef58d6996124fca943c403ed1001 /src/bin/netconf | |
parent | [#2084] allow trailing comma in JSON configuration (diff) | |
download | kea-446ead1e545757c05d762c224547bf376a383ac7.tar.xz kea-446ead1e545757c05d762c224547bf376a383ac7.zip |
[#2084] add unit tests for trailing comma
Diffstat (limited to 'src/bin/netconf')
-rw-r--r-- | src/bin/netconf/tests/parser_unittests.cc | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/src/bin/netconf/tests/parser_unittests.cc b/src/bin/netconf/tests/parser_unittests.cc index a282b35133..f8a372f4ea 100644 --- a/src/bin/netconf/tests/parser_unittests.cc +++ b/src/bin/netconf/tests/parser_unittests.cc @@ -7,8 +7,8 @@ #include <config.h> #include <cc/data.h> -#include <netconf/parser_context.h> #include <cc/dhcp_config_error.h> +#include <netconf/parser_context.h> #include <testutils/gtest_utils.h> #include <testutils/io_utils.h> #include <testutils/user_context_utils.h> @@ -18,6 +18,8 @@ #include <fstream> #include <set> +#include <boost/algorithm/string.hpp> + using namespace isc::data; using namespace isc::test; using namespace std; @@ -51,8 +53,9 @@ void compareJSON(ConstElementPtr a, ConstElementPtr b) { /// @param compare whether to compare the output with legacy JSON parser void testParser(const std::string& txt, ParserContext::ParserType parser_type, bool compare = true) { - ConstElementPtr test_json; + SCOPED_TRACE("\n=== tested config ===\n" + txt + "====================="); + ConstElementPtr test_json; ASSERT_NO_THROW_LOG({ try { ParserContext ctx; @@ -396,8 +399,9 @@ TEST(ParserTest, file) { /// @param msg expected content of the exception void testError(const std::string& txt, ParserContext::ParserType parser_type, - const std::string& msg) -{ + const std::string& msg) { + SCOPED_TRACE("\n=== tested config ===\n" + txt + "====================="); + try { ParserContext ctx; ConstElementPtr parsed = ctx.parseString(txt, parser_type); @@ -644,10 +648,6 @@ TEST(ParserTest, errors) { ParserContext::PARSER_JSON, "<string>:1.3: syntax error, unexpected \",\", " "expecting }"); - testError("{ \"foo\":true, }\n", - ParserContext::PARSER_JSON, - "<string>:1.15: syntax error, unexpected }, " - "expecting constant string"); // bad type testError("{ \"Netconf\":{\n" @@ -703,7 +703,7 @@ TEST(ParserTest, errors) { " \"Netconf\":{\n" " \"comment\": \"second\" }}\n", ParserContext::PARSER_NETCONF, - "<string>:2.23: syntax error, unexpected \",\", expecting }"); + "<string>:3.3-11: syntax error, unexpected Netconf, expecting \",\" or }"); // duplicate of not string entries testError("{ \"Netconf\":{\n" @@ -917,6 +917,45 @@ TEST(ParserTest, duplicateMapEntries) { cout << "checked " << cnt << " duplicated map entries\n"; } +// Test that trailing commas are allowed. +TEST(ParserTest, trailingCommas) { + string txt(R"({ + "Netconf": { + "boot-update": true, + "loggers": [ + { + "name": "kea-netconf", + "severity": "DEBUG", + "debuglevel": 99, + }, + ], + "managed-servers": { + "dhcp4": { + "control-socket": { + "socket-name": "/tmp/kea-dhcp4-ctrl.sock", + "socket-type": "unix", + }, + "model": "kea-dhcp4-server", + }, + "dhcp6": { + "control-socket": { + "socket-name": "/tmp/kea-dhcp6-ctrl.sock", + "socket-type": "unix", + }, + "model": "kea-dhcp6-server", + }, + }, + "subscribe-changes": true, + "validate-changes": true, + }, +})"); + testParser(txt, ParserContext::PARSER_NETCONF, false); + + // Test with many consecutive commas. + boost::replace_all(txt, ",", ",,,,"); + testParser(txt, ParserContext::PARSER_NETCONF, false); } -} -} + +} // namespace test +} // namespace netconf +} // namespace isc |