mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-05 21:20:38 +00:00
13b01c86a6
-- Moved all RPCServer initialization logic to rpcserver constructor -- Fixed config logic, fxn binding to rpc address, fxn adding rpc cats -- router hive failed CI/CD resulting from outdated reference to rpcBindAddr -- ipc socket as default hidden from windows (for now) refactored config endpoint - added rpc call script (contrib/omq-rpc.py) - added new fxns to .ini config stuff - added delete .ini file functionality to config endpoint - added edge case control for config endpoint add commented out line in clang-form for header reorg later
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#include <llarp/config/ini.hpp>
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
TEST_CASE("ConfigParser", "[config]")
|
|
{
|
|
llarp::ConfigParser parser;
|
|
|
|
SECTION("Parse empty")
|
|
{
|
|
REQUIRE(parser.LoadFromStr(""));
|
|
}
|
|
|
|
SECTION("Parse one section")
|
|
{
|
|
llarp::ConfigParser::SectionValues_t sect;
|
|
// this is an anti pattern don't write this kind of code with configpaser
|
|
auto assertVisit = [§](const auto& section) -> bool {
|
|
sect = section;
|
|
return true;
|
|
};
|
|
REQUIRE(parser.LoadFromStr("[test]\nkey=val \n"));
|
|
REQUIRE(parser.VisitSection("test", assertVisit));
|
|
auto itr = sect.find("notfound");
|
|
REQUIRE(itr == sect.end());
|
|
itr = sect.find("key");
|
|
REQUIRE(itr != sect.end());
|
|
REQUIRE(itr->second == "val");
|
|
}
|
|
|
|
SECTION("Parse section duplicate keys")
|
|
{
|
|
REQUIRE(parser.LoadFromStr("[test]\nkey1=val1\nkey1=val2"));
|
|
size_t num = 0;
|
|
auto visit = [&num](const auto& section) -> bool {
|
|
num = section.count("key1");
|
|
return true;
|
|
};
|
|
REQUIRE(parser.VisitSection("test", visit));
|
|
REQUIRE(num == size_t(2));
|
|
}
|
|
|
|
SECTION("No key")
|
|
{
|
|
REQUIRE_THROWS(parser.LoadFromStr("[test]\n=1090\n"));
|
|
}
|
|
|
|
SECTION("Parse invalid")
|
|
{
|
|
REQUIRE_THROWS(
|
|
parser.LoadFromStr("srged5ghe5\nf34wtge5\nw34tgfs4ygsd5yg=4;\n#"
|
|
"g4syhgd5\n"));
|
|
}
|
|
|
|
parser.Clear();
|
|
}
|