diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-12 14:27:44 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-09-13 14:41:00 +0200 |
commit | dd15af0ba4b22348e38d535aadc9fa5e929f3824 (patch) | |
tree | a2504746ec5ff77bafcfa9ec66795b9e22ad42a7 | |
parent | 4f7d0c2af84d25a8b8b7a5c0ad7b58d94b4c8f7c (diff) | |
download | justbuild-dd15af0ba4b22348e38d535aadc9fa5e929f3824.tar.gz |
Implement TestHashType class
...that is designed to provide an access to the hash type in tests based on the environment variable
-rw-r--r-- | test/utils/TARGETS | 12 | ||||
-rw-r--r-- | test/utils/hermeticity/test_hash_function_type.hpp | 31 | ||||
-rw-r--r-- | test/utils/hermeticity/test_storage_config.hpp | 6 |
3 files changed, 44 insertions, 5 deletions
diff --git a/test/utils/TARGETS b/test/utils/TARGETS index d0a427a6..ffded132 100644 --- a/test/utils/TARGETS +++ b/test/utils/TARGETS @@ -53,7 +53,17 @@ , ["@", "src", "src/buildtool/logging", "logging"] , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/utils/cpp", "tmp_dir"] - , ["@", "src", "src/buildtool/crypto", "hash_function"] + , ["@", "src", "src/buildtool/common", "protocol_traits"] + , "test_hash_function_type" + ] + , "stage": ["test", "utils"] + } +, "test_hash_function_type": + { "type": ["@", "rules", "CC", "library"] + , "name": ["test_hash_function_type"] + , "hdrs": ["hermeticity/test_hash_function_type.hpp"] + , "deps": + [ ["@", "src", "src/buildtool/crypto", "hash_function"] , ["@", "src", "src/buildtool/common", "protocol_traits"] ] , "stage": ["test", "utils"] diff --git a/test/utils/hermeticity/test_hash_function_type.hpp b/test/utils/hermeticity/test_hash_function_type.hpp new file mode 100644 index 00000000..14c89d4a --- /dev/null +++ b/test/utils/hermeticity/test_hash_function_type.hpp @@ -0,0 +1,31 @@ +// 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_HERMETICITY_TEST_HASH_FUNCTION_TYPE_HPP +#define INCLUDED_SRC_TEST_UTILS_HERMETICITY_TEST_HASH_FUNCTION_TYPE_HPP + +#include "src/buildtool/common/protocol_traits.hpp" +#include "src/buildtool/crypto/hash_function.hpp" + +class TestHashType final { + public: + [[nodiscard]] static auto ReadFromEnvironment() noexcept + -> HashFunction::Type { + return ProtocolTraits::Instance().IsCompatible() + ? HashFunction::Type::PlainSHA256 + : HashFunction::Type::GitSHA1; + } +}; + +#endif // INCLUDED_SRC_TEST_UTILS_HERMETICITY_TEST_HASH_FUNCTION_TYPE_HPP diff --git a/test/utils/hermeticity/test_storage_config.hpp b/test/utils/hermeticity/test_storage_config.hpp index 4820782f..5f5ecab4 100644 --- a/test/utils/hermeticity/test_storage_config.hpp +++ b/test/utils/hermeticity/test_storage_config.hpp @@ -22,11 +22,11 @@ #include "gsl/gsl" #include "src/buildtool/common/protocol_traits.hpp" -#include "src/buildtool/crypto/hash_function.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/buildtool/storage/config.hpp" #include "src/utils/cpp/tmp_dir.hpp" +#include "test/utils/hermeticity/test_hash_function_type.hpp" class TestStorageConfig final { public: @@ -54,9 +54,7 @@ class TestStorageConfig final { StorageConfig::Builder builder; auto config = builder.SetBuildRoot(temp_dir->GetPath()) - .SetHashType(ProtocolTraits::Instance().IsCompatible() - ? HashFunction::Type::PlainSHA256 - : HashFunction::Type::GitSHA1) + .SetHashType(TestHashType::ReadFromEnvironment()) .Build(); if (not config) { Logger::Log(LogLevel::Error, config.error()); |