diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp | 54 | ||||
-rw-r--r-- | test/buildtool/storage/local_cas.test.cpp | 4 |
2 files changed, 51 insertions, 7 deletions
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 4322a46b..2d7aa602 100644 --- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp @@ -13,6 +13,7 @@ // limitations under the License. #include <filesystem> +#include <unordered_map> #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/artifact_factory.hpp" @@ -29,11 +30,18 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") { std::filesystem::path file1 = subdir1 / "file1"; std::filesystem::path file2 = subdir2 / "file2"; - auto file1_blob = CreateBlobFromFile(file1); - auto file2_blob = CreateBlobFromFile(file2); + // create a symlink + std::filesystem::path link = subdir1 / "link"; + REQUIRE(FileSystemManager::CreateSymlink("file1", link)); + + // create the corresponding blobs + auto file1_blob = CreateBlobFromPath(file1); + auto file2_blob = CreateBlobFromPath(file2); + auto link_blob = CreateBlobFromPath(link); CHECK(file1_blob); CHECK(file2_blob); + CHECK(link_blob); // both files are the same and should result in identical blobs CHECK(file1_blob->data == file2_blob->data); @@ -57,15 +65,51 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") { CHECK(artifact2_opt.has_value()); auto artifact2 = DependencyGraph::ArtifactNode{std::move(*artifact2_opt)}; + auto artifact3_opt = + ArtifactFactory::FromDescription(ArtifactFactory::DescribeKnownArtifact( + NativeSupport::Unprefix(link_blob->digest.hash()), + static_cast<std::size_t>(link_blob->digest.size_bytes()), + ObjectType::Symlink)); + CHECK(artifact3_opt.has_value()); + auto artifact3 = DependencyGraph::ArtifactNode{std::move(*artifact3_opt)}; + // create directory tree - auto tree = DirectoryTree::FromNamedArtifacts( - {{file1.string(), &artifact1}, {file2.string(), &artifact2}}); + auto tree = + DirectoryTree::FromNamedArtifacts({{file1.string(), &artifact1}, + {file2.string(), &artifact2}, + {link.string(), &artifact3}}); CHECK(tree.has_value()); + // a mapping between digests and content is needed; usually via a concrete + // API one gets this content either locally or from the network + std::unordered_map<bazel_re::Digest, std::filesystem::path> fake_cas{ + {file1_blob->digest, file1}, + {file2_blob->digest, file2}, + {link_blob->digest, link}}; + // create blobs via tree BlobContainer blobs{}; REQUIRE(BazelMsgFactory::CreateDirectoryDigestFromTree( - *tree, [&blobs](BazelBlob&& blob) { blobs.Emplace(std::move(blob)); })); + *tree, + [&fake_cas](std::vector<bazel_re::Digest> const& digests, + std::vector<std::string>* targets) { + targets->reserve(digests.size()); + for (auto const& digest : digests) { + REQUIRE(fake_cas.contains(digest)); + auto fpath = fake_cas[digest]; + if (std::filesystem::is_symlink(fpath)) { + auto content = FileSystemManager::ReadSymlink(fpath); + REQUIRE(content); + targets->emplace_back(*content); + } + else { + auto content = FileSystemManager::ReadFile(fpath); + REQUIRE(content); + targets->emplace_back(*content); + } + } + }, + [&blobs](BazelBlob&& blob) { blobs.Emplace(std::move(blob)); })); // TODO(aehlig): also check total number of DirectoryNode blobs in container } diff --git a/test/buildtool/storage/local_cas.test.cpp b/test/buildtool/storage/local_cas.test.cpp index 631d2eba..a5f6876f 100644 --- a/test/buildtool/storage/local_cas.test.cpp +++ b/test/buildtool/storage/local_cas.test.cpp @@ -72,7 +72,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "test/buildtool/storage/data/non_executable_file"}; auto const& cas = Storage::Instance().CAS(); - auto test_blob = CreateBlobFromFile(non_exec_file); + auto test_blob = CreateBlobFromPath(non_exec_file); REQUIRE(test_blob); // check blob not in storage @@ -121,7 +121,7 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "test/buildtool/storage/data/executable_file"}; auto const& cas = Storage::Instance().CAS(); - auto test_blob = CreateBlobFromFile(exec_file); + auto test_blob = CreateBlobFromPath(exec_file); REQUIRE(test_blob); // check blob not in storage |