summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2025-05-09 14:55:05 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2025-05-12 18:30:04 +0200
commitfe4006fce755432b1ae3a273873f3649512c7f94 (patch)
tree195fd6727ff7ccc3e2437f757c4b438f83307a3f /test
parent541ccbb58b9d85af308a1cbfbc6642c19758b883 (diff)
downloadjustbuild-fe4006fce755432b1ae3a273873f3649512c7f94.tar.gz
LocalAction: Fix collection of directory symlink
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/execution_api/bazel/bazel_api.test.cpp17
-rw-r--r--test/buildtool/execution_api/common/api_test.hpp32
-rw-r--r--test/buildtool/execution_api/local/local_api.test.cpp13
3 files changed, 62 insertions, 0 deletions
diff --git a/test/buildtool/execution_api/bazel/bazel_api.test.cpp b/test/buildtool/execution_api/bazel/bazel_api.test.cpp
index 8fb50006..bc147ef5 100644
--- a/test/buildtool/execution_api/bazel/bazel_api.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_api.test.cpp
@@ -208,3 +208,20 @@ TEST_CASE("BazelAPI: Create directory prior to execution", "[execution_api]") {
TestCreateDirPriorToExecution(api_factory,
remote_config->platform_properties);
}
+
+TEST_CASE("BazelAPI: Collect file and directory symlinks", "[execution_api]") {
+ auto storage_config = TestStorageConfig::Create();
+ auto remote_config = TestRemoteConfig::ReadFromEnvironment();
+
+ REQUIRE(remote_config);
+ REQUIRE(remote_config->remote_address);
+ auto auth = TestAuthConfig::ReadFromEnvironment();
+ REQUIRE(auth);
+
+ FactoryApi api_factory{
+ &*remote_config->remote_address,
+ &*auth,
+ storage_config.Get().hash_function,
+ storage_config.Get().CreateTypedTmpDir("test_space")};
+ TestSymlinkCollection(api_factory, remote_config->platform_properties);
+}
diff --git a/test/buildtool/execution_api/common/api_test.hpp b/test/buildtool/execution_api/common/api_test.hpp
index f8981434..441c27b0 100644
--- a/test/buildtool/execution_api/common/api_test.hpp
+++ b/test/buildtool/execution_api/common/api_test.hpp
@@ -725,4 +725,36 @@ TestRetrieveFileAndSymlinkWithSameContentToPath(ApiFactory const& api_factory,
}
}
+[[nodiscard]] static inline auto TestSymlinkCollection(
+ ApiFactory const& api_factory,
+ ExecProps const& props) {
+ auto api = api_factory();
+
+ auto action = api->CreateAction(
+ *api->UploadTree({}),
+ {"/bin/sh", "-c", "set -e; ln -s none foo; rm -rf bar; ln -s none bar"},
+ "",
+ {"foo"},
+ {"bar"},
+ {},
+ props);
+
+ // run execution
+ auto const response = action->Execute();
+ REQUIRE(response);
+
+ // verify result
+ auto const artifacts = response->Artifacts();
+ REQUIRE(artifacts.has_value());
+ REQUIRE(artifacts.value()->contains("foo"));
+ CHECK(IsSymlinkObject(artifacts.value()->at("foo").type));
+ REQUIRE(artifacts.value()->contains("bar"));
+ CHECK(IsSymlinkObject(artifacts.value()->at("bar").type));
+
+ // check if bar was correctly detected as directory symlink
+ auto dir_symlinks = response->DirectorySymlinks();
+ REQUIRE(dir_symlinks);
+ CHECK((*dir_symlinks)->contains("bar"));
+}
+
#endif // INCLUDED_SRC_TEST_BUILDTOOL_EXECUTION_API_COMMON_API_TEST_HPP
diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp
index ec065cb7..94b9bf75 100644
--- a/test/buildtool/execution_api/local/local_api.test.cpp
+++ b/test/buildtool/execution_api/local/local_api.test.cpp
@@ -146,3 +146,16 @@ TEST_CASE("LocalAPI: Create directory prior to execution", "[execution_api]") {
TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true);
}
+
+TEST_CASE("LocalAPI: Collect file and directory symlinks", "[execution_api]") {
+ auto const storage_config = TestStorageConfig::Create();
+ auto const storage = Storage::Create(&storage_config.Get());
+ auto const local_exec_config = CreateLocalExecConfig();
+ // pack the local context instances to be passed to LocalApi
+ LocalContext const local_context{.exec_config = &local_exec_config,
+ .storage_config = &storage_config.Get(),
+ .storage = &storage};
+ FactoryApi api_factory(&local_context);
+
+ TestSymlinkCollection(api_factory, {});
+}