Use 'undeclared handler' for multi-valued 'add-node' config option

pull/1186/head
Stephen Shelton 4 years ago
parent feacde7864
commit c5ff672c79
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -386,15 +386,17 @@ namespace llarp
void
BootstrapConfig::defineConfigOptions(Configuration& conf)
{
// TODO: multi-value
/*
if(key == "add-node")
{
routers.emplace_back(val.begin(), val.end());
}
*/
(void)conf;
// throw std::runtime_error("FIXME");
conf.addUndeclaredHandler("bootstrap", [&](string_view, string_view name, string_view value) {
if (name != "add-node")
{
return false;
}
else
{
routers.emplace_back(str(value));
return true;
}
});
}
void

@ -313,3 +313,20 @@ TEST_CASE("Configuration undeclared handler wrong section", "[config]")
REQUIRE_THROWS_WITH(config.addConfigValue("argle", "bar", "val"), "no declared section [argle]");
}
TEST_CASE("Configuration undeclared handler duplicate names", "[config]")
{
llarp::Configuration config;
int count = 0;
config.addUndeclaredHandler("foo", [&](string_view, string_view, string_view) {
count++;
});
REQUIRE_NOTHROW(config.addConfigValue("foo", "k", "v"));
REQUIRE_NOTHROW(config.addConfigValue("foo", "k", "v"));
REQUIRE_NOTHROW(config.addConfigValue("foo", "k", "v"));
REQUIRE(count == 3);
}

Loading…
Cancel
Save