diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-06 11:35:32 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-11 14:52:07 +0200 |
commit | 8e652e5d7b6fbe0abf07df62814c655759564247 (patch) | |
tree | cd338f2f3425cf6305e0c2647ae6cc6369998d45 /test/buildtool/file_system | |
parent | 15c54bf96fbc8ca19af7ff5edf0faa37228c4c00 (diff) | |
download | justbuild-8e652e5d7b6fbe0abf07df62814c655759564247.tar.gz |
Use ArtifactDigestFactory in tests
...to create ArtifactDigests.
In some tests ArtifactDigests were constructed using non-hexadecimal string identifiers. These tests were adjusted so that ArtifactDigest contained a valid hash.
Diffstat (limited to 'test/buildtool/file_system')
-rw-r--r-- | test/buildtool/file_system/TARGETS | 2 | ||||
-rw-r--r-- | test/buildtool/file_system/file_root.test.cpp | 54 |
2 files changed, 35 insertions, 21 deletions
diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS index a8e998a6..a7342221 100644 --- a/test/buildtool/file_system/TARGETS +++ b/test/buildtool/file_system/TARGETS @@ -61,6 +61,8 @@ , ["utils", "container_matchers"] , ["@", "src", "src/buildtool/common", "artifact_description"] , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["utils", "shell_quoting"] diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index 2f21dfab..f709aa7a 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -24,6 +24,8 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_description.hpp" #include "src/buildtool/common/artifact_digest.hpp" +#include "src/buildtool/common/artifact_digest_factory.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "test/utils/container_matchers.hpp" #include "test/utils/shell_quoting.hpp" @@ -411,37 +413,47 @@ static void CheckGitRoot(bool ignore_special) noexcept { auto const foo = root->ToArtifactDescription("baz/foo", "repo"); REQUIRE(foo); if (Compatibility::IsCompatible()) { + auto const digest = + ArtifactDigestFactory::Create(HashFunction::Type::PlainSHA256, + kFooIdSha256, + kFooContentLength, + /*is_tree=*/false); + REQUIRE(digest); CHECK(*foo == - ArtifactDescription::CreateKnown( - ArtifactDigest{ - kFooIdSha256, kFooContentLength, /*is_tree=*/false}, - ObjectType::File)); + ArtifactDescription::CreateKnown(*digest, ObjectType::File)); } else { - CHECK(*foo == - ArtifactDescription::CreateKnown( - ArtifactDigest{ - kFooIdGitSha1, kFooContentLength, /*is_tree=*/false}, - ObjectType::File, - "repo")); + auto const digest = + ArtifactDigestFactory::Create(HashFunction::Type::GitSHA1, + kFooIdGitSha1, + kFooContentLength, + /*is_tree=*/false); + REQUIRE(digest); + CHECK(*foo == ArtifactDescription::CreateKnown( + *digest, ObjectType::File, "repo")); } auto const bar = root->ToArtifactDescription("baz/bar", "repo"); REQUIRE(bar); if (Compatibility::IsCompatible()) { - CHECK(*bar == - ArtifactDescription::CreateKnown( - ArtifactDigest{ - kBarIdSha256, kBarContentLength, /*is_tree=*/false}, - ObjectType::Executable)); + auto const digest = + ArtifactDigestFactory::Create(HashFunction::Type::PlainSHA256, + kBarIdSha256, + kBarContentLength, + /*is_tree=*/false); + REQUIRE(digest); + CHECK(*bar == ArtifactDescription::CreateKnown(*digest, + ObjectType::Executable)); } else { - CHECK(*bar == - ArtifactDescription::CreateKnown( - ArtifactDigest{ - kBarIdGitSha1, kBarContentLength, /*is_tree=*/false}, - ObjectType::Executable, - "repo")); + auto const digest = + ArtifactDigestFactory::Create(HashFunction::Type::GitSHA1, + kBarIdGitSha1, + kBarContentLength, + /*is_tree=*/false); + REQUIRE(digest); + CHECK(*bar == ArtifactDescription::CreateKnown( + *digest, ObjectType::Executable, "repo")); } CHECK_FALSE(root->ToArtifactDescription("baz", "repo")); |