diff options
Diffstat (limited to 'test/buildtool/execution_api/bazel')
5 files changed, 53 insertions, 48 deletions
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index ce5c8077..25fbda81 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -6,7 +6,6 @@ [ ["@", "catch2", "", "catch2"] , ["@", "gsl", "", "gsl"] , ["@", "src", "src/buildtool/common", "artifact_blob"] - , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common/remote", "remote_common"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] @@ -14,6 +13,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/utils/cpp", "expected"] , ["utils", "catch-main-remote-execution"] , ["utils", "test_auth_config"] , ["utils", "test_hash_function_type"] @@ -63,6 +63,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/utils/cpp", "expected"] , ["utils", "catch-main-remote-execution"] , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] @@ -80,7 +81,6 @@ , ["@", "grpc", "", "grpc"] , ["@", "gsl", "", "gsl"] , ["@", "src", "src/buildtool/common", "artifact_blob"] - , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "remote_common"] @@ -90,6 +90,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/utils/cpp", "expected"] , ["utils", "catch-main-remote-execution"] , ["utils", "execution_bazel"] , ["utils", "test_auth_config"] @@ -107,7 +108,6 @@ [ ["@", "catch2", "", "catch2"] , ["@", "src", "src/buildtool/common", "artifact_blob"] , ["@", "src", "src/buildtool/common", "artifact_description"] - , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/crypto", "hash_function"] , [ "@" @@ -120,6 +120,7 @@ , ["@", "src", "src/buildtool/execution_engine/dag", "dag"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/file_system", "object_type"] + , ["@", "src", "src/utils/cpp", "expected"] , ["", "catch-main"] , ["utils", "test_hash_function_type"] ] 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 031da8f0..814de567 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -24,13 +24,13 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_blob.hpp" #include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/remote/remote_common.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_capabilities_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/utils/cpp/expected.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -60,25 +60,26 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { SECTION("Valid digest and blob") { // digest of "test" HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; - auto const digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, content); - // Valid blob - ArtifactBlob blob{digest, content, /*is_exec=*/false}; + auto const blob = + ArtifactBlob::FromMemory(hash_function, ObjectType::File, content); + REQUIRE(blob.has_value()); // Search blob via digest - auto digests = cas_client.FindMissingBlobs(instance_name, {digest}); + auto digests = + cas_client.FindMissingBlobs(instance_name, {blob->GetDigest()}); CHECK(digests.size() <= 1); if (not digests.empty()) { // Upload blob, if not found - CHECK(cas_client.BatchUpdateBlobs(instance_name, {blob}) == 1U); + CHECK(cas_client.BatchUpdateBlobs(instance_name, {*blob}) == 1U); } // Read blob - auto blobs = cas_client.BatchReadBlobs(instance_name, {digest}); + auto blobs = + cas_client.BatchReadBlobs(instance_name, {blob->GetDigest()}); REQUIRE(blobs.size() == 1); - CHECK(blobs.begin()->GetDigest() == digest); + CHECK(blobs.begin()->GetDigest() == blob->GetDigest()); auto const read_content = blobs.begin()->ReadContent(); CHECK(read_content != nullptr); CHECK(*read_content == content); diff --git a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp index 6b106bc7..e4422884 100644 --- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp @@ -28,12 +28,12 @@ #include "src/buildtool/common/artifact_blob.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/execution_api/bazel_msg/directory_tree.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/utils/cpp/expected.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" namespace { @@ -46,14 +46,16 @@ namespace { if (not type) { return std::nullopt; } - auto const content = FileSystemManager::ReadContentAtPath(fpath, *type); + auto content = FileSystemManager::ReadContentAtPath(fpath, *type); if (not content.has_value()) { return std::nullopt; } - return ArtifactBlob{ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, *content), - *content, - IsExecutableObject(*type)}; + auto blob = ArtifactBlob::FromMemory( + hash_function, ObjectType::File, *std::move(content)); + if (not blob.has_value()) { + return std::nullopt; + } + return *std::move(blob); } } // namespace diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index 3cb0ef35..fd812287 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -28,7 +28,6 @@ #include "gsl/gsl" #include "src/buildtool/common/artifact_blob.hpp" #include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/remote_common.hpp" #include "src/buildtool/common/remote/retry_config.hpp" @@ -37,6 +36,7 @@ #include "src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/utils/cpp/expected.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -69,29 +69,26 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { std::string content_bar("bar"); std::string content_baz(kLargeSize, 'x'); // single larger blob - ArtifactBlob foo{ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, content_foo), - content_foo, - /*is_exec=*/false}; - ArtifactBlob bar{ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, content_bar), - content_bar, - /*is_exec=*/false}; - ArtifactBlob baz{ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, content_baz), - content_baz, - /*is_exec=*/false}; + auto const foo = + ArtifactBlob::FromMemory(hash_function, ObjectType::File, content_foo); + REQUIRE(foo.has_value()); + auto const bar = + ArtifactBlob::FromMemory(hash_function, ObjectType::File, content_bar); + REQUIRE(bar.has_value()); + auto const baz = + ArtifactBlob::FromMemory(hash_function, ObjectType::File, content_baz); + REQUIRE(baz.has_value()); // Search blobs via digest - REQUIRE(network.UploadBlobs({foo, bar, baz})); + REQUIRE(network.UploadBlobs({*foo, *bar, *baz})); // Read blobs in order auto reader = network.CreateReader(); - std::vector<ArtifactDigest> to_read{foo.GetDigest(), - bar.GetDigest(), - baz.GetDigest(), - bar.GetDigest(), - foo.GetDigest()}; + std::vector<ArtifactDigest> to_read{foo->GetDigest(), + bar->GetDigest(), + baz->GetDigest(), + bar->GetDigest(), + foo->GetDigest()}; std::vector<ArtifactBlob> blobs{}; for (auto next : reader.ReadIncrementally(&to_read)) { blobs.insert(blobs.end(), next.begin(), next.end()); diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 991dcf72..823c317c 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -30,6 +30,7 @@ #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/utils/cpp/expected.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -53,13 +54,14 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { std::string content("foobar"); // digest of "foobar" - auto digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, content); + auto const blob = + ArtifactBlob::FromMemory(hash_function, ObjectType::File, content); + REQUIRE(blob.has_value()); - ArtifactBlob const blob{digest, content, /*is_exec=*/false}; - CHECK(stream.Write(instance_name, blob)); + CHECK(stream.Write(instance_name, *blob)); - auto const downloaded_blob = stream.Read(instance_name, digest); + auto const downloaded_blob = + stream.Read(instance_name, blob->GetDigest()); REQUIRE(downloaded_blob.has_value()); auto const downloaded_content = downloaded_blob->ReadContent(); @@ -91,14 +93,15 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { } // digest of "instance_nameinstance_nameinstance_..." - auto digest = ArtifactDigestFactory::HashDataAs<ObjectType::File>( - hash_function, content); - ArtifactBlob const blob{digest, content, /*is_exec=*/false}; + auto const blob = + ArtifactBlob::FromMemory(hash_function, ObjectType::File, content); + REQUIRE(blob.has_value()); - CHECK(stream.Write(instance_name, blob)); + CHECK(stream.Write(instance_name, *blob)); SECTION("Download large blob") { - auto const downloaded_blob = stream.Read(instance_name, digest); + auto const downloaded_blob = + stream.Read(instance_name, blob->GetDigest()); REQUIRE(downloaded_blob.has_value()); auto const downloaded_content = downloaded_blob->ReadContent(); @@ -107,7 +110,8 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { } SECTION("Incrementally download large blob") { - auto reader = stream.IncrementalRead(instance_name, digest); + auto reader = + stream.IncrementalRead(instance_name, blob->GetDigest()); std::string data{}; auto chunk = reader.Next(); |