From: Slawek Figiel Date: Fri, 25 Mar 2022 11:12:59 +0000 (+0100) Subject: [#1716] Parser unit tests X-Git-Tag: Kea-2.1.5~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46df0e8f8d2fd22552edbe40e5aa31437965a775;p=thirdparty%2Fkea.git [#1716] Parser unit tests --- diff --git a/src/lib/dhcpsrv/tests/ifaces_config_parser_unittest.cc b/src/lib/dhcpsrv/tests/ifaces_config_parser_unittest.cc index 8b3fe7239f..974ba96af6 100644 --- a/src/lib/dhcpsrv/tests/ifaces_config_parser_unittest.cc +++ b/src/lib/dhcpsrv/tests/ifaces_config_parser_unittest.cc @@ -275,4 +275,109 @@ TEST_F(IfacesConfigParserTest, outboundInterface) { EXPECT_THROW(parser6.parse(cfg_iface, config_element), DhcpConfigError); } +// Tests that service-sockets-require-all is parsed properly. +TEST_F(IfacesConfigParserTest, serviceSocketRequireAll) { + // Create the reference configuration, which we will compare + // the parsed configuration to. + CfgIface cfg_ref; + + // Configuration with a require all sockets to open selected. + std::string config = "{ \"interfaces\": [ ]," + " \"re-detect\": false," + " \"service-sockets-require-all\": true }"; + + ElementPtr config_element = Element::fromJSON(config); + + // Parse the configuration. + IfacesConfigParser parser(AF_INET, false); + CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); + ASSERT_TRUE(cfg_iface); + ASSERT_NO_THROW(parser.parse(cfg_iface, config_element)); + + // Check it can be unparsed. + runToElementTest(config, *cfg_iface); +} + +// Tests that service-sockets-max-retries is parsed properly. +TEST_F(IfacesConfigParserTest, serviceSocketMaxRetries) { + // Create the reference configuration, which we will compare + // the parsed configuration to. + CfgIface cfg_ref; + + // Configuration with a non-zero retries selected. + std::string config = "{ \"interfaces\": [ ]," + " \"re-detect\": false," + " \"service-sockets-max-retries\": 42 }"; + + ElementPtr config_element = Element::fromJSON(config); + + // Parse the configuration. + IfacesConfigParser parser(AF_INET, false); + CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); + ASSERT_TRUE(cfg_iface); + ASSERT_NO_THROW(parser.parse(cfg_iface, config_element)); + + // Configuration should contain a number of retries and a wait time. + std::string expected_config = "{ \"interfaces\": [ ]," + " \"re-detect\": false," + " \"service-sockets-retry-wait-time\": 5000," + " \"service-sockets-max-retries\": 42 }"; + + // Check it can be unparsed. + runToElementTest(expected_config, *cfg_iface); +} + +// Tests that service-sockets-retry-wait-time is parsed properly if +// service-sockets-max-retries is provided. +TEST_F(IfacesConfigParserTest, serviceSocketRetryWaitTime) { + // Create the reference configuration, which we will compare + // the parsed configuration to. + CfgIface cfg_ref; + + // Configuration with a non-zero number of retries and a non-default wait time. + std::string config = "{ \"interfaces\": [ ]," + " \"re-detect\": false," + " \"service-sockets-retry-wait-time\": 4224," + " \"service-sockets-max-retries\": 42 }"; + + ElementPtr config_element = Element::fromJSON(config); + + // Parse the configuration. + IfacesConfigParser parser(AF_INET, false); + CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); + ASSERT_TRUE(cfg_iface); + ASSERT_NO_THROW(parser.parse(cfg_iface, config_element)); + + // Check it can be unparsed. + runToElementTest(config, *cfg_iface); +} + +// Tests that service-sockets-retry-wait-time is ignored if +// service-sockets-max-retries is not provided. +TEST_F(IfacesConfigParserTest, serviceSocketRetryWaitTimeWithoutMaxRetries) { + // Create the reference configuration, which we will compare + // the parsed configuration to. + CfgIface cfg_ref; + + // Configuration with zero (default) retries and a non-default wait time. + std::string config = "{ \"interfaces\": [ ]," + " \"re-detect\": false," + " \"service-sockets-retry-wait-time\": 4224 }"; + + ElementPtr config_element = Element::fromJSON(config); + + // Parse the configuration. + IfacesConfigParser parser(AF_INET, false); + CfgIfacePtr cfg_iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); + ASSERT_TRUE(cfg_iface); + ASSERT_NO_THROW(parser.parse(cfg_iface, config_element)); + + // Retry wait time is not applicable; it is skipped. + std::string expected_config = "{ \"interfaces\": [ ]," + " \"re-detect\": false }"; + + // Check it can be unparsed. + runToElementTest(expected_config, *cfg_iface); +} + } // end of anonymous namespace