summaryrefslogtreecommitdiff
path: root/test/buildtool/common
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-10 18:51:20 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-13 14:41:00 +0200
commitf60d39620b29aeaf1addeb244bdd6e15ddf4894c (patch)
tree2617d65884c975b3fc63dd48e58242ec36138246 /test/buildtool/common
parented8f24fb246142ffaa88707ae86b53c34df82986 (diff)
downloadjustbuild-f60d39620b29aeaf1addeb244bdd6e15ddf4894c.tar.gz
Rename Compatibility class to ProtocolTraits
...and move it to the common stage.
Diffstat (limited to 'test/buildtool/common')
-rw-r--r--test/buildtool/common/TARGETS4
-rw-r--r--test/buildtool/common/action_description.test.cpp5
-rw-r--r--test/buildtool/common/artifact_description.test.cpp42
3 files changed, 31 insertions, 20 deletions
diff --git a/test/buildtool/common/TARGETS b/test/buildtool/common/TARGETS
index ef1fff25..1355af3f 100644
--- a/test/buildtool/common/TARGETS
+++ b/test/buildtool/common/TARGETS
@@ -9,9 +9,9 @@
, ["@", "src", "src/buildtool/common", "artifact_description"]
, ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/common", "artifact_digest_factory"]
+ , ["@", "src", "src/buildtool/common", "protocol_traits"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
- , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "stage": ["test", "buildtool", "common"]
}
@@ -25,8 +25,8 @@
, ["@", "json", "", "json"]
, ["@", "src", "src/buildtool/common", "action_description"]
, ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "protocol_traits"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
- , ["@", "src", "src/buildtool/compatibility", "compatibility"]
]
, "stage": ["test", "buildtool", "common"]
}
diff --git a/test/buildtool/common/action_description.test.cpp b/test/buildtool/common/action_description.test.cpp
index 7d5a72d7..504f6aa3 100644
--- a/test/buildtool/common/action_description.test.cpp
+++ b/test/buildtool/common/action_description.test.cpp
@@ -20,7 +20,7 @@
#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/common/protocol_traits.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
[[nodiscard]] static inline auto GetHashType(bool compatible) noexcept
@@ -45,7 +45,8 @@ TEST_CASE("From JSON", "[action_description]") {
desc.Inputs()}
.ToJson();
- auto const hash_type = GetHashType(Compatibility::IsCompatible());
+ auto const hash_type =
+ GetHashType(ProtocolTraits::Instance().IsCompatible());
SECTION("Parse full action") {
auto description = ActionDescription::FromJson(hash_type, "id", json);
REQUIRE(description);
diff --git a/test/buildtool/common/artifact_description.test.cpp b/test/buildtool/common/artifact_description.test.cpp
index a05baa66..99a24964 100644
--- a/test/buildtool/common/artifact_description.test.cpp
+++ b/test/buildtool/common/artifact_description.test.cpp
@@ -22,12 +22,12 @@
#include "src/buildtool/common/artifact.hpp"
#include "src/buildtool/common/artifact_digest.hpp"
#include "src/buildtool/common/artifact_digest_factory.hpp"
-#include "src/buildtool/compatibility/compatibility.hpp"
+#include "src/buildtool/common/protocol_traits.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/object_type.hpp"
static auto NamedDigest(std::string const& str) -> ArtifactDigest {
- HashFunction const hash_function{Compatibility::IsCompatible()
+ HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible()
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
return ArtifactDigestFactory::HashDataAs<ObjectType::File>(hash_function,
@@ -50,7 +50,8 @@ TEST_CASE("Local artifact", "[artifact_description]") {
auto local_desc = ArtifactDescription::CreateLocal(
std::filesystem::path{"local_path"}, "repo");
auto from_json = ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), local_desc.ToJson());
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ local_desc.ToJson());
CHECK(local_desc == *from_json);
}
@@ -59,21 +60,24 @@ TEST_CASE("Known artifact", "[artifact_description]") {
auto known_desc = ArtifactDescription::CreateKnown(
NamedDigest("f_fake_hash"), ObjectType::File);
auto from_json = ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), known_desc.ToJson());
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ known_desc.ToJson());
CHECK(known_desc == *from_json);
}
SECTION("Executable object") {
auto known_desc = ArtifactDescription::CreateKnown(
NamedDigest("x_fake_hash"), ObjectType::Executable);
auto from_json = ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), known_desc.ToJson());
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ known_desc.ToJson());
CHECK(known_desc == *from_json);
}
SECTION("Symlink object") {
auto known_desc = ArtifactDescription::CreateKnown(
NamedDigest("l_fake_hash"), ObjectType::Symlink);
auto from_json = ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), known_desc.ToJson());
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ known_desc.ToJson());
CHECK(known_desc == *from_json);
}
}
@@ -82,7 +86,8 @@ TEST_CASE("Action artifact", "[artifact_description]") {
auto action_desc = ArtifactDescription::CreateAction(
"action_id", std::filesystem::path{"out_path"});
auto from_json = ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), action_desc.ToJson());
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ action_desc.ToJson());
CHECK(action_desc == *from_json);
}
@@ -93,7 +98,8 @@ TEST_CASE("From JSON", "[artifact_description]") {
.ToJson();
auto action = ArtifactDescription::CreateAction("id", "output").ToJson();
- auto const hash_type = GetHashType(Compatibility::IsCompatible());
+ auto const hash_type =
+ GetHashType(ProtocolTraits::Instance().IsCompatible());
SECTION("Parse artifacts") {
CHECK(ArtifactDescription::FromJson(hash_type, local));
CHECK(ArtifactDescription::FromJson(hash_type, known));
@@ -172,10 +178,10 @@ TEST_CASE("Description missing mandatory key/value pair",
"[artifact_description]") {
nlohmann::json const missing_type = {{"data", {{"path", "some/path"}}}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), missing_type));
+ GetHashType(ProtocolTraits::Instance().IsCompatible()), missing_type));
nlohmann::json const missing_data = {{"type", "LOCAL"}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), missing_data));
+ GetHashType(ProtocolTraits::Instance().IsCompatible()), missing_data));
}
TEST_CASE("Local artifact description contains incorrect value for \"data\"",
@@ -183,7 +189,8 @@ TEST_CASE("Local artifact description contains incorrect value for \"data\"",
nlohmann::json const local_art_missing_path = {
{"type", "LOCAL"}, {"data", nlohmann::json::object()}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), local_art_missing_path));
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ local_art_missing_path));
}
TEST_CASE("Known artifact description contains incorrect value for \"data\"",
@@ -195,14 +202,15 @@ TEST_CASE("Known artifact description contains incorrect value for \"data\"",
{"type", "KNOWN"},
{"data", {{"size", 15}, {"file_type", file_type}}}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), known_art_missing_id));
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ known_art_missing_id));
}
SECTION("missing \"size\"") {
nlohmann::json const known_art_missing_size = {
{"type", "KNOWN"},
{"data", {{"id", "known_input"}, {"file_type", file_type}}}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()),
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
known_art_missing_size));
}
SECTION("missing \"file_type\"") {
@@ -210,7 +218,7 @@ TEST_CASE("Known artifact description contains incorrect value for \"data\"",
{"type", "KNOWN"}, {"data", {{"id", "known_input"}, {"size", 15}}}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()),
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
known_art_missing_file_type));
}
}
@@ -220,10 +228,12 @@ TEST_CASE("Action artifact description contains incorrect value for \"data\"",
nlohmann::json const action_art_missing_id = {
{"type", "ACTION"}, {"data", {{"path", "output/path"}}}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), action_art_missing_id));
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ action_art_missing_id));
nlohmann::json const action_art_missing_path = {
{"type", "ACTION"}, {"data", {{"id", "action_id"}}}};
CHECK(not ArtifactDescription::FromJson(
- GetHashType(Compatibility::IsCompatible()), action_art_missing_path));
+ GetHashType(ProtocolTraits::Instance().IsCompatible()),
+ action_art_missing_path));
}