From 770b1c5c76b1d88b1e70cb1da8238a86fe78272e Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 14 Mar 2022 15:27:50 +0100 Subject: ExecutionApi: Add test for creating outdirs before execution --- test/buildtool/execution_api/common/api_test.hpp | 74 ++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'test/buildtool/execution_api/common/api_test.hpp') 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; 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()); + } + } +} -- cgit v1.2.3