mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add helper to modify Env configs (RIPD-1247)
Add envconfig test helper for manipulating Env config via callables. Create new common modifiers for non-admin config, validator config and one for using different server port values.
This commit is contained in:
committed by
Scott Schurr
parent
09a1d1a593
commit
80d9b0464a
89
src/test/jtx/impl/envconfig.cpp
Normal file
89
src/test/jtx/impl/envconfig.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012-2017 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <test/jtx/envconfig.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
void
|
||||
setupConfigForUnitTests (Config& cfg)
|
||||
{
|
||||
cfg.overwrite (ConfigSection::nodeDatabase (), "type", "memory");
|
||||
cfg.overwrite (ConfigSection::nodeDatabase (), "path", "main");
|
||||
cfg.deprecatedClearSection (ConfigSection::importNodeDatabase ());
|
||||
cfg.legacy("database_path", "");
|
||||
cfg.setupControl(true, true, true);
|
||||
cfg["server"].append("port_peer");
|
||||
cfg["port_peer"].set("ip", "127.0.0.1");
|
||||
cfg["port_peer"].set("port", "8080");
|
||||
cfg["port_peer"].set("protocol", "peer");
|
||||
cfg["server"].append("port_rpc");
|
||||
cfg["port_rpc"].set("ip", "127.0.0.1");
|
||||
cfg["port_rpc"].set("port", "8081");
|
||||
cfg["port_rpc"].set("protocol", "http,ws2");
|
||||
cfg["port_rpc"].set("admin", "127.0.0.1");
|
||||
cfg["server"].append("port_ws");
|
||||
cfg["port_ws"].set("ip", "127.0.0.1");
|
||||
cfg["port_ws"].set("port", "8082");
|
||||
cfg["port_ws"].set("protocol", "ws");
|
||||
cfg["port_ws"].set("admin", "127.0.0.1");
|
||||
}
|
||||
|
||||
namespace jtx {
|
||||
|
||||
std::unique_ptr<Config>
|
||||
no_admin(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin","");
|
||||
(*cfg)["port_ws"].set("admin","");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
|
||||
|
||||
std::unique_ptr<Config>
|
||||
validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
{
|
||||
// If the config has valid validation keys then we run as a validator.
|
||||
cfg->section(SECTION_VALIDATION_SEED).append(
|
||||
std::vector<std::string>{seed.empty() ? defaultseed : seed});
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
port_increment(std::unique_ptr<Config> cfg, int increment)
|
||||
{
|
||||
for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
|
||||
{
|
||||
Section& s = (*cfg)[sectionName];
|
||||
auto const port = s.get<std::int32_t>("port");
|
||||
if (port)
|
||||
{
|
||||
s.set ("port", std::to_string(*port + increment));
|
||||
}
|
||||
}
|
||||
return cfg;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
} // ripple
|
||||
Reference in New Issue
Block a user