Rename function for clarity

This commit is contained in:
Stephen Shelton 2020-03-18 07:39:18 -06:00
parent 8160c13458
commit 60d0bf2a9b
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C
3 changed files with 8 additions and 13 deletions

View File

@ -45,7 +45,7 @@ Configuration::addConfigValue(string_view section, string_view name, string_view
}
void
Configuration::validate()
Configuration::validateRequiredFields()
{
visitSections([&](const std::string& section, const DefinitionMap&) {
visitDefinitions(section, [&](const std::string&, const ConfigDefinition_ptr& def) {

View File

@ -222,16 +222,11 @@ namespace llarp
return derived->getValue();
}
/// Validate the config, presumably called after parsing. This will throw an exception if the
/// parsed values do not meet the provided definition.
///
/// Note that this will only handle a subset of errors that may occur. Specifically, this will
/// handle errors about missing required fields, whereas errors about incorrect type,
/// duplicates, etc. are handled during parsing.
/// Validate that all required fields are present.
///
/// @throws std::invalid_argument if configuration constraints are not met
void
validate();
validateRequiredFields();
/// Generate a config string from the current config definition, optionally using overridden
/// values. The generated config will preserve insertion order of both sections and their

View File

@ -105,11 +105,11 @@ TEST_CASE("Configuration required test", "[config]")
false,
1));
CHECK_THROWS(config.validate());
CHECK_THROWS(config.validateRequiredFields());
config.addConfigValue("router", "threads", "12");
CHECK_NOTHROW(config.validate());
CHECK_NOTHROW(config.validateRequiredFields());
}
TEST_CASE("Configuration section test", "[config]")
@ -128,13 +128,13 @@ TEST_CASE("Configuration section test", "[config]")
false,
1));
CHECK_THROWS(config.validate());
CHECK_THROWS(config.validateRequiredFields());
config.addConfigValue("foo", "bar", "5");
CHECK_THROWS(config.validate());
CHECK_THROWS(config.validateRequiredFields());
CHECK_NOTHROW(config.addConfigValue("goo", "bar", "6"));
CHECK_NOTHROW(config.validate());
CHECK_NOTHROW(config.validateRequiredFields());
CHECK(config.getConfigValue<int>("foo", "bar") == 5);
CHECK(config.getConfigValue<int>("goo", "bar") == 6);