Skip to content

Commit

Permalink
fix: Check result of parsing config (#1829)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuznetsss authored Jan 14, 2025
1 parent 2cf849d commit 7834b63
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/app/VerifyConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace app {
* @return true if config values are all correct, false otherwise
*/
inline bool
verifyConfig(std::string_view configPath)
parseConfig(std::string_view configPath)
{
using namespace util::config;

Expand All @@ -54,4 +54,5 @@ verifyConfig(std::string_view configPath)
}
return true;
}

} // namespace app
8 changes: 3 additions & 5 deletions src/main/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ try {
return action.apply(
[](app::CliArgs::Action::Exit const& exit) { return exit.exitCode; },
[](app::CliArgs::Action::VerifyConfig const& verify) {
if (app::verifyConfig(verify.configPath)) {
if (app::parseConfig(verify.configPath)) {
std::cout << "Config " << verify.configPath << " is correct" << "\n";
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
},
[](app::CliArgs::Action::Run const& run) {
auto const res = app::verifyConfig(run.configPath);
if (res != EXIT_SUCCESS)
if (not app::parseConfig(run.configPath))
return EXIT_FAILURE;

util::LogService::init(gClioConfig);
app::ClioApplication clio{gClioConfig};
return clio.run(run.useNgWebServer);
},
[](app::CliArgs::Action::Migrate const& migrate) {
auto const res = app::verifyConfig(migrate.configPath);
if (res != EXIT_SUCCESS)
if (not app::parseConfig(migrate.configPath))
return EXIT_FAILURE;

util::LogService::init(gClioConfig);
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/app/VerifyConfigTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(VerifyConfigTest, InvalidConfig)
auto const tmpConfigFile = TmpFile(kJSON_DATA);

// 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)
Expand All @@ -46,12 +46,12 @@ TEST(VerifyConfigTest, ValidConfig)
auto const tmpConfigFile = TmpFile(kVALID_JSON_DATA);

// current example config should always be compatible with configDefinition
EXPECT_TRUE(verifyConfig(tmpConfigFile.path));
EXPECT_TRUE(parseConfig(tmpConfigFile.path));
}

TEST(VerifyConfigTest, ConfigFileNotExist)
{
EXPECT_FALSE(verifyConfig("doesn't exist Config File"));
EXPECT_FALSE(parseConfig("doesn't exist Config File"));
}

TEST(VerifyConfigTest, InvalidJsonFile)
Expand All @@ -65,5 +65,5 @@ TEST(VerifyConfigTest, InvalidJsonFile)
})";
auto const tmpConfigFile = TmpFile(kINVALID_JSON);

EXPECT_FALSE(verifyConfig(tmpConfigFile.path));
EXPECT_FALSE(parseConfig(tmpConfigFile.path));
}

0 comments on commit 7834b63

Please sign in to comment.