diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-29 11:32:23 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-08-30 17:17:09 +0200 |
commit | 60daf819bbe7db97064c7e102acedbf3cd693410 (patch) | |
tree | 43cd28daadadd1eede9db7882b76f02c12ad99d0 | |
parent | 9bc887e80bd1845f5ca4277518512149345d2422 (diff) | |
download | justbuild-60daf819bbe7db97064c7e102acedbf3cd693410.tar.gz |
Remove blob_creator lib from tests
...and move this functionality to bazel_msg_factory_test, where it is actually used.
For local_cas.test the regular hashing is used, since blob_creator is redundant there.
-rw-r--r-- | test/buildtool/execution_api/bazel/TARGETS | 5 | ||||
-rw-r--r-- | test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp | 37 | ||||
-rw-r--r-- | test/buildtool/storage/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/storage/local_cas.test.cpp | 41 | ||||
-rw-r--r-- | test/utils/TARGETS | 13 | ||||
-rw-r--r-- | test/utils/blob_creator.hpp | 47 |
6 files changed, 53 insertions, 91 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)); diff --git a/test/utils/TARGETS b/test/utils/TARGETS index 619e4134..18bda841 100644 --- a/test/utils/TARGETS +++ b/test/utils/TARGETS @@ -157,19 +157,6 @@ , "hdrs": ["shell_quoting.hpp"] , "stage": ["test", "utils"] } -, "blob_creator": - { "type": ["@", "rules", "CC", "library"] - , "name": ["blob_creator"] - , "hdrs": ["blob_creator.hpp"] - , "stage": ["test", "utils"] - , "deps": - [ ["@", "src", "src/buildtool/common", "common"] - , ["@", "src", "src/buildtool/file_system", "object_type"] - , ["@", "src", "src/buildtool/file_system", "file_system_manager"] - , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] - , ["@", "src", "src/buildtool/crypto", "hash_function"] - ] - } , "test_api_bundle": { "type": ["@", "rules", "CC", "library"] , "name": ["test_api_bundle"] diff --git a/test/utils/blob_creator.hpp b/test/utils/blob_creator.hpp deleted file mode 100644 index 944fb9d2..00000000 --- a/test/utils/blob_creator.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef INCLUDED_SRC_TEST_UTILS_BLOB_CREATOR_HPP -#define INCLUDED_SRC_TEST_UTILS_BLOB_CREATOR_HPP - -#include <filesystem> -#include <optional> -#include <string> - -#include "src/buildtool/common/artifact_digest.hpp" -#include "src/buildtool/crypto/hash_function.hpp" -#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" -#include "src/buildtool/file_system/file_system_manager.hpp" -#include "src/buildtool/file_system/object_type.hpp" - -/// \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<BazelBlob> { - 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 BazelBlob{ - ArtifactDigest::Create<ObjectType::File>(hash_function, *content), - *content, - IsExecutableObject(*type)}; -} - -#endif // INCLUDED_SRC_TEST_UTILS_BLOB_CREATOR_HPP |