summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/utils/TARGETS12
-rw-r--r--test/utils/hermeticity/test_hash_function_type.hpp31
-rw-r--r--test/utils/hermeticity/test_storage_config.hpp6
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());