diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-01 17:44:23 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 14:52:07 +0200 |
commit | 2bc6d309c00161b2315b9f98645810699fff3126 (patch) | |
tree | 8185d375463e79b39485448920fa68cca2a206a2 /test/buildtool/common/action_description.test.cpp | |
parent | abae1d3c8032fec872bda44de7f7d754654cf201 (diff) | |
download | justbuild-2bc6d309c00161b2315b9f98645810699fff3126.tar.gz |
Use HashFunction::Type to deserialize ArtifactDescription
Diffstat (limited to 'test/buildtool/common/action_description.test.cpp')
-rw-r--r-- | test/buildtool/common/action_description.test.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/test/buildtool/common/action_description.test.cpp b/test/buildtool/common/action_description.test.cpp index eab2cc48..7d5a72d7 100644 --- a/test/buildtool/common/action_description.test.cpp +++ b/test/buildtool/common/action_description.test.cpp @@ -20,6 +20,14 @@ #include "nlohmann/json.hpp" #include "src/buildtool/common/action.hpp" #include "src/buildtool/common/artifact_description.hpp" +#include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/crypto/hash_function.hpp" + +[[nodiscard]] static inline auto GetHashType(bool compatible) noexcept + -> HashFunction::Type { + return compatible ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; +} TEST_CASE("From JSON", "[action_description]") { using path = std::filesystem::path; @@ -37,56 +45,57 @@ TEST_CASE("From JSON", "[action_description]") { desc.Inputs()} .ToJson(); + auto const hash_type = GetHashType(Compatibility::IsCompatible()); SECTION("Parse full action") { - auto description = ActionDescription::FromJson("id", json); + auto description = ActionDescription::FromJson(hash_type, "id", json); REQUIRE(description); CHECK((*description)->ToJson() == json); } SECTION("Parse action without optional input") { json["input"] = nlohmann::json::object(); - CHECK(ActionDescription::FromJson("id", json)); + CHECK(ActionDescription::FromJson(hash_type, "id", json)); json["input"] = nlohmann::json::array(); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); json.erase("input"); - CHECK(ActionDescription::FromJson("id", json)); + CHECK(ActionDescription::FromJson(hash_type, "id", json)); } SECTION("Parse action without optional env") { json["env"] = nlohmann::json::object(); - CHECK(ActionDescription::FromJson("id", json)); + CHECK(ActionDescription::FromJson(hash_type, "id", json)); json["env"] = nlohmann::json::array(); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); json.erase("env"); - CHECK(ActionDescription::FromJson("id", json)); + CHECK(ActionDescription::FromJson(hash_type, "id", json)); } SECTION("Parse action without mandatory outputs") { json["output"] = nlohmann::json::array(); json["output_dirs"] = nlohmann::json::array(); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); json["output"] = nlohmann::json::object(); json["output_dirs"] = nlohmann::json::object(); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); json.erase("output"); json.erase("output_dirs"); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); } SECTION("Parse action without mandatory command") { json["command"] = nlohmann::json::array(); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); json["command"] = nlohmann::json::object(); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); json.erase("command"); - CHECK_FALSE(ActionDescription::FromJson("id", json)); + CHECK_FALSE(ActionDescription::FromJson(hash_type, "id", json)); } } |