mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -37,6 +37,12 @@ struct TmpFile {
|
||||
ofs << content;
|
||||
}
|
||||
|
||||
static TmpFile
|
||||
empty()
|
||||
{
|
||||
return TmpFile{""};
|
||||
}
|
||||
|
||||
TmpFile(TmpFile const&) = delete;
|
||||
TmpFile(TmpFile&& other) : path{std::move(other.path)}
|
||||
{
|
||||
|
||||
@@ -18,12 +18,19 @@
|
||||
//==============================================================================
|
||||
|
||||
#include "app/CliArgs.hpp"
|
||||
#include "util/TmpFile.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigDescription.hpp"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
using namespace app;
|
||||
@@ -145,3 +152,71 @@ TEST_F(CliArgsTests, Parse_VerifyConfig)
|
||||
returnCode
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(CliArgsTests, Parse_ConfigDescriptionInvalidPath)
|
||||
{
|
||||
using namespace util::config;
|
||||
std::array argv{"clio_server", "--config-description", ""};
|
||||
auto const action = CliArgs::parse(argv.size(), argv.data());
|
||||
EXPECT_CALL(onExitMock, Call).WillOnce([](CliArgs::Action::Exit const& exit) { return exit.exitCode; });
|
||||
|
||||
EXPECT_EQ(
|
||||
action.apply(
|
||||
onRunMock.AsStdFunction(),
|
||||
onExitMock.AsStdFunction(),
|
||||
onMigrateMock.AsStdFunction(),
|
||||
onVerifyMock.AsStdFunction()
|
||||
),
|
||||
EXIT_FAILURE
|
||||
);
|
||||
}
|
||||
|
||||
struct CliArgsTestsWithTmpFile : CliArgsTests {
|
||||
TmpFile tmpFile = TmpFile::empty();
|
||||
};
|
||||
|
||||
TEST_F(CliArgsTestsWithTmpFile, Parse_ConfigDescription)
|
||||
{
|
||||
std::array argv{"clio_server", "--config-description", tmpFile.path.c_str()};
|
||||
auto const action = CliArgs::parse(argv.size(), argv.data());
|
||||
EXPECT_CALL(onExitMock, Call).WillOnce([](CliArgs::Action::Exit const& exit) { return exit.exitCode; });
|
||||
|
||||
// user provide config markdown file name as well
|
||||
ASSERT_TRUE(std::filesystem::exists(tmpFile.path));
|
||||
|
||||
EXPECT_EQ(
|
||||
action.apply(
|
||||
onRunMock.AsStdFunction(),
|
||||
onExitMock.AsStdFunction(),
|
||||
onMigrateMock.AsStdFunction(),
|
||||
onVerifyMock.AsStdFunction()
|
||||
),
|
||||
EXIT_SUCCESS
|
||||
);
|
||||
}
|
||||
|
||||
TEST_F(CliArgsTestsWithTmpFile, Parse_ConfigDescriptionFileContent)
|
||||
{
|
||||
using namespace util::config;
|
||||
|
||||
std::ofstream file(tmpFile.path);
|
||||
ASSERT_TRUE(file.is_open());
|
||||
ClioConfigDescription::writeConfigDescriptionToFile(file);
|
||||
file.close();
|
||||
|
||||
std::ifstream inFile(tmpFile.path);
|
||||
ASSERT_TRUE(inFile.is_open());
|
||||
|
||||
std::stringstream buffer;
|
||||
buffer << inFile.rdbuf();
|
||||
inFile.close();
|
||||
|
||||
auto const fileContent = buffer.str();
|
||||
EXPECT_TRUE(fileContent.find("# Clio Config Description") != std::string::npos);
|
||||
EXPECT_TRUE(fileContent.find("This file lists all Clio Configuration definitions in detail.") != std::string::npos);
|
||||
EXPECT_TRUE(fileContent.find("## Configuration Details") != std::string::npos);
|
||||
|
||||
// all keys that exist in clio config should be listed in config description file
|
||||
for (auto const& key : gClioConfig)
|
||||
EXPECT_TRUE(fileContent.find(key.first));
|
||||
}
|
||||
|
||||
@@ -165,7 +165,10 @@ TEST(ConfigDescription, GetValues)
|
||||
{
|
||||
ClioConfigDescription const definition{};
|
||||
|
||||
EXPECT_EQ(definition.get("database.type"), "Type of database to use. Default is Scylladb.");
|
||||
EXPECT_EQ(
|
||||
definition.get("database.type"),
|
||||
"Type of database to use. We currently support Cassandra and Scylladb. We default to Scylladb."
|
||||
);
|
||||
EXPECT_EQ(definition.get("etl_sources.[].ip"), "IP address of the ETL source.");
|
||||
EXPECT_EQ(definition.get("prometheus.enabled"), "Enable or disable Prometheus metrics.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user