52 lines
2.7 KiB
C++
52 lines
2.7 KiB
C++
#include <iostream>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
#include "daggy/Serialization.hpp"
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
TEST_CASE("Deserialize Parameters", "[deserialize_parameters]") {
|
|
SECTION("Basic Parse") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": "name"})"};
|
|
auto params = daggy::parametersFromJSON(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::parametersFromJSON(testParams));
|
|
}SECTION("Non-string Keys") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], 6: "name"})"};
|
|
REQUIRE_THROWS(daggy::parametersFromJSON(testParams));
|
|
}SECTION("Non-array/Non-string values") {
|
|
std::string testParams{R"({"DATE": ["2021-05-06", "2021-05-07" ], "SOURCE": {"name": "kevin"}})"};
|
|
REQUIRE_THROWS(daggy::parametersFromJSON(testParams));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Task Deserialization", "[deserialize_task]") {
|
|
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::tasksFromJSON(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::parametersFromJSON(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::tasksFromJSON(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::parametersFromJSON(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::tasksFromJSON(testTasks, params);
|
|
REQUIRE(tasks.size() == 4);
|
|
}
|
|
} |