mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-04 20:05:51 +00:00
fix: Check result of parsing config (#1829)
This commit is contained in:
@@ -35,7 +35,7 @@ namespace app {
|
|||||||
* @return true if config values are all correct, false otherwise
|
* @return true if config values are all correct, false otherwise
|
||||||
*/
|
*/
|
||||||
inline bool
|
inline bool
|
||||||
verifyConfig(std::string_view configPath)
|
parseConfig(std::string_view configPath)
|
||||||
{
|
{
|
||||||
using namespace util::config;
|
using namespace util::config;
|
||||||
|
|
||||||
@@ -54,4 +54,5 @@ verifyConfig(std::string_view configPath)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
|||||||
@@ -41,15 +41,14 @@ try {
|
|||||||
return action.apply(
|
return action.apply(
|
||||||
[](app::CliArgs::Action::Exit const& exit) { return exit.exitCode; },
|
[](app::CliArgs::Action::Exit const& exit) { return exit.exitCode; },
|
||||||
[](app::CliArgs::Action::VerifyConfig const& verify) {
|
[](app::CliArgs::Action::VerifyConfig const& verify) {
|
||||||
if (app::verifyConfig(verify.configPath)) {
|
if (app::parseConfig(verify.configPath)) {
|
||||||
std::cout << "Config " << verify.configPath << " is correct" << "\n";
|
std::cout << "Config " << verify.configPath << " is correct" << "\n";
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
},
|
},
|
||||||
[](app::CliArgs::Action::Run const& run) {
|
[](app::CliArgs::Action::Run const& run) {
|
||||||
auto const res = app::verifyConfig(run.configPath);
|
if (not app::parseConfig(run.configPath))
|
||||||
if (res != EXIT_SUCCESS)
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
util::LogService::init(gClioConfig);
|
util::LogService::init(gClioConfig);
|
||||||
@@ -57,8 +56,7 @@ try {
|
|||||||
return clio.run(run.useNgWebServer);
|
return clio.run(run.useNgWebServer);
|
||||||
},
|
},
|
||||||
[](app::CliArgs::Action::Migrate const& migrate) {
|
[](app::CliArgs::Action::Migrate const& migrate) {
|
||||||
auto const res = app::verifyConfig(migrate.configPath);
|
if (not app::parseConfig(migrate.configPath))
|
||||||
if (res != EXIT_SUCCESS)
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
util::LogService::init(gClioConfig);
|
util::LogService::init(gClioConfig);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ TEST(VerifyConfigTest, InvalidConfig)
|
|||||||
auto const tmpConfigFile = TmpFile(kJSON_DATA);
|
auto const tmpConfigFile = TmpFile(kJSON_DATA);
|
||||||
|
|
||||||
// false because json data(kJSON_DATA) is not compatible with current configDefintion
|
// false because json data(kJSON_DATA) is not compatible with current configDefintion
|
||||||
EXPECT_FALSE(verifyConfig(tmpConfigFile.path));
|
EXPECT_FALSE(parseConfig(tmpConfigFile.path));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifyConfigTest, ValidConfig)
|
TEST(VerifyConfigTest, ValidConfig)
|
||||||
@@ -46,12 +46,12 @@ TEST(VerifyConfigTest, ValidConfig)
|
|||||||
auto const tmpConfigFile = TmpFile(kVALID_JSON_DATA);
|
auto const tmpConfigFile = TmpFile(kVALID_JSON_DATA);
|
||||||
|
|
||||||
// current example config should always be compatible with configDefinition
|
// current example config should always be compatible with configDefinition
|
||||||
EXPECT_TRUE(verifyConfig(tmpConfigFile.path));
|
EXPECT_TRUE(parseConfig(tmpConfigFile.path));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifyConfigTest, ConfigFileNotExist)
|
TEST(VerifyConfigTest, ConfigFileNotExist)
|
||||||
{
|
{
|
||||||
EXPECT_FALSE(verifyConfig("doesn't exist Config File"));
|
EXPECT_FALSE(parseConfig("doesn't exist Config File"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(VerifyConfigTest, InvalidJsonFile)
|
TEST(VerifyConfigTest, InvalidJsonFile)
|
||||||
@@ -65,5 +65,5 @@ TEST(VerifyConfigTest, InvalidJsonFile)
|
|||||||
})";
|
})";
|
||||||
auto const tmpConfigFile = TmpFile(kINVALID_JSON);
|
auto const tmpConfigFile = TmpFile(kINVALID_JSON);
|
||||||
|
|
||||||
EXPECT_FALSE(verifyConfig(tmpConfigFile.path));
|
EXPECT_FALSE(parseConfig(tmpConfigFile.path));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user