Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit c9a2fa2

Browse files
committed
Generalize testing and fix createHTTPRepo function
1 parent 4213823 commit c9a2fa2

3 files changed

Lines changed: 43 additions & 29 deletions

File tree

src/functions.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,26 @@ bool exists(const std::filesystem::path& path)
387387

388388
void createHTTPRepo(const std::string_view repoName)
389389
{
390-
auto runner = cloyster::Singleton<BaseRunner>::get();
390+
const auto confPath = fmt::format("/etc/httpd/conf.d/{}.conf", repoName);
391+
if (exists(confPath)) {
392+
LOG_WARN("Skipping the creation of HTTP repository, {} already exists", confPath);
393+
return;
394+
}
391395
auto repoFolder = fmt::format("/var/www/html/{}", repoName);
396+
LOG_INFO("Creating HTTP repository {} at {}", confPath, repoFolder);
397+
auto runner = cloyster::Singleton<BaseRunner>::get();
392398
cloyster::createDirectory(repoFolder);
393399
cloyster::installFile(
394-
fmt::format("/etc/httpd.d/conf.d/{}.conf", repoName),
400+
confPath,
395401
fmt::format(
396-
R"(Alias "/rpmrepo" "{0}"
397-
<Directory "{0}">
402+
R"(<Directory "{0}">
398403
Options +Indexes +FollowSymLinks
399404
AllowOverride None
400405
Require all granted
401406
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
402407
</Directory>
403408
)", repoFolder));
409+
404410
runner->checkCommand("apachectl configtest");
405411
runner->checkCommand("systemctl restart httpd");
406412
}

src/main.cpp

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ int main(int argc, const char** argv)
125125
"-u, --unattended", unattended, "Perform an unattended installation");
126126

127127
#ifndef NDEBUG
128-
std::string loadConfFile{};
129-
app.add_option("--test-conf-file", loadConfFile,
130-
"Hook for testing configuration file loading");
131128

132129
std::string testCommand{};
133-
app.add_option("--test-command", testCommand,
134-
"Run a command for testing purposes");
130+
app.add_option("--test", testCommand,
131+
"Run a command for testing purposes");
132+
133+
std::string testCommandArgs{};
134+
app.add_option("--test-args", testCommandArgs,
135+
"Run a command for testing purposes with arguments");
135136
#endif
136137

137138
CLI11_PARSE(app, argc, argv)
@@ -148,16 +149,6 @@ int main(int argc, const char** argv)
148149
}
149150
}());
150151

151-
#ifndef NDEBUG
152-
if (!loadConfFile.empty()) {
153-
LOG_INFO("Loading file {}", loadConfFile);
154-
auto file = cloyster::services::files::KeyFile(loadConfFile);
155-
LOG_INFO("Groups: {}", fmt::join(file.getGroups(), ","));
156-
LOG_INFO("Contents: {}", file.toData());
157-
return EXIT_SUCCESS;
158-
}
159-
#endif
160-
161152
if (cloyster::showVersion) {
162153
fmt::print("{}: Version {}\n", productName, productVersion);
163154
return EXIT_SUCCESS;
@@ -177,6 +168,11 @@ int main(int argc, const char** argv)
177168

178169
cloyster::checkEffectiveUserId();
179170

171+
// --test implies --unattended
172+
if (!testCommand.empty()) {
173+
unattended = true;
174+
}
175+
180176
if (cloyster::dryRun) {
181177
LOG_INFO("Dry run enabled.");
182178
} else {
@@ -216,7 +212,7 @@ int main(int argc, const char** argv)
216212
model->printData();
217213
#endif
218214

219-
if (cloyster::enableTUI) {
215+
if (cloyster::enableTUI && testCommand.empty()) {
220216
// Entrypoint; if the view is constructed it will start the TUI.
221217
auto view = std::make_unique<Newt>();
222218
auto presenter
@@ -233,15 +229,28 @@ int main(int argc, const char** argv)
233229
initializeSingletons(std::move(model));
234230

235231
#ifndef NDEBUG
236-
if (!testCommand.empty()) {
237-
LOG_INFO("Running test command {}", testCommand);
238-
auto runner = cloyster::Singleton<cloyster::BaseRunner>::get();
239-
runner->checkCommand(testCommand);
240-
return EXIT_SUCCESS;
241-
}
232+
// Run The Test Commands and exit
233+
if (!testCommand.empty()) {
234+
LOG_INFO("Running test command {} {} ", testCommand, testCommandArgs);
235+
auto runner = cloyster::Singleton<cloyster::BaseRunner>::get();
236+
if (testCommand == "checkCommand") {
237+
runner->checkCommand(testCommandArgs);
238+
} else if (testCommand == "createHTTPRepo") {
239+
assert(testCommandArgs.size() > 0);
240+
cloyster::createHTTPRepo(testCommandArgs);
241+
} else if (testCommand == "keyFile") {
242+
assert(testCommandArgs.size() > 0);
243+
LOG_INFO("Loading file {}", testCommandArgs);
244+
auto file = cloyster::services::files::KeyFile(testCommandArgs);
245+
LOG_INFO("Groups: {}", fmt::join(file.getGroups(), ","));
246+
LOG_INFO("Contents: {}", file.toData());
247+
} else {
248+
LOG_ERROR("Invalid test command {}", testCommand);
249+
return EXIT_FAILURE;
250+
}
251+
return EXIT_SUCCESS;
252+
}
242253
#endif
243-
244-
245254
std::unique_ptr<Execution> executionEngine
246255
= std::make_unique<cloyster::services::Shell>();
247256

src/services/repos.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <algorithm>
77
#include <filesystem>
88
#include <functional>
9-
#include <glibmm/keyfile.h>
109
#include <memory>
1110
#include <ranges>
1211
#include <sstream>

0 commit comments

Comments
 (0)