76 lines
3.6 KiB
C++
76 lines
3.6 KiB
C++
#include <iostream>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
#include "catch.hpp"
|
|
|
|
#include "daggy/Utilities.hpp"
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
TEST_CASE("Parameter Parsing", "[utilities_parse_parameters]") {
|
|
SECTION("Basic Parse") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name"})"};
|
|
auto params = daggy::parseParameters(testParams);
|
|
REQUIRE(params.size() == 2);
|
|
REQUIRE(std::holds_alternative<std::vector<std::string>>(params["{{DATE}}"]));
|
|
REQUIRE(std::holds_alternative<std::string>(params["{{SOURCE}}"]));
|
|
}
|
|
SECTION("Invalid JSON") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name")"};
|
|
REQUIRE_THROWS(daggy::parseParameters(testParams));
|
|
}
|
|
SECTION("Non-string Keys") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], 6: "name"})"};
|
|
REQUIRE_THROWS(daggy::parseParameters(testParams));
|
|
}
|
|
SECTION("Non-array/Non-string values") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": {"name": "kevin"}})"};
|
|
REQUIRE_THROWS(daggy::parseParameters(testParams));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Parameter Expansion", "[utilities_parameter_expansion]") {
|
|
SECTION("Basic Parse") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name", "TYPE": ["a", "b", "c"]})"};
|
|
auto params = daggy::parseParameters(testParams);
|
|
std::vector<std::string> cmd{"/usr/bin/echo", "{{DATE}}", "{{SOURCE}}", "{{TYPE}}"};
|
|
auto allCmds = daggy::expandCommands(cmd, params);
|
|
|
|
REQUIRE(allCmds.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::parseParameters(testParams);
|
|
std::vector<std::string> cmd{"/usr/bin/echo", "{{DATE}}", "{{SOURCE}}"};
|
|
auto allCmds = daggy::expandCommands(cmd, params);
|
|
|
|
// TYPE isn't used, so it's just |DATE| * |SOURCE|
|
|
REQUIRE(allCmds.size() == 2);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Building Tasks", "[utilities_build_tasks]") {
|
|
SECTION("Build with no expansion") {
|
|
std::string testTasks = R"([{"name": "A", "command": ["/bin/echo", "A"], "children": ["C"]}, {"name": "B", "command": ["/bin/echo", "B"], "children": ["C"]},{"name": "C", "command": ["/bin/echo", "C"]}])";
|
|
auto tasks = daggy::buildTasks(testTasks);
|
|
REQUIRE(tasks.size() == 3);
|
|
}
|
|
|
|
SECTION("Build with expansion") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name"})"};
|
|
auto params = daggy::parseParameters(testParams);
|
|
std::string testTasks = R"([{"name": "A", "command": ["/bin/echo", "A"], "children": ["B"]}, {"name": "B", "command": ["/bin/echo", "B", "{{SOURCE}}", "{{DATE}}"], "children": ["C"]},{"name": "C", "command": ["/bin/echo", "C"]}])";
|
|
auto tasks = daggy::buildTasks(testTasks, params);
|
|
REQUIRE(tasks.size() == 4);
|
|
}
|
|
|
|
SECTION("Build with expansion using parents instead of children") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name"})"};
|
|
auto params = daggy::parseParameters(testParams);
|
|
std::string testTasks = R"([{"name": "A", "command": ["/bin/echo", "A"]}, {"name": "B", "command": ["/bin/echo", "B", "{{SOURCE}}", "{{DATE}}"], "parents": ["A"]},{"name": "C", "command": ["/bin/echo", "C"], "parents": ["A"]}])";
|
|
auto tasks = daggy::buildTasks(testTasks, params);
|
|
REQUIRE(tasks.size() == 4);
|
|
}
|
|
} |