diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-05 16:49:45 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-22 17:01:13 +0200 |
commit | beb3faa6956b9bfd58d4ea6644a9b2987409aaba (patch) | |
tree | 9a1edee40bfe335717eb856237372d50127367ac /test | |
parent | 30f2b4a215ebd4f9c0c491f41de6e8eb56ed3fdf (diff) | |
download | justbuild-beb3faa6956b9bfd58d4ea6644a9b2987409aaba.tar.gz |
Use HashFunction functionality via Instance()
...to track changes during refactoring easier.
Diffstat (limited to 'test')
-rw-r--r-- | test/buildtool/build_engine/target_map/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/build_engine/target_map/target_map.test.cpp | 5 | ||||
-rw-r--r-- | test/buildtool/crypto/hash_function.test.cpp | 20 | ||||
-rw-r--r-- | test/buildtool/execution_engine/executor/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/execution_engine/executor/executor_api.test.hpp | 24 | ||||
-rw-r--r-- | test/utils/TARGETS | 1 | ||||
-rw-r--r-- | test/utils/remote_execution/main-remote-execution.cpp | 7 |
7 files changed, 33 insertions, 26 deletions
diff --git a/test/buildtool/build_engine/target_map/TARGETS b/test/buildtool/build_engine/target_map/TARGETS index 3bbc42c3..9b3865d8 100644 --- a/test/buildtool/build_engine/target_map/TARGETS +++ b/test/buildtool/build_engine/target_map/TARGETS @@ -42,6 +42,7 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/serve_api/remote", "config"] , ["@", "src", "src/buildtool/serve_api/remote", "serve_api"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] , ["utils", "test_storage_config"] , ["utils", "test_serve_config"] ] diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index 4a475fab..0880422f 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -29,6 +29,7 @@ #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/execution_api/local/config.hpp" #include "src/buildtool/execution_api/remote/config.hpp" @@ -960,10 +961,10 @@ TEST_CASE("built-in rules", "[target_map]") { CHECK(error_msg == "NONE"); CHECK(bar_result->Artifacts()->ToJson()["foo.txt."]["type"] == "KNOWN"); CHECK(bar_result->Artifacts()->ToJson()["foo.txt."]["data"]["id"] == - HashFunction::ComputeBlobHash("bar").HexString()); + HashFunction::Instance().ComputeBlobHash("bar").HexString()); CHECK(baz_result->Artifacts()->ToJson()["foo.txt."]["type"] == "KNOWN"); CHECK(baz_result->Artifacts()->ToJson()["foo.txt."]["data"]["id"] == - HashFunction::ComputeBlobHash("baz").HexString()); + HashFunction::Instance().ComputeBlobHash("baz").HexString()); } } diff --git a/test/buildtool/crypto/hash_function.test.cpp b/test/buildtool/crypto/hash_function.test.cpp index ccee68aa..4a85e327 100644 --- a/test/buildtool/crypto/hash_function.test.cpp +++ b/test/buildtool/crypto/hash_function.test.cpp @@ -22,39 +22,39 @@ TEST_CASE("Hash Function", "[crypto]") { std::string bytes{"test"}; SECTION("Native") { - HashFunction::SetHashType(HashFunction::JustHash::Native); + HashFunction const hash_function{HashFunction::JustHash::Native}; // same as: echo -n test | sha1sum - CHECK(HashFunction::ComputeHash(bytes).HexString() == + CHECK(hash_function.ComputeHash(bytes).HexString() == "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); // same as: echo -n test | git hash-object --stdin - CHECK(HashFunction::ComputeBlobHash(bytes).HexString() == + CHECK(hash_function.ComputeBlobHash(bytes).HexString() == "30d74d258442c7c65512eafab474568dd706c430"); // same as: echo -n test | git hash-object -t "tree" --stdin --literally - CHECK(HashFunction::ComputeTreeHash(bytes).HexString() == + CHECK(hash_function.ComputeTreeHash(bytes).HexString() == "5f0ecc1a989593005e80f457446133250fcc43cc"); - auto hasher = HashFunction::Hasher(); + auto hasher = hash_function.Hasher(); hasher.Update(bytes); CHECK(std::move(hasher).Finalize().HexString() == // NOLINT "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"); } SECTION("Compatible") { - HashFunction::SetHashType(HashFunction::JustHash::Compatible); + HashFunction const hash_function{HashFunction::JustHash::Compatible}; // all same as: echo -n test | sha256sum CHECK( - HashFunction::ComputeHash(bytes).HexString() == + hash_function.ComputeHash(bytes).HexString() == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); CHECK( - HashFunction::ComputeBlobHash(bytes).HexString() == + hash_function.ComputeBlobHash(bytes).HexString() == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); CHECK( - HashFunction::ComputeTreeHash(bytes).HexString() == + hash_function.ComputeTreeHash(bytes).HexString() == "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); - auto hasher = HashFunction::Hasher(); + auto hasher = hash_function.Hasher(); hasher.Update(bytes); CHECK( std::move(hasher).Finalize().HexString() == // NOLINT diff --git a/test/buildtool/execution_engine/executor/TARGETS b/test/buildtool/execution_engine/executor/TARGETS index f6640f01..59acfa43 100644 --- a/test/buildtool/execution_engine/executor/TARGETS +++ b/test/buildtool/execution_engine/executor/TARGETS @@ -12,6 +12,7 @@ , ["@", "src", "src/buildtool/execution_engine/executor", "executor"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/progress_reporting", "progress"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] , ["@", "catch2", "", "catch2"] , ["@", "gsl", "", "gsl"] , ["utils", "test_remote_config"] diff --git a/test/buildtool/execution_engine/executor/executor_api.test.hpp b/test/buildtool/execution_engine/executor/executor_api.test.hpp index e683f373..7009b075 100644 --- a/test/buildtool/execution_engine/executor/executor_api.test.hpp +++ b/test/buildtool/execution_engine/executor/executor_api.test.hpp @@ -29,6 +29,7 @@ #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/common/statistics.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/execution_engine/dag/dag.hpp" @@ -52,9 +53,10 @@ static inline void RunBlobUpload(RepositoryConfig* repo_config, auto api = factory(); std::string const blob = "test"; CHECK(api->Upload(ArtifactBlobContainer{{ArtifactBlob{ - ArtifactDigest{HashFunction::ComputeBlobHash(blob).HexString(), - blob.size(), - /*is_tree=*/false}, + ArtifactDigest{ + HashFunction::Instance().ComputeBlobHash(blob).HexString(), + blob.size(), + /*is_tree=*/false}, blob, /*is_exec=*/false}}})); } @@ -401,14 +403,14 @@ static inline void TestUploadAndDownloadTrees( auto foo = std::string{"foo"}; auto bar = std::string{"bar"}; - auto foo_digest = - ArtifactDigest{HashFunction::ComputeBlobHash(foo).HexString(), - foo.size(), - /*is_tree=*/false}; - auto bar_digest = - ArtifactDigest{HashFunction::ComputeBlobHash(bar).HexString(), - bar.size(), - /*is_tree=*/false}; + auto foo_digest = ArtifactDigest{ + HashFunction::Instance().ComputeBlobHash(foo).HexString(), + foo.size(), + /*is_tree=*/false}; + auto bar_digest = ArtifactDigest{ + HashFunction::Instance().ComputeBlobHash(bar).HexString(), + bar.size(), + /*is_tree=*/false}; // upload blobs auto api = factory(); diff --git a/test/utils/TARGETS b/test/utils/TARGETS index 76bf256c..b7a4db53 100644 --- a/test/utils/TARGETS +++ b/test/utils/TARGETS @@ -77,6 +77,7 @@ , ["@", "src", "src/buildtool/file_system", "git_context"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/compatibility", "compatibility"] + , ["@", "src", "src/buildtool/crypto", "hash_function"] , "log_config" , "test_env" , "test_auth_config" diff --git a/test/utils/remote_execution/main-remote-execution.cpp b/test/utils/remote_execution/main-remote-execution.cpp index 3b4bc60e..05aec296 100644 --- a/test/utils/remote_execution/main-remote-execution.cpp +++ b/test/utils/remote_execution/main-remote-execution.cpp @@ -22,6 +22,7 @@ #include "catch2/catch_session.hpp" #include "catch2/catch_test_macros.hpp" #include "src/buildtool/compatibility/compatibility.hpp" +#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/git_context.hpp" @@ -50,9 +51,9 @@ void ConfigureRemoteExecution() { std::exit(EXIT_FAILURE); } - HashFunction::SetHashType(Compatibility::IsCompatible() - ? HashFunction::JustHash::Compatible - : HashFunction::JustHash::Native); + HashFunction::Instance().SetHashType( + Compatibility::IsCompatible() ? HashFunction::JustHash::Compatible + : HashFunction::JustHash::Native); auto remote_config = TestRemoteConfig::ReadFromEnvironment(); if (not remote_config or remote_config->remote_address == std::nullopt) { |