summaryrefslogtreecommitdiff
path: root/test/buildtool/build_engine/base_maps/source_map.test.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-12 14:28:13 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-13 14:41:00 +0200
commit5fb67de531fead44123ff30ee5cf37340fc63a0b (patch)
tree0e1c7c8810e8ee311467e5e07ebb8ff2902adf28 /test/buildtool/build_engine/base_maps/source_map.test.cpp
parentdd15af0ba4b22348e38d535aadc9fa5e929f3824 (diff)
downloadjustbuild-5fb67de531fead44123ff30ee5cf37340fc63a0b.tar.gz
Use TestHashType in tests
...instead of calling ProtocolTraits::IsCompatible
Diffstat (limited to 'test/buildtool/build_engine/base_maps/source_map.test.cpp')
-rw-r--r--test/buildtool/build_engine/base_maps/source_map.test.cpp47
1 files changed, 19 insertions, 28 deletions
diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp
index bd1e71ba..ab5323e4 100644
--- a/test/buildtool/build_engine/base_maps/source_map.test.cpp
+++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp
@@ -32,6 +32,7 @@
#include "src/buildtool/multithreading/async_map_consumer.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
#include "test/buildtool/build_engine/base_maps/test_repo.hpp"
+#include "test/utils/hermeticity/test_hash_function_type.hpp"
namespace {
@@ -89,16 +90,14 @@ auto ReadSourceTarget(EntityName const& id,
} // namespace
TEST_CASE("from file") {
+ auto const hash_type = TestHashType::ReadFromEnvironment();
+
nlohmann::json artifacts;
auto name = EntityName{"", ".", "file"};
auto consumer = [&artifacts](auto values) {
artifacts = (*values[0])->Artifacts()->ToJson();
};
- auto const hash_type = ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1;
-
SECTION("via file") {
CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false));
CHECK(artifacts["file"]["type"] == "LOCAL");
@@ -108,24 +107,22 @@ TEST_CASE("from file") {
SECTION("via git tree") {
CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true));
CHECK(artifacts["file"]["type"] == "KNOWN");
- CHECK(artifacts["file"]["data"]["id"] ==
- (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256
- : kEmptySha1));
+ CHECK(
+ artifacts["file"]["data"]["id"] ==
+ (ProtocolTraits::IsNative(hash_type) ? kEmptySha1 : kEmptySha256));
CHECK(artifacts["file"]["data"]["size"] == 0);
}
}
TEST_CASE("not present at all") {
+ auto const hash_type = TestHashType::ReadFromEnvironment();
+
bool consumed{false};
bool failure_called{false};
auto name = EntityName{"", ".", "does_not_exist"};
auto consumer = [&consumed](auto /*unused*/) { consumed = true; };
auto fail_func = [&failure_called]() { failure_called = true; };
- auto const hash_type = ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1;
-
SECTION("via file") {
CHECK_FALSE(ReadSourceTarget(
name, consumer, hash_type, /*use_git=*/false, fail_func));
@@ -142,16 +139,14 @@ TEST_CASE("not present at all") {
}
TEST_CASE("malformed entry") {
+ auto const hash_type = TestHashType::ReadFromEnvironment();
+
bool consumed{false};
bool failure_called{false};
auto name = EntityName{"", ".", "bad_entry"};
auto consumer = [&consumed](auto /*unused*/) { consumed = true; };
auto fail_func = [&failure_called]() { failure_called = true; };
- auto const hash_type = ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1;
-
SECTION("via git tree") {
CHECK_FALSE(ReadSourceTarget(
name, consumer, hash_type, /*use_git=*/false, fail_func));
@@ -168,16 +163,14 @@ TEST_CASE("malformed entry") {
}
TEST_CASE("subdir file") {
+ auto const hash_type = TestHashType::ReadFromEnvironment();
+
nlohmann::json artifacts;
auto name = EntityName{"", "foo", "bar/file"};
auto consumer = [&artifacts](auto values) {
artifacts = (*values[0])->Artifacts()->ToJson();
};
- auto const hash_type = ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1;
-
SECTION("via file") {
CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false));
CHECK(artifacts["bar/file"]["type"] == "LOCAL");
@@ -187,24 +180,22 @@ TEST_CASE("subdir file") {
SECTION("via git tree") {
CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true));
CHECK(artifacts["bar/file"]["type"] == "KNOWN");
- CHECK(artifacts["bar/file"]["data"]["id"] ==
- (ProtocolTraits::Instance().IsCompatible() ? kEmptySha256
- : kEmptySha1));
+ CHECK(
+ artifacts["bar/file"]["data"]["id"] ==
+ (ProtocolTraits::IsNative(hash_type) ? kEmptySha1 : kEmptySha256));
CHECK(artifacts["bar/file"]["data"]["size"] == 0);
}
}
TEST_CASE("subdir symlink") {
+ auto const hash_type = TestHashType::ReadFromEnvironment();
+
nlohmann::json artifacts;
auto name = EntityName{"", "foo", "link"};
auto consumer = [&artifacts](auto values) {
artifacts = (*values[0])->Artifacts()->ToJson();
};
- auto const hash_type = ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1;
-
SECTION("via file") {
CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false));
CHECK(artifacts["link"]["type"] == "LOCAL");
@@ -215,8 +206,8 @@ TEST_CASE("subdir symlink") {
CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true));
CHECK(artifacts["link"]["type"] == "KNOWN");
CHECK(artifacts["link"]["data"]["id"] ==
- (ProtocolTraits::Instance().IsCompatible() ? kSrcLinkIdSha256
- : kSrcLinkIdSha1));
+ (ProtocolTraits::IsNative(hash_type) ? kSrcLinkIdSha1
+ : kSrcLinkIdSha256));
CHECK(artifacts["link"]["data"]["size"] == 5); // content: dummy
}
}