summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/buildtool/execution_api/bazel/bazel_api.test.cpp4
-rw-r--r--test/buildtool/execution_api/common/api_test.hpp74
-rw-r--r--test/buildtool/execution_api/local/local_api.test.cpp6
3 files changed, 84 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 df9e8c65..952edcda 100644
--- a/test/buildtool/execution_api/bazel/bazel_api.test.cpp
+++ b/test/buildtool/execution_api/bazel/bazel_api.test.cpp
@@ -38,3 +38,7 @@ TEST_CASE("BazelAPI: Retrieve two identical trees to path", "[execution_api]") {
TestRetrieveTwoIdenticalTreesToPath(
api_factory, ReadPlatformPropertiesFromEnv(), "remote");
}
+
+TEST_CASE("BazelAPI: Create directory prior to execution", "[execution_api]") {
+ TestCreateDirPriorToExecution(api_factory, ReadPlatformPropertiesFromEnv());
+}
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());
+ }
+ }
+}
diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp
index e01ae7de..7ffd65fd 100644
--- a/test/buildtool/execution_api/local/local_api.test.cpp
+++ b/test/buildtool/execution_api/local/local_api.test.cpp
@@ -42,3 +42,9 @@ TEST_CASE_METHOD(HermeticLocalTestFixture,
TestRetrieveTwoIdenticalTreesToPath(
api_factory, {}, "local", /*is_hermetic=*/true);
}
+
+TEST_CASE_METHOD(HermeticLocalTestFixture,
+ "LocalAPI: Create directory prior to execution",
+ "[execution_api]") {
+ TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true);
+}