summaryrefslogtreecommitdiff
path: root/test/buildtool/execution_api/common/api_test.hpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-03-24 18:12:25 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2022-03-25 17:28:13 +0100
commit8aea452283f58c252f992c83dafa614d645466b2 (patch)
tree6dd0836c9260e49393db11f1fc398372b6894c80 /test/buildtool/execution_api/common/api_test.hpp
parent7d70ea28d8ab335928343fb10ad136c9efe4a69e (diff)
downloadjustbuild-8aea452283f58c252f992c83dafa614d645466b2.tar.gz
ExecutionApi: Add test for retrieving mixed blobs and trees
Diffstat (limited to 'test/buildtool/execution_api/common/api_test.hpp')
-rw-r--r--test/buildtool/execution_api/common/api_test.hpp71
1 files changed, 70 insertions, 1 deletions
diff --git a/test/buildtool/execution_api/common/api_test.hpp b/test/buildtool/execution_api/common/api_test.hpp
index e9bd9d4f..e94c6564 100644
--- a/test/buildtool/execution_api/common/api_test.hpp
+++ b/test/buildtool/execution_api/common/api_test.hpp
@@ -15,7 +15,7 @@ using ExecProps = std::map<std::string, std::string>;
-> std::filesystem::path {
auto* tmp_dir = std::getenv("TEST_TMPDIR");
if (tmp_dir != nullptr) {
- return tmp_dir;
+ return std::filesystem::path{tmp_dir} / test_name;
}
return FileSystemManager::GetCurrentDirectory() /
"test/buildtool/execution_api" / test_name;
@@ -390,6 +390,75 @@ using ExecProps = std::map<std::string, std::string>;
}
}
+[[nodiscard]] static inline auto TestRetrieveMixedBlobsAndTrees(
+ ApiFactory const& api_factory,
+ ExecProps const& props,
+ std::string const& test_name,
+ bool is_hermetic = false) {
+ auto api = api_factory();
+
+ auto foo_path = std::filesystem::path{"foo"};
+ auto bar_path = std::filesystem::path{"subdir"} / "bar";
+
+ auto cmd = fmt::format("set -e\nmkdir -p {}\ntouch {} {}",
+ bar_path.parent_path().string(),
+ bar_path.string(),
+ foo_path.string());
+
+ auto action = api->CreateAction(*api->UploadTree({}),
+ {"/bin/sh", "-c", cmd},
+ {foo_path.string()},
+ {bar_path.parent_path().string()},
+ {},
+ props);
+
+ action->SetCacheFlag(IExecutionAction::CacheFlag::CacheOutput);
+
+ // run execution
+ auto response = action->Execute();
+ REQUIRE(response);
+
+ // verify result
+ CHECK(response->ExitCode() == 0);
+
+ if (is_hermetic) {
+ CHECK_FALSE(response->IsCached());
+ }
+
+ auto artifacts = response->Artifacts();
+ REQUIRE_FALSE(artifacts.empty());
+
+ std::vector<std::filesystem::path> paths{};
+ std::vector<Artifact::ObjectInfo> infos{};
+
+ SECTION("retrieve via same API object") {
+ auto out_path = GetTestDir(test_name) / "out1";
+ std::for_each(artifacts.begin(),
+ artifacts.end(),
+ [&out_path, &paths, &infos](auto const& entry) {
+ paths.emplace_back(out_path / entry.first);
+ infos.emplace_back(entry.second);
+ });
+ CHECK(api->RetrieveToPaths(infos, paths));
+ CHECK(FileSystemManager::IsFile(out_path / foo_path));
+ CHECK(FileSystemManager::IsFile(out_path / bar_path));
+ }
+
+ SECTION("retrieve from new API object but same endpoint") {
+ auto second_api = api_factory();
+ auto out_path = GetTestDir(test_name) / "out2";
+ std::for_each(artifacts.begin(),
+ artifacts.end(),
+ [&out_path, &paths, &infos](auto const& entry) {
+ paths.emplace_back(out_path / entry.first);
+ infos.emplace_back(entry.second);
+ });
+ CHECK(second_api->RetrieveToPaths(infos, paths));
+ CHECK(FileSystemManager::IsFile(out_path / foo_path));
+ CHECK(FileSystemManager::IsFile(out_path / bar_path));
+ }
+}
+
[[nodiscard]] static inline auto TestCreateDirPriorToExecution(
ApiFactory const& api_factory,
ExecProps const& props,