summaryrefslogtreecommitdiff
path: root/test/buildtool/execution_api/common/api_test.hpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-03-14 15:27:50 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2022-03-14 15:27:50 +0100
commit770b1c5c76b1d88b1e70cb1da8238a86fe78272e (patch)
tree3b0e9aa56eb5a094eb99d6b28b5883f3490fd481 /test/buildtool/execution_api/common/api_test.hpp
parentc069b6f25578bfff9c6756be87f4b80ffbb7a62d (diff)
downloadjustbuild-770b1c5c76b1d88b1e70cb1da8238a86fe78272e.tar.gz
ExecutionApi: Add test for creating outdirs before execution
Diffstat (limited to 'test/buildtool/execution_api/common/api_test.hpp')
-rw-r--r--test/buildtool/execution_api/common/api_test.hpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/buildtool/execution_api/common/api_test.hpp b/test/buildtool/execution_api/common/api_test.hpp
index 0d5fc2e1..e9bd9d4f 100644
--- a/test/buildtool/execution_api/common/api_test.hpp
+++ b/test/buildtool/execution_api/common/api_test.hpp
@@ -389,3 +389,77 @@ using ExecProps = std::map<std::string, std::string>;
FileSystemManager::ReadFile(out_path / bar_path));
}
}
+
+[[nodiscard]] static inline auto TestCreateDirPriorToExecution(
+ ApiFactory const& api_factory,
+ ExecProps const& props,
+ bool is_hermetic = false) {
+ auto api = api_factory();
+
+ auto output_path = std::filesystem::path{"foo/bar/baz"};
+
+ auto action = api->CreateAction(
+ *api->UploadTree({}),
+ {"/bin/sh",
+ "-c",
+ fmt::format("set -e\n [ -d {} ]", output_path.string())},
+ {},
+ {output_path},
+ {},
+ props);
+
+ SECTION("Cache execution result in action cache") {
+ action->SetCacheFlag(IExecutionAction::CacheFlag::CacheOutput);
+
+ // run execution
+ auto response = action->Execute();
+ REQUIRE(response);
+
+ // verify result
+ auto artifacts = response->Artifacts();
+ REQUIRE(artifacts.contains(output_path));
+ CHECK(IsTreeObject(artifacts.at(output_path).type));
+
+ if (is_hermetic) {
+ CHECK(not response->IsCached());
+
+ SECTION("Rerun execution to verify caching") {
+ // run execution
+ auto response = action->Execute();
+ REQUIRE(response);
+
+ // verify result
+ auto artifacts = response->Artifacts();
+ REQUIRE(artifacts.contains(output_path));
+ CHECK(IsTreeObject(artifacts.at(output_path).type));
+ CHECK(response->IsCached());
+ }
+ }
+ }
+
+ SECTION("Do not cache execution result in action cache") {
+ action->SetCacheFlag(IExecutionAction::CacheFlag::DoNotCacheOutput);
+
+ // run execution
+ auto response = action->Execute();
+ REQUIRE(response);
+
+ // verify result
+ auto artifacts = response->Artifacts();
+ REQUIRE(artifacts.contains(output_path));
+ CHECK(IsTreeObject(artifacts.at(output_path).type));
+ CHECK(not response->IsCached());
+
+ SECTION("Rerun execution to verify caching") {
+ // run execution
+ auto response = action->Execute();
+ REQUIRE(response);
+
+ // verify result
+ auto artifacts = response->Artifacts();
+ REQUIRE(artifacts.contains(output_path));
+ CHECK(IsTreeObject(artifacts.at(output_path).type));
+ CHECK(not response->IsCached());
+ }
+ }
+}