diff options
Diffstat (limited to 'test/buildtool/execution_api')
-rw-r--r-- | test/buildtool/execution_api/common/api_test.hpp | 13 | ||||
-rw-r--r-- | test/buildtool/execution_api/local/local_api.test.cpp | 32 | ||||
-rw-r--r-- | test/buildtool/execution_api/local/local_execution.test.cpp | 48 |
3 files changed, 45 insertions, 48 deletions
diff --git a/test/buildtool/execution_api/common/api_test.hpp b/test/buildtool/execution_api/common/api_test.hpp index d43c850d..f9a814f7 100644 --- a/test/buildtool/execution_api/common/api_test.hpp +++ b/test/buildtool/execution_api/common/api_test.hpp @@ -32,7 +32,8 @@ using ApiFactory = std::function<IExecutionApi::Ptr()>; using ExecProps = std::map<std::string, std::string>; -inline void SetLauncher() { +[[nodiscard]] static inline auto SetLauncher() noexcept + -> LocalExecutionConfig { std::vector<std::string> launcher{"env"}; auto* env_path = std::getenv("PATH"); if (env_path != nullptr) { @@ -41,10 +42,12 @@ inline void SetLauncher() { else { launcher.emplace_back("PATH=/bin:/usr/bin"); } - if (not LocalExecutionConfig::SetLauncher(launcher)) { - Logger::Log(LogLevel::Error, "Failure setting the local launcher."); - std::exit(EXIT_FAILURE); + LocalExecutionConfig::Builder builder; + if (auto config = builder.SetLauncher(std::move(launcher)).Build()) { + return *std::move(config); } + Logger::Log(LogLevel::Error, "Failure setting the local launcher."); + std::exit(EXIT_FAILURE); } [[nodiscard]] static inline auto GetTestDir(std::string const& test_name) @@ -68,8 +71,6 @@ inline void SetLauncher() { auto action = api->CreateAction( *api->UploadTree({}), {"echo", "-n", test_content}, {}, {}, {}, props); - SetLauncher(); - SECTION("Cache execution result in action cache") { action->SetCacheFlag(IExecutionAction::CacheFlag::CacheOutput); diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp index 164226b9..6a6b899a 100644 --- a/test/buildtool/execution_api/local/local_api.test.cpp +++ b/test/buildtool/execution_api/local/local_api.test.cpp @@ -51,8 +51,8 @@ class FactoryApi final { TEST_CASE("LocalAPI: No input, no output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestNoInputNoOutput(api_factory, {}, /*is_hermetic=*/true); } @@ -60,8 +60,8 @@ TEST_CASE("LocalAPI: No input, no output", "[execution_api]") { TEST_CASE("LocalAPI: No input, create output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestNoInputCreateOutput(api_factory, {}, /*is_hermetic=*/true); } @@ -69,8 +69,8 @@ TEST_CASE("LocalAPI: No input, create output", "[execution_api]") { TEST_CASE("LocalAPI: One input copied to output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestOneInputCopiedToOutput(api_factory, {}, /*is_hermetic=*/true); } @@ -78,8 +78,8 @@ TEST_CASE("LocalAPI: One input copied to output", "[execution_api]") { TEST_CASE("LocalAPI: Non-zero exit code, create output", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestNonZeroExitCodeCreateOutput(api_factory, {}); } @@ -87,8 +87,8 @@ TEST_CASE("LocalAPI: Non-zero exit code, create output", "[execution_api]") { TEST_CASE("LocalAPI: Retrieve two identical trees to path", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestRetrieveTwoIdenticalTreesToPath( api_factory, {}, "two_trees", /*is_hermetic=*/true); @@ -98,8 +98,8 @@ TEST_CASE("LocalAPI: Retrieve file and symlink with same content to path", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestRetrieveFileAndSymlinkWithSameContentToPath( api_factory, {}, "file_and_symlink", /*is_hermetic=*/true); @@ -108,8 +108,8 @@ TEST_CASE("LocalAPI: Retrieve file and symlink with same content to path", TEST_CASE("LocalAPI: Retrieve mixed blobs and trees", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestRetrieveMixedBlobsAndTrees( api_factory, {}, "blobs_and_trees", /*is_hermetic=*/true); @@ -118,8 +118,8 @@ TEST_CASE("LocalAPI: Retrieve mixed blobs and trees", "[execution_api]") { TEST_CASE("LocalAPI: Create directory prior to execution", "[execution_api]") { auto const storage_config = TestStorageConfig::Create(); auto const storage = Storage::Create(&storage_config.Get()); - FactoryApi api_factory( - &storage_config.Get(), &storage, &LocalExecutionConfig::Instance()); + auto const local_exec_config = SetLauncher(); + FactoryApi api_factory(&storage_config.Get(), &storage, &local_exec_config); TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true); } diff --git a/test/buildtool/execution_api/local/local_execution.test.cpp b/test/buildtool/execution_api/local/local_execution.test.cpp index e8489b33..72db2800 100644 --- a/test/buildtool/execution_api/local/local_execution.test.cpp +++ b/test/buildtool/execution_api/local/local_execution.test.cpp @@ -41,7 +41,8 @@ namespace { "test/buildtool/execution_api/local"; } -inline void SetLauncher() { +[[nodiscard]] inline auto CreateLocalExecConfig() noexcept + -> LocalExecutionConfig { std::vector<std::string> launcher{"env"}; auto* env_path = std::getenv("PATH"); if (env_path != nullptr) { @@ -50,10 +51,12 @@ inline void SetLauncher() { else { launcher.emplace_back("PATH=/bin:/usr/bin"); } - if (not LocalExecutionConfig::SetLauncher(launcher)) { - Logger::Log(LogLevel::Error, "Failure setting the local launcher."); - std::exit(EXIT_FAILURE); + LocalExecutionConfig::Builder builder; + if (auto config = builder.SetLauncher(std::move(launcher)).Build()) { + return *std::move(config); } + Logger::Log(LogLevel::Error, "Failure setting the local launcher."); + std::exit(EXIT_FAILURE); } } // namespace @@ -63,10 +66,9 @@ TEST_CASE("LocalExecution: No input, no output", "[execution_api]") { auto const storage = Storage::Create(&storage_config.Get()); RepositoryConfig repo_config{}; - auto api = LocalApi(&storage_config.Get(), - &storage, - &LocalExecutionConfig::Instance(), - &repo_config); + auto const local_exec_config = CreateLocalExecConfig(); + auto api = LocalApi( + &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); std::vector<std::string> const cmdline = {"echo", "-n", test_content}; @@ -74,8 +76,6 @@ TEST_CASE("LocalExecution: No input, no output", "[execution_api]") { api.CreateAction(*api.UploadTree({}), cmdline, {}, {}, {}, {}); REQUIRE(action); - SetLauncher(); - SECTION("Cache execution result in action cache") { // run execution action->SetCacheFlag(IExecutionAction::CacheFlag::CacheOutput); @@ -114,10 +114,9 @@ TEST_CASE("LocalExecution: No input, no output, env variables used", auto const storage = Storage::Create(&storage_config.Get()); RepositoryConfig repo_config{}; - auto api = LocalApi(&storage_config.Get(), - &storage, - &LocalExecutionConfig::Instance(), - &repo_config); + auto const local_exec_config = CreateLocalExecConfig(); + auto api = LocalApi( + &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test from env var"); std::vector<std::string> const cmdline = { @@ -168,10 +167,9 @@ TEST_CASE("LocalExecution: No input, create output", "[execution_api]") { auto const storage = Storage::Create(&storage_config.Get()); RepositoryConfig repo_config{}; - auto api = LocalApi(&storage_config.Get(), - &storage, - &LocalExecutionConfig::Instance(), - &repo_config); + auto const local_exec_config = CreateLocalExecConfig(); + auto api = LocalApi( + &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); @@ -228,10 +226,9 @@ TEST_CASE("LocalExecution: One input copied to output", "[execution_api]") { auto const storage = Storage::Create(&storage_config.Get()); RepositoryConfig repo_config{}; - auto api = LocalApi(&storage_config.Get(), - &storage, - &LocalExecutionConfig::Instance(), - &repo_config); + auto const local_exec_config = CreateLocalExecConfig(); + auto api = LocalApi( + &storage_config.Get(), &storage, &local_exec_config, &repo_config); std::string test_content("test"); auto test_digest = ArtifactDigest::Create<ObjectType::File>(test_content); @@ -301,10 +298,9 @@ TEST_CASE("LocalExecution: Cache failed action's result", "[execution_api]") { auto const storage = Storage::Create(&storage_config.Get()); RepositoryConfig repo_config{}; - auto api = LocalApi(&storage_config.Get(), - &storage, - &LocalExecutionConfig::Instance(), - &repo_config); + auto const local_exec_config = CreateLocalExecConfig(); + auto api = LocalApi( + &storage_config.Get(), &storage, &local_exec_config, &repo_config); auto flag = GetTestDir() / "flag"; std::vector<std::string> const cmdline = { |