diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-12 14:28:13 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-13 14:41:00 +0200 |
commit | 5fb67de531fead44123ff30ee5cf37340fc63a0b (patch) | |
tree | 0e1c7c8810e8ee311467e5e07ebb8ff2902adf28 /test/buildtool/execution_api/bazel | |
parent | dd15af0ba4b22348e38d535aadc9fa5e929f3824 (diff) | |
download | justbuild-5fb67de531fead44123ff30ee5cf37340fc63a0b.tar.gz |
Use TestHashType in tests
...instead of calling ProtocolTraits::IsCompatible
Diffstat (limited to 'test/buildtool/execution_api/bazel')
7 files changed, 37 insertions, 69 deletions
diff --git a/test/buildtool/execution_api/bazel/TARGETS b/test/buildtool/execution_api/bazel/TARGETS index 64e52ad6..02b55b78 100644 --- a/test/buildtool/execution_api/bazel/TARGETS +++ b/test/buildtool/execution_api/bazel/TARGETS @@ -9,13 +9,13 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -30,12 +30,12 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/common/remote", "retry_config"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -50,12 +50,12 @@ , ["utils", "test_auth_config"] , ["utils", "test_remote_config"] , ["@", "src", "src/buildtool/common", "bazel_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["@", "src", "src/buildtool/execution_api/remote", "bazel_network"] , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -77,6 +77,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "config"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } @@ -97,8 +98,8 @@ , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/common", "artifact_digest_factory"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["utils", "test_hash_function_type"] , ["@", "src", "src/buildtool/execution_api/common", "common"] , [ "@" , "src" @@ -122,7 +123,7 @@ , ["@", "src", "src/buildtool/execution_api/remote", "bazel"] , ["buildtool/execution_api/common", "api_test"] , ["@", "src", "src/buildtool/crypto", "hash_function"] - , ["@", "src", "src/buildtool/common", "protocol_traits"] + , ["utils", "test_hash_function_type"] ] , "stage": ["test", "buildtool", "execution_api", "bazel"] } diff --git a/test/buildtool/execution_api/bazel/bazel_api.test.cpp b/test/buildtool/execution_api/bazel/bazel_api.test.cpp index 5dc4198d..16c45aae 100644 --- a/test/buildtool/execution_api/bazel/bazel_api.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_api.test.cpp @@ -18,11 +18,11 @@ #include <string> #include "catch2/catch_test_macros.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "test/buildtool/execution_api/common/api_test.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" @@ -59,15 +59,13 @@ class FactoryApi final { TEST_CASE("BazelAPI: No input, no output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestNoInputNoOutput(api_factory, remote_config->platform_properties); @@ -75,15 +73,13 @@ TEST_CASE("BazelAPI: No input, no output", "[execution_api]") { TEST_CASE("BazelAPI: No input, create output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestNoInputCreateOutput(api_factory, remote_config->platform_properties); @@ -91,15 +87,13 @@ TEST_CASE("BazelAPI: No input, create output", "[execution_api]") { TEST_CASE("BazelAPI: One input copied to output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestOneInputCopiedToOutput(api_factory, remote_config->platform_properties); @@ -107,15 +101,13 @@ TEST_CASE("BazelAPI: One input copied to output", "[execution_api]") { TEST_CASE("BazelAPI: Non-zero exit code, create output", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestNonZeroExitCodeCreateOutput(api_factory, @@ -124,15 +116,13 @@ TEST_CASE("BazelAPI: Non-zero exit code, create output", "[execution_api]") { TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestRetrieveTwoIdenticalTreesToPath( @@ -142,15 +132,13 @@ TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") { TEST_CASE("BazelAPI: Retrieve file and symlink with same content to path", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestRetrieveFileAndSymlinkWithSameContentToPath( @@ -159,15 +147,13 @@ TEST_CASE("BazelAPI: Retrieve file and symlink with same content to path", TEST_CASE("BazelAPI: Retrieve mixed blobs and trees", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestRetrieveMixedBlobsAndTrees( @@ -176,15 +162,13 @@ TEST_CASE("BazelAPI: Retrieve mixed blobs and trees", "[execution_api]") { TEST_CASE("BazelAPI: Create directory prior to execution", "[execution_api]") { auto remote_config = TestRemoteConfig::ReadFromEnvironment(); + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + REQUIRE(remote_config); REQUIRE(remote_config->remote_address); auto auth = TestAuthConfig::ReadFromEnvironment(); REQUIRE(auth); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - FactoryApi api_factory{ &*remote_config->remote_address, &*auth, hash_function}; TestCreateDirPriorToExecution(api_factory, 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 4be61071..e8234282 100644 --- a/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_cas_client.test.cpp @@ -21,13 +21,13 @@ #include "catch2/catch_test_macros.hpp" #include "gsl/gsl" #include "src/buildtool/common/bazel_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp" #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.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" @@ -50,10 +50,7 @@ TEST_CASE("Bazel internals: CAS Client", "[execution_api]") { SECTION("Valid digest and blob") { // digest of "test" - HashFunction const hash_function{ - ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto digest = BazelDigestFactory::HashDataAs<ObjectType::File>( hash_function, content); diff --git a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp index a0f77066..e7df319b 100644 --- a/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_execution_client.test.cpp @@ -18,11 +18,11 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/common/bazel_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/common/remote/retry_config.hpp" #include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" #include "test/utils/remote_execution/bazel_action_creator.hpp" #include "test/utils/remote_execution/test_auth_config.hpp" #include "test/utils/remote_execution/test_remote_config.hpp" @@ -31,9 +31,7 @@ TEST_CASE("Bazel internals: Execution Client", "[execution_api]") { std::string instance_name{"remote-execution"}; std::string content("test"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>( hash_function, content); @@ -115,9 +113,7 @@ TEST_CASE("Bazel internals: Execution Client using env variables", std::string instance_name{"remote-execution"}; std::string content("contents of env variable"); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto test_digest = BazelDigestFactory::HashDataAs<ObjectType::File>( hash_function, 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 8ec074f9..5262971c 100644 --- a/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_msg_factory.test.cpp @@ -23,11 +23,11 @@ #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/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.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/hermeticity/test_hash_function_type.hpp" namespace { /// \brief Create a blob from the content found in file or symlink pointed to by @@ -62,9 +62,7 @@ TEST_CASE("Bazel internals: MessageFactory", "[execution_api]") { std::filesystem::path link = subdir1 / "link"; REQUIRE(FileSystemManager::CreateSymlink("file1", link)); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; // create the corresponding blobs auto file1_blob = CreateBlobFromPath(file1, hash_function); diff --git a/test/buildtool/execution_api/bazel/bazel_network.test.cpp b/test/buildtool/execution_api/bazel/bazel_network.test.cpp index c69e7619..8224de74 100644 --- a/test/buildtool/execution_api/bazel/bazel_network.test.cpp +++ b/test/buildtool/execution_api/bazel/bazel_network.test.cpp @@ -29,6 +29,7 @@ #include "src/buildtool/execution_api/remote/bazel/bazel_execution_client.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.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" @@ -46,9 +47,7 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; auto network = BazelNetwork{instance_name, remote_config->remote_address->host, @@ -97,7 +96,8 @@ TEST_CASE("Bazel network: write/read blobs", "[execution_api]") { } TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { - if (ProtocolTraits::Instance().IsCompatible()) { + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; + if (not ProtocolTraits::IsNative(hash_function.GetType())) { // only supported in native mode return; } @@ -113,10 +113,6 @@ TEST_CASE("Bazel network: read blobs with unknown size", "[execution_api]") { RetryConfig retry_config{}; // default retry config - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; - auto network = BazelNetwork{instance_name, remote_config->remote_address->host, remote_config->remote_address->port, diff --git a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp index 1956a6a3..c8b7cac6 100644 --- a/test/buildtool/execution_api/bazel/bytestream_client.test.cpp +++ b/test/buildtool/execution_api/bazel/bytestream_client.test.cpp @@ -21,12 +21,12 @@ #include "catch2/catch_test_macros.hpp" #include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/bazel_digest_factory.hpp" -#include "src/buildtool/common/protocol_traits.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/execution_common.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/file_system/object_type.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" @@ -45,9 +45,7 @@ TEST_CASE("ByteStream Client: Transfer single blob", "[execution_api]") { &*auth_config}; auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId()); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; SECTION("Upload small blob") { std::string instance_name{"remote-execution"}; @@ -152,9 +150,7 @@ TEST_CASE("ByteStream Client: Transfer multiple blobs", "[execution_api]") { &*auth_config}; auto uuid = CreateUUIDVersion4(*CreateProcessUniqueId()); - HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1}; + HashFunction const hash_function{TestHashType::ReadFromEnvironment()}; SECTION("Upload small blobs") { std::string instance_name{"remote-execution"}; |