This paves the way for implementing daggys and other utilities. Squashed commit of the following: commit 1f77239ab3c9e44d190eef94531a39501c8c4dfe Author: Ian Roddis <gitlab@ie2r.com> Date: Mon Oct 18 16:25:02 2021 -0300 Adding README, stdout support for daggyd logging commit c2c237224e84a3be68aaa597ce98af1365e74a13 Author: Ian Roddis <gitlab@ie2r.com> Date: Mon Oct 18 16:10:29 2021 -0300 removing old daggyd commit cfea2baf61ca10c535801c5a391d2d525a1a2d04 Author: Ian Roddis <gitlab@ie2r.com> Date: Mon Oct 18 16:10:09 2021 -0300 Moving tests into their sub-project folders commit e41ca42069bea1db16dd76b6684a3f692fef6b15 Author: Ian Roddis <gitlab@ie2r.com> Date: Mon Oct 18 15:57:40 2021 -0300 Splitting out daggyd from libdaggy commit be97b146c1d2446f5c03cb78707e921f18c60bd8 Author: Ian Roddis <gitlab@ie2r.com> Date: Mon Oct 18 15:56:55 2021 -0300 Splitting out daggyd from libdaggy commit cb61e140e9d6d8832d61fb7037fd4c0ff6edad00 Author: Ian Roddis <gitlab@ie2r.com> Date: Mon Oct 18 15:49:47 2021 -0300 moving daggy to libdaggy
57 lines
1.8 KiB
C++
57 lines
1.8 KiB
C++
#include <algorithm>
|
|
#include <catch2/catch.hpp>
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
|
|
#include "daggy/Serialization.hpp"
|
|
#include "daggy/Utilities.hpp"
|
|
|
|
TEST_CASE("string_utilities", "[utilities_string]")
|
|
{
|
|
std::string test = "/this/is/{{A}}/test/{{A}}";
|
|
auto res = daggy::globalSub(test, "{{A}}", "hello");
|
|
REQUIRE(res == "/this/is/hello/test/hello");
|
|
}
|
|
|
|
TEST_CASE("string_expansion", "[utilities_parameter_expansion]")
|
|
{
|
|
SECTION("Basic expansion")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name", "TYPE": ["a", "b", "c"]})"};
|
|
auto params = daggy::configFromJSON(testParams);
|
|
std::vector<std::string> cmd{"/usr/bin/echo", "{{DATE}}", "{{SOURCE}}",
|
|
"{{TYPE}}"};
|
|
auto allCommands = daggy::interpolateValues(cmd, params);
|
|
|
|
REQUIRE(allCommands.size() == 6);
|
|
}
|
|
|
|
SECTION("Skip over unused parameters")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name", "TYPE": ["a", "b", "c"]})"};
|
|
auto params = daggy::configFromJSON(testParams);
|
|
std::vector<std::string> cmd{"/usr/bin/echo", "{{DATE}}", "{{SOURCE}}"};
|
|
auto allCommands = daggy::interpolateValues(cmd, params);
|
|
|
|
// TYPE isn't used, so it's just |DATE| * |SOURCE|
|
|
REQUIRE(allCommands.size() == 2);
|
|
}
|
|
|
|
SECTION("Expand within a command part")
|
|
{
|
|
std::string testParams{
|
|
R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": ["A", "B"], "TYPE": ["a", "b", "c"]})"};
|
|
auto params = daggy::configFromJSON(testParams);
|
|
std::vector<std::string> cmd{"/usr/bin/touch", "{{DATE}}_{{SOURCE}}"};
|
|
auto result = daggy::interpolateValues(cmd, params);
|
|
|
|
// TYPE isn't used, so it's just |DATE| * |SOURCE|
|
|
REQUIRE(result.size() == 4);
|
|
}
|
|
}
|