[tests] Unit tests for network-specific config entries
This commit is contained in:
parent
68797e20f4
commit
608415d4e6
1 changed files with 34 additions and 3 deletions
|
@ -187,6 +187,7 @@ BOOST_AUTO_TEST_CASE(util_FormatISO8601Time)
|
|||
|
||||
struct TestArgsManager : public ArgsManager
|
||||
{
|
||||
TestArgsManager() { m_network_only_args.clear(); }
|
||||
std::map<std::string, std::vector<std::string> >& GetOverrideArgs() { return m_override_args; }
|
||||
std::map<std::string, std::vector<std::string> >& GetConfigArgs() { return m_config_args; }
|
||||
void ReadConfigString(const std::string str_config)
|
||||
|
@ -198,6 +199,11 @@ struct TestArgsManager : public ArgsManager
|
|||
}
|
||||
ReadConfigStream(streamConfig);
|
||||
}
|
||||
void SetNetworkOnlyArg(const std::string arg)
|
||||
{
|
||||
LOCK(cs_args);
|
||||
m_network_only_args.insert(arg);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_ParseParameters)
|
||||
|
@ -327,6 +333,7 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
|
|||
"\n"
|
||||
"[sec1]\n"
|
||||
"ccc=extend2\n"
|
||||
"d=eee\n"
|
||||
"h=1\n"
|
||||
"[sec2]\n"
|
||||
"ccc=extend3\n"
|
||||
|
@ -336,10 +343,10 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
|
|||
|
||||
test_args.ReadConfigString(str_config);
|
||||
// expectation: a, b, ccc, d, fff, ggg, h, i end up in map
|
||||
// so do sec1.ccc, sec1.h, sec2.ccc, sec2.iii
|
||||
// so do sec1.ccc, sec1.d, sec1.h, sec2.ccc, sec2.iii
|
||||
|
||||
BOOST_CHECK(test_args.GetOverrideArgs().empty());
|
||||
BOOST_CHECK(test_args.GetConfigArgs().size() == 12);
|
||||
BOOST_CHECK(test_args.GetConfigArgs().size() == 13);
|
||||
|
||||
BOOST_CHECK(test_args.GetConfigArgs().count("-a")
|
||||
&& test_args.GetConfigArgs().count("-b")
|
||||
|
@ -429,12 +436,13 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
|
|||
// same as original
|
||||
BOOST_CHECK(test_args.GetArg("-a", "xxx") == ""
|
||||
&& test_args.GetArg("-b", "xxx") == "1"
|
||||
&& test_args.GetArg("-d", "xxx") == "e"
|
||||
&& test_args.GetArg("-fff", "xxx") == "0"
|
||||
&& test_args.GetArg("-ggg", "xxx") == "1"
|
||||
&& test_args.GetArg("-zzz", "xxx") == "xxx"
|
||||
&& test_args.GetArg("-iii", "xxx") == "xxx"
|
||||
);
|
||||
// d is overridden
|
||||
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee");
|
||||
// section-specific setting
|
||||
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1");
|
||||
// section takes priority for multiple values
|
||||
|
@ -463,6 +471,29 @@ BOOST_AUTO_TEST_CASE(util_ReadConfigStream)
|
|||
const std::vector<std::string> sec2_ccc_expected = {"extend3","argument","multiple"};
|
||||
const auto& sec2_ccc_res = test_args.GetArgs("-ccc");
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(sec2_ccc_res.begin(), sec2_ccc_res.end(), sec2_ccc_expected.begin(), sec2_ccc_expected.end());
|
||||
|
||||
// Test section only options
|
||||
|
||||
test_args.SetNetworkOnlyArg("-d");
|
||||
test_args.SetNetworkOnlyArg("-ccc");
|
||||
test_args.SetNetworkOnlyArg("-h");
|
||||
|
||||
test_args.SelectConfigNetwork(CBaseChainParams::MAIN);
|
||||
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "e");
|
||||
BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2);
|
||||
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0");
|
||||
|
||||
test_args.SelectConfigNetwork("sec1");
|
||||
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "eee");
|
||||
BOOST_CHECK(test_args.GetArgs("-d").size() == 1);
|
||||
BOOST_CHECK(test_args.GetArgs("-ccc").size() == 2);
|
||||
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "1");
|
||||
|
||||
test_args.SelectConfigNetwork("sec2");
|
||||
BOOST_CHECK(test_args.GetArg("-d", "xxx") == "xxx");
|
||||
BOOST_CHECK(test_args.GetArgs("-d").size() == 0);
|
||||
BOOST_CHECK(test_args.GetArgs("-ccc").size() == 1);
|
||||
BOOST_CHECK(test_args.GetArg("-h", "xxx") == "0");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_GetArg)
|
||||
|
|
Loading…
Reference in a new issue