summaryrefslogtreecommitdiff
path: root/test/buildtool
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-08-29 17:29:49 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-08-30 17:17:09 +0200
commit013d83eed166049be110d47f00feb4c6af1315af (patch)
treed792e9f6a180337365f639a17c0e07b52b480b37 /test/buildtool
parent576e31959bb7550bdd2b348f5d096f4926e859c6 (diff)
downloadjustbuild-013d83eed166049be110d47f00feb4c6af1315af.tar.gz
Use BazelDigestFactory to create bazel_re::Digest directly if needed
...bypassing ArtifactDigest functionality.
Diffstat (limited to 'test/buildtool')
-rw-r--r--test/buildtool/execution_api/bazel/TARGETS8
-rw-r--r--test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp6
-rw-r--r--test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp10
-rw-r--r--test/buildtool/execution_api/bazel/bazel_network.test.cpp42
-rw-r--r--test/buildtool/execution_api/bazel/bytestream_client.test.cpp51
-rw-r--r--test/buildtool/execution_api/execution_service/TARGETS1
-rw-r--r--test/buildtool/execution_api/execution_service/cas_server.test.cpp5
7 files changed, 62 insertions, 61 deletions
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS
index 18a9e012..9d9aa5d8 100644
--- a/test/buildtool/execution_api/bazel/TARGETS
+++ b/test/buildtool/execution_api/bazel/TARGETS
@@ -8,7 +8,7 @@
, ["utils", "catch-main-remote-execution"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
@@ -28,7 +28,7 @@
, ["utils", "execution_bazel"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
@@ -48,7 +48,7 @@
, ["utils", "execution_bazel"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
, ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"]
, ["@", "src", "src/buildtool/execution_api/remote", "config"]
@@ -68,7 +68,7 @@
, ["utils", "execution_bazel"]
, ["utils", "test_auth_config"]
, ["utils", "test_remote_config"]
- , ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/common/remote", "retry_config"]
, ["@", "src", "src/buildtool/compatibility", "compatibility"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
diff --git a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
index bd005497..e4772f7d 100644
--- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp
@@ -20,7 +20,7 @@
#include "catch2/catch_test_macros.hpp"
#include "gsl/gsl"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
@@ -52,8 +52,8 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") {
HashFunction const hash_function{Compatibility::IsCompatible()
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- auto digest =
- ArtifactDigest::Create<ObjectType::File>(hash_function, content);
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
// Valid blob
BazelBlob blob{digest, content, /*is_exec=*/false};
diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
index 093c4eb1..c354316c 100644
--- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp
@@ -17,7 +17,7 @@
#include <string>
#include "catch2/catch_test_macros.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
@@ -35,8 +35,8 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") {
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- auto test_digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
auto auth_config = TestAuthConfig::ReadFromEnvironment();
REQUIRE(auth_config);
@@ -119,8 +119,8 @@ TEST_CASE("Bazel internals: Execution Client using env variables",
? HashFunction::Type::PlainSHA256
: HashFunction::Type::GitSHA1};
- auto test_digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
auto auth_config = TestAuthConfig::ReadFromEnvironment();
REQUIRE(auth_config);
diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp
index edc35ea7..01c5aea9 100644
--- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp
@@ -21,7 +21,7 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/auth/authentication.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
@@ -62,18 +62,18 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") {
std::string content_bar("bar");
std::string content_baz(kLargeSize, 'x'); // single larger blob
- BazelBlob foo{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_foo),
- content_foo,
- /*is_exec=*/false};
- BazelBlob bar{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_bar),
- content_bar,
- /*is_exec=*/false};
- BazelBlob baz{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_baz),
- content_baz,
- /*is_exec=*/false};
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_foo),
+ content_foo,
+ /*is_exec=*/false};
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_bar),
+ content_bar,
+ /*is_exec=*/false};
+ BazelBlob baz{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_baz),
+ content_baz,
+ /*is_exec=*/false};
// Search blobs via digest
REQUIRE(network.UploadBlobs(BazelBlobContainer{{foo, bar, baz}}));
@@ -128,14 +128,14 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") {
std::string content_foo("foo");
std::string content_bar(kLargeSize, 'x'); // single larger blob
- BazelBlob foo{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_foo),
- content_foo,
- /*is_exec=*/false};
- BazelBlob bar{
- ArtifactDigest::Create<ObjectType::File>(hash_function, content_bar),
- content_bar,
- /*is_exec=*/false};
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_foo),
+ content_foo,
+ /*is_exec=*/false};
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_bar),
+ content_bar,
+ /*is_exec=*/false};
// Upload blobs
REQUIRE(network.UploadBlobs(BazelBlobContainer{{foo, bar}}));
diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
index 10fe0c83..731073e5 100644
--- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
+++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp
@@ -20,7 +20,7 @@
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/auth/authentication.hpp"
-#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
@@ -54,8 +54,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
std::string content("foobar");
// digest of "foobar"
- auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -80,9 +80,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
std::string other_content("This is a differnt string");
// Valid digest, but for a different string
- auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function,
- other_content));
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, other_content);
CHECK(not stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -101,8 +100,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") {
}
// digest of "instance_nameinstance_nameinstance_..."
- auto digest = static_cast<bazel_re::Digest>(
- ArtifactDigest::Create<ObjectType::File>(hash_function, content));
+ auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content);
CHECK(stream.Write(fmt::format("{}/uploads/{}/blobs/{}/{}",
instance_name,
@@ -160,18 +159,18 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") {
SECTION("Upload small blobs") {
std::string instance_name{"remote-execution"};
- BazelBlob foo{
- ArtifactDigest::Create<ObjectType::File>(hash_function, "foo"),
- "foo",
- /*is_exec=*/false};
- BazelBlob bar{
- ArtifactDigest::Create<ObjectType::File>(hash_function, "bar"),
- "bar",
- /*is_exec=*/false};
- BazelBlob baz{
- ArtifactDigest::Create<ObjectType::File>(hash_function, "baz"),
- "baz",
- /*is_exec=*/false};
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, "foo"),
+ "foo",
+ /*is_exec=*/false};
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, "bar"),
+ "bar",
+ /*is_exec=*/false};
+ BazelBlob baz{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, "baz"),
+ "baz",
+ /*is_exec=*/false};
CHECK(stream.WriteMany<BazelBlob>(
{foo, bar, baz},
@@ -216,16 +215,16 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") {
content_baz[i] = instance_name[(i + 2) % instance_name.size()];
}
- BazelBlob foo{ArtifactDigest::Create<ObjectType::File>(hash_function,
- content_foo),
+ BazelBlob foo{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_foo),
content_foo,
/*is_exec=*/false};
- BazelBlob bar{ArtifactDigest::Create<ObjectType::File>(hash_function,
- content_bar),
+ BazelBlob bar{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_bar),
content_bar,
/*is_exec=*/false};
- BazelBlob baz{ArtifactDigest::Create<ObjectType::File>(hash_function,
- content_baz),
+ BazelBlob baz{BazelDigestFactory::HashDataAs<ObjectType::File>(
+ hash_function, content_baz),
content_baz,
/*is_exec=*/false};
diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS
index 0e32c4ad..a2c1e9dd 100644
--- a/test/buildtool/execution_api/execution_service/TARGETS
+++ b/test/buildtool/execution_api/execution_service/TARGETS
@@ -16,6 +16,7 @@
, ["@", "src", "src/buildtool/file_system", "git_repo"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/common", "common"]
+ , ["@", "src", "src/buildtool/common", "bazel_digest_factory"]
, ["@", "src", "src/buildtool/storage", "config"]
, ["@", "src", "src/buildtool/storage", "storage"]
, ["@", "gsl", "", "gsl"]
diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp
index 4bc90546..ca88b17b 100644
--- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp
+++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp
@@ -19,6 +19,7 @@
#include "catch2/catch_test_macros.hpp"
#include "gsl/gsl"
#include "src/buildtool/common/artifact_digest.hpp"
+#include "src/buildtool/common/bazel_digest_factory.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
#include "src/buildtool/execution_api/local/context.hpp"
#include "src/buildtool/file_system/git_repo.hpp"
@@ -66,7 +67,7 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") {
auto empty_entries = GitRepo::tree_entries_t{};
auto empty_tree = GitRepo::CreateShallowTree(empty_entries);
REQUIRE(empty_tree);
- auto empty_tree_digest = ArtifactDigest::Create<ObjectType::Tree>(
+ auto empty_tree_digest = BazelDigestFactory::HashDataAs<ObjectType::Tree>(
storage_config.Get().hash_function, empty_tree->second);
// Create a tree containing the empty tree.
@@ -74,7 +75,7 @@ TEST_CASE("CAS Service: upload incomplete tree", "[execution_service]") {
entries[empty_tree->first].emplace_back("empty_tree", ObjectType::Tree);
auto tree = GitRepo::CreateShallowTree(entries);
REQUIRE(tree);
- auto tree_digest = ArtifactDigest::Create<ObjectType::Tree>(
+ auto tree_digest = BazelDigestFactory::HashDataAs<ObjectType::Tree>(
storage_config.Get().hash_function, tree->second);
// Upload tree. The tree invariant is violated, thus, a negative answer is