From 5140befaa10f65145fe041b416b7764127efc379 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 4 Jul 2024 12:25:20 +0200 Subject: Convert Storage to a general class --- .../execution_api/local/local_api.test.cpp | 49 +++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'test/buildtool/execution_api/local/local_api.test.cpp') diff --git a/test/buildtool/execution_api/local/local_api.test.cpp b/test/buildtool/execution_api/local/local_api.test.cpp index fa296c9b..de875a2c 100644 --- a/test/buildtool/execution_api/local/local_api.test.cpp +++ b/test/buildtool/execution_api/local/local_api.test.cpp @@ -23,10 +23,21 @@ #include "test/utils/hermeticity/local.hpp" namespace { +class FactoryApi final { + public: + explicit FactoryApi( + gsl::not_null const& storage, + gsl::not_null const& storage_config) noexcept + : storage_{*storage}, storage_config_{*storage_config} {} -auto const kApiFactory = []() { - return IExecutionApi::Ptr{ - new LocalApi(&StorageConfig::Instance(), &Storage::Instance())}; + [[nodiscard]] auto operator()() const -> IExecutionApi::Ptr { + return IExecutionApi::Ptr{ + new LocalApi{&StorageConfig::Instance(), &storage_}}; + } + + private: + Storage const& storage_; + StorageConfig const& storage_config_; }; } // namespace @@ -34,51 +45,67 @@ auto const kApiFactory = []() { TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: No input, no output", "[execution_api]") { - TestNoInputNoOutput(kApiFactory, {}, /*is_hermetic=*/true); + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); + TestNoInputNoOutput(api_factory, {}, /*is_hermetic=*/true); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: No input, create output", "[execution_api]") { - TestNoInputCreateOutput(kApiFactory, {}, /*is_hermetic=*/true); + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); + TestNoInputCreateOutput(api_factory, {}, /*is_hermetic=*/true); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: One input copied to output", "[execution_api]") { - TestOneInputCopiedToOutput(kApiFactory, {}, /*is_hermetic=*/true); + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); + TestOneInputCopiedToOutput(api_factory, {}, /*is_hermetic=*/true); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: Non-zero exit code, create output", "[execution_api]") { - TestNonZeroExitCodeCreateOutput(kApiFactory, {}); + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); + TestNonZeroExitCodeCreateOutput(api_factory, {}); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: Retrieve two identical trees to path", "[execution_api]") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); TestRetrieveTwoIdenticalTreesToPath( - kApiFactory, {}, "two_trees", /*is_hermetic=*/true); + api_factory, {}, "two_trees", /*is_hermetic=*/true); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: Retrieve file and symlink with same content to " "path", "[execution_api]") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); TestRetrieveFileAndSymlinkWithSameContentToPath( - kApiFactory, {}, "file_and_symlink", /*is_hermetic=*/true); + api_factory, {}, "file_and_symlink", /*is_hermetic=*/true); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: Retrieve mixed blobs and trees", "[execution_api]") { + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); TestRetrieveMixedBlobsAndTrees( - kApiFactory, {}, "blobs_and_trees", /*is_hermetic=*/true); + api_factory, {}, "blobs_and_trees", /*is_hermetic=*/true); } TEST_CASE_METHOD(HermeticLocalTestFixture, "LocalAPI: Create directory prior to execution", "[execution_api]") { - TestCreateDirPriorToExecution(kApiFactory, {}, /*is_hermetic=*/true); + auto const storage = Storage::Create(&StorageConfig::Instance()); + FactoryApi api_factory(&storage, &StorageConfig::Instance()); + TestCreateDirPriorToExecution(api_factory, {}, /*is_hermetic=*/true); } -- cgit v1.2.3