diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-03-14 15:27:50 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-03-14 15:27:50 +0100 |
commit | 770b1c5c76b1d88b1e70cb1da8238a86fe78272e (patch) | |
tree | 3b0e9aa56eb5a094eb99d6b28b5883f3490fd481 | |
parent | c069b6f25578bfff9c6756be87f4b80ffbb7a62d (diff) | |
download | justbuild-770b1c5c76b1d88b1e70cb1da8238a86fe78272e.tar.gz |
ExecutionApi: Add test for creating outdirs before execution
-rw-r--r-- | test/buildtool/execution_api/bazel/bazel_api.test.cpp | 4 | ||||
-rw-r--r-- | test/buildtool/execution_api/common/api_test.hpp | 74 | ||||
-rw-r--r-- | test/buildtool/execution_api/local/local_api.test.cpp | 6 |
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); +} |