summaryrefslogtreecommitdiff
path: root/test/buildtool
diff options
context:
space:
mode:
Diffstat (limited to 'test/buildtool')
-rw-r--r--test/buildtool/execution_api/bazel/TARGETS5
-rw-r--r--test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp37
-rw-r--r--test/buildtool/storage/TARGETS1
-rw-r--r--test/buildtool/storage/local_cas.test.cpp41
4 files changed, 53 insertions, 31 deletions
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS
index 90bddd80..aad61b68 100644
--- a/test/buildtool/execution_api/bazel/TARGETS
+++ b/test/buildtool/execution_api/bazel/TARGETS
@@ -94,9 +94,12 @@
, "bazel_msg_factory"
]
, ["@", "src", "src/buildtool/file_system", "object_type"]
- , ["utils", "blob_creator"]
+ , ["@", "src", "src/buildtool/common", "common"]
, ["@", "src", "src/buildtool/crypto", "hash_function"]
, ["@", "src", "src/buildtool/compatibility", "compatibility"]
+ , ["@", "src", "src/buildtool/execution_api/common", "common"]
+ , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
+ , ["@", "src", "src/buildtool/file_system", "file_system_manager"]
]
, "stage": ["test", "buildtool", "execution_api", "bazel"]
}
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 2c4035b0..8fca672b 100644
--- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp
@@ -15,16 +15,40 @@
#include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp"
#include <filesystem>
+#include <optional>
+#include <string>
#include <unordered_map>
#include "catch2/catch_test_macros.hpp"
#include "src/buildtool/common/artifact_description.hpp"
+#include "src/buildtool/common/artifact_digest.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"
+#include "src/buildtool/execution_api/common/artifact_blob_container.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/object_type.hpp"
-#include "test/utils/blob_creator.hpp"
+
+namespace {
+/// \brief Create a blob from the content found in file or symlink pointed to by
+/// given path.
+[[nodiscard]] static inline auto CreateBlobFromPath(
+ std::filesystem::path const& fpath,
+ HashFunction hash_function) noexcept -> std::optional<ArtifactBlob> {
+ auto const type = FileSystemManager::Type(fpath, /*allow_upwards=*/true);
+ if (not type) {
+ return std::nullopt;
+ }
+ auto const content = FileSystemManager::ReadContentAtPath(fpath, *type);
+ if (not content.has_value()) {
+ return std::nullopt;
+ }
+ return ArtifactBlob{
+ ArtifactDigest::Create<ObjectType::File>(hash_function, *content),
+ *content,
+ IsExecutableObject(*type)};
+}
+} // namespace
TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") {
std::filesystem::path workspace{"test/buildtool/storage/data"};
@@ -54,24 +78,21 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") {
// both files are the same and should result in identical blobs
CHECK(*file1_blob->data == *file2_blob->data);
CHECK(file1_blob->digest.hash() == file2_blob->digest.hash());
- CHECK(file1_blob->digest.size_bytes() == file2_blob->digest.size_bytes());
+ CHECK(file1_blob->digest.size() == file2_blob->digest.size());
// create known artifacts
auto artifact1_opt =
- ArtifactDescription::CreateKnown(ArtifactDigest{file1_blob->digest},
- ObjectType::File)
+ ArtifactDescription::CreateKnown(file1_blob->digest, ObjectType::File)
.ToArtifact();
auto artifact1 = DependencyGraph::ArtifactNode{std::move(artifact1_opt)};
auto artifact2_opt =
- ArtifactDescription::CreateKnown(ArtifactDigest{file2_blob->digest},
- ObjectType::File)
+ ArtifactDescription::CreateKnown(file2_blob->digest, ObjectType::File)
.ToArtifact();
auto artifact2 = DependencyGraph::ArtifactNode{std::move(artifact2_opt)};
auto artifact3_opt =
- ArtifactDescription::CreateKnown(ArtifactDigest{link_blob->digest},
- ObjectType::Symlink)
+ ArtifactDescription::CreateKnown(link_blob->digest, ObjectType::Symlink)
.ToArtifact();
auto artifact3 = DependencyGraph::ArtifactNode{std::move(artifact3_opt)};
diff --git a/test/buildtool/storage/TARGETS b/test/buildtool/storage/TARGETS
index 69d13137..c61cde66 100644
--- a/test/buildtool/storage/TARGETS
+++ b/test/buildtool/storage/TARGETS
@@ -21,7 +21,6 @@
, ["@", "src", "src/buildtool/file_system", "file_system_manager"]
, ["@", "src", "src/buildtool/file_system", "object_type"]
, ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"]
- , ["utils", "blob_creator"]
, ["@", "src", "src/buildtool/storage", "storage"]
, ["@", "src", "src/buildtool/storage", "config"]
]
diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp
index b4ede8ca..4b7c844a 100644
--- a/test/buildtool/storage/local_cas.test.cpp
+++ b/test/buildtool/storage/local_cas.test.cpp
@@ -22,7 +22,6 @@
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
-#include "test/utils/blob_creator.hpp"
#include "test/utils/hermeticity/test_storage_config.hpp"
TEST_CASE("LocalCAS: Add blob to storage from bytes", "[storage]") {
@@ -83,27 +82,27 @@ TEST_CASE("LocalCAS: Add blob to storage from non-executable file",
std::filesystem::path non_exec_file{
"test/buildtool/storage/data/non_executable_file"};
- auto test_blob =
- CreateBlobFromPath(non_exec_file, storage_config.Get().hash_function);
+ auto test_blob = ArtifactDigest::CreateFromFile<ObjectType::File>(
+ storage_config.Get().hash_function, non_exec_file);
REQUIRE(test_blob);
// check blob not in storage
- CHECK(not cas.BlobPath(test_blob->digest, true));
- CHECK(not cas.BlobPath(test_blob->digest, false));
+ CHECK(not cas.BlobPath(*test_blob, true));
+ CHECK(not cas.BlobPath(*test_blob, false));
// ensure previous calls did not accidentially create the blob
- CHECK(not cas.BlobPath(test_blob->digest, true));
- CHECK(not cas.BlobPath(test_blob->digest, false));
+ CHECK(not cas.BlobPath(*test_blob, true));
+ CHECK(not cas.BlobPath(*test_blob, false));
SECTION("Add non-executable blob to storage") {
CHECK(cas.StoreBlob(non_exec_file, false));
- auto file_path = cas.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(*test_blob, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = cas.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(*test_blob, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -113,12 +112,12 @@ TEST_CASE("LocalCAS: Add blob to storage from non-executable file",
SECTION("Add executable blob to storage") {
CHECK(cas.StoreBlob(non_exec_file, true));
- auto file_path = cas.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(*test_blob, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = cas.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(*test_blob, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -134,27 +133,27 @@ TEST_CASE("LocalCAS: Add blob to storage from executable file", "[storage]") {
std::filesystem::path exec_file{
"test/buildtool/storage/data/executable_file"};
- auto test_blob =
- CreateBlobFromPath(exec_file, storage_config.Get().hash_function);
+ auto test_blob = ArtifactDigest::CreateFromFile<ObjectType::File>(
+ storage_config.Get().hash_function, exec_file);
REQUIRE(test_blob);
// check blob not in storage
- CHECK(not cas.BlobPath(test_blob->digest, true));
- CHECK(not cas.BlobPath(test_blob->digest, false));
+ CHECK(not cas.BlobPath(*test_blob, true));
+ CHECK(not cas.BlobPath(*test_blob, false));
// ensure previous calls did not accidentially create the blob
- CHECK(not cas.BlobPath(test_blob->digest, true));
- CHECK(not cas.BlobPath(test_blob->digest, false));
+ CHECK(not cas.BlobPath(*test_blob, true));
+ CHECK(not cas.BlobPath(*test_blob, false));
SECTION("Add non-executable blob to storage") {
CHECK(cas.StoreBlob(exec_file, false));
- auto file_path = cas.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(*test_blob, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = cas.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(*test_blob, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));
@@ -164,12 +163,12 @@ TEST_CASE("LocalCAS: Add blob to storage from executable file", "[storage]") {
SECTION("Add executable blob to storage") {
CHECK(cas.StoreBlob(exec_file, true));
- auto file_path = cas.BlobPath(test_blob->digest, false);
+ auto file_path = cas.BlobPath(*test_blob, false);
REQUIRE(file_path);
CHECK(FileSystemManager::IsFile(*file_path));
CHECK(not FileSystemManager::IsExecutable(*file_path));
- auto exe_path = cas.BlobPath(test_blob->digest, true);
+ auto exe_path = cas.BlobPath(*test_blob, true);
REQUIRE(exe_path);
CHECK(FileSystemManager::IsFile(*exe_path));
CHECK(FileSystemManager::IsExecutable(*exe_path));