diff options
Diffstat (limited to 'test/buildtool')
-rw-r--r-- | test/buildtool/build_engine/base_maps/TARGETS | 10 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/directory_map.test.cpp | 24 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/expression_map.test.cpp | 47 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/json_file_map.test.cpp | 55 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/rule_map.test.cpp | 54 | ||||
-rw-r--r-- | test/buildtool/build_engine/base_maps/source_map.test.cpp | 64 | ||||
-rw-r--r-- | test/buildtool/common/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/common/repository_config.test.cpp | 62 | ||||
-rw-r--r-- | test/buildtool/file_system/TARGETS | 1 | ||||
-rw-r--r-- | test/buildtool/file_system/file_root.test.cpp | 69 |
10 files changed, 286 insertions, 101 deletions
diff --git a/test/buildtool/build_engine/base_maps/TARGETS b/test/buildtool/build_engine/base_maps/TARGETS index 2bd0882a..ac75dd9e 100644 --- a/test/buildtool/build_engine/base_maps/TARGETS +++ b/test/buildtool/build_engine/base_maps/TARGETS @@ -33,7 +33,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -50,7 +52,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -72,8 +76,10 @@ , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] , ["utils", "test_hash_function_type"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -92,7 +98,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } @@ -112,7 +120,9 @@ , ["@", "src", "src/buildtool/common", "config"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/multithreading", "task_system"] + , ["@", "src", "src/buildtool/storage", "config"] , ["", "catch-main"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "build_engine", "base_maps"] } diff --git a/test/buildtool/build_engine/base_maps/directory_map.test.cpp b/test/buildtool/build_engine/base_maps/directory_map.test.cpp index 8f53454b..6538a371 100644 --- a/test/buildtool/build_engine/base_maps/directory_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/directory_map.test.cpp @@ -25,18 +25,23 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath / "data_src"}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kSrcTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kSrcTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -47,8 +52,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadDirectory(ModuleName const& id, DirectoryEntriesMap::Consumer value_checker, + StorageConfig const* storage_config, bool use_git = false) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto data_direntries = CreateDirectoryEntriesMap(&repo_config); bool success{true}; { @@ -77,12 +83,14 @@ TEST_CASE("simple usage") { }; SECTION("via file") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/false)); + CHECK(ReadDirectory(name, consumer, nullptr, /*use_git=*/false)); CHECK(as_expected); } SECTION("via git tree") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadDirectory( + name, consumer, &storage_config.Get(), /*use_git=*/true)); CHECK(as_expected); } } @@ -97,12 +105,14 @@ TEST_CASE("missing directory") { }; SECTION("via file") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/false)); + CHECK(ReadDirectory(name, consumer, nullptr, /*use_git=*/false)); CHECK(as_expected); } SECTION("via git tree") { - CHECK(ReadDirectory(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadDirectory( + name, consumer, &storage_config.Get(), /*use_git=*/true)); CHECK(as_expected); } } diff --git a/test/buildtool/build_engine/base_maps/expression_map.test.cpp b/test/buildtool/build_engine/base_maps/expression_map.test.cpp index 86e95a32..098c884b 100644 --- a/test/buildtool/build_engine/base_maps/expression_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/expression_map.test.cpp @@ -28,18 +28,23 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath / "data_expr"}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kExprTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kExprTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -50,8 +55,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadExpressionFunction(EntityName const& id, ExpressionFunctionMap::Consumer value_checker, + StorageConfig const* storage_config = nullptr, bool use_git = false) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto expr_file_map = CreateExpressionFileMap(&repo_config, 0); auto expr_func_map = CreateExpressionMap(&expr_file_map, &repo_config); @@ -83,11 +89,14 @@ TEST_CASE("Simple expression object literal", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -106,11 +115,14 @@ TEST_CASE("Simple read of variable", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -129,11 +141,14 @@ TEST_CASE("Simple call of imported expression", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -152,11 +167,14 @@ TEST_CASE("Overwrite import in nested expression", "[expression_map]") { }; SECTION("via file") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -167,11 +185,14 @@ TEST_CASE("Fail due to unkown ID", "[expression_map]") { }; SECTION("via file") { - CHECK_FALSE(ReadExpressionFunction(name, consumer, /*use_git=*/false)); + CHECK_FALSE( + ReadExpressionFunction(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK_FALSE(ReadExpressionFunction(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadExpressionFunction( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } diff --git a/test/buildtool/build_engine/base_maps/json_file_map.test.cpp b/test/buildtool/build_engine/base_maps/json_file_map.test.cpp index 65064927..ecdcbd9e 100644 --- a/test/buildtool/build_engine/base_maps/json_file_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/json_file_map.test.cpp @@ -25,19 +25,24 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT auto SetupConfig(std::string target_file_name, + StorageConfig const* storage_config, bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kJsonTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kJsonTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -52,10 +57,11 @@ template <bool kMandatory = true> auto ReadJsonFile(std::string const& target_file_name, ModuleName const& id, JsonFileMap::Consumer value_checker, + StorageConfig const* storage_config, bool use_git = false, std::optional<JsonFileMap::FailureFunction> fail_func = std::nullopt) -> bool { - auto repo_config = SetupConfig(target_file_name, use_git); + auto repo_config = SetupConfig(target_file_name, storage_config, use_git); auto json_files = CreateJsonFileMap<&RepositoryConfig::WorkspaceRoot, &RepositoryConfig::TargetFileName, kMandatory>(&repo_config, 0); @@ -86,12 +92,18 @@ TEST_CASE("simple usage") { }; SECTION("via file") { - CHECK(ReadJsonFile("foo.json", name, consumer, /*use_git=*/false)); + CHECK(ReadJsonFile( + "foo.json", name, consumer, nullptr, /*use_git=*/false)); CHECK(as_expected); } SECTION("via git tree") { - CHECK(ReadJsonFile("foo.json", name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadJsonFile("foo.json", + name, + consumer, + &storage_config.Get(), + /*use_git=*/true)); CHECK(as_expected); } } @@ -113,15 +125,24 @@ TEST_CASE("non existent") { auto name = ModuleName{"", "missing"}; SECTION("via file") { - CHECK(ReadJsonFile<false>( - "foo.json", name, consumer, /*use_git=*/false, fail_func)); + CHECK(ReadJsonFile<false>("foo.json", + name, + consumer, + nullptr, + /*use_git=*/false, + fail_func)); CHECK(as_expected); CHECK(failcont_counter == 0); } SECTION("via git tree") { - CHECK(ReadJsonFile<false>( - "foo.json", name, consumer, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadJsonFile<false>("foo.json", + name, + consumer, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK(as_expected); CHECK(failcont_counter == 0); } @@ -131,15 +152,24 @@ TEST_CASE("non existent") { auto name = ModuleName{"", "missing"}; SECTION("via file") { - CHECK_FALSE(ReadJsonFile<true>( - "foo.json", name, consumer, /*use_git=*/false, fail_func)); + CHECK_FALSE(ReadJsonFile<true>("foo.json", + name, + consumer, + nullptr, + /*use_git=*/false, + fail_func)); CHECK_FALSE(as_expected); CHECK(failcont_counter == 1); } SECTION("via git tree") { - CHECK_FALSE(ReadJsonFile<true>( - "foo.json", name, consumer, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadJsonFile<true>("foo.json", + name, + consumer, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK_FALSE(as_expected); CHECK(failcont_counter == 1); } @@ -153,6 +183,7 @@ TEST_CASE("Bad syntax") { "bad.json", {"", "data_json"}, [](auto const& /* unused */) {}, + nullptr, /*use_git=*/false, fail_func)); CHECK(failcont_counter == 1); diff --git a/test/buildtool/build_engine/base_maps/rule_map.test.cpp b/test/buildtool/build_engine/base_maps/rule_map.test.cpp index eb91aaf5..f3a64954 100644 --- a/test/buildtool/build_engine/base_maps/rule_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/rule_map.test.cpp @@ -29,18 +29,23 @@ #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { auto root = FileRoot{kBasePath / "data_rule"}; if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kRuleTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kRuleTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -51,8 +56,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadUserRule(EntityName const& id, UserRuleMap::Consumer value_checker, + StorageConfig const* storage_config = nullptr, bool use_git = false) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto expr_file_map = CreateExpressionFileMap(&repo_config, 0); auto expr_func_map = CreateExpressionMap(&expr_file_map, &repo_config); auto rule_file_map = CreateRuleFileMap(&repo_config, 0); @@ -80,11 +86,13 @@ TEST_CASE("Test empty rule", "[expression_map]") { auto consumer = [](auto values) { REQUIRE(values[0]); }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -101,11 +109,13 @@ TEST_CASE("Test rule fields", "[rule_map]") { }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -117,11 +127,13 @@ TEST_CASE("Test config_transitions target", "[rule_map]") { EntityName{"", ".", "test_config_transitions_target_via_field"}; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } SECTION("via implicit") { @@ -129,11 +141,13 @@ TEST_CASE("Test config_transitions target", "[rule_map]") { EntityName{"", ".", "test_config_transitions_target_via_implicit"}; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } } @@ -159,11 +173,13 @@ TEST_CASE("Test config_transitions canonicalness", "[rule_map]") { }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -185,11 +201,13 @@ TEST_CASE("Test call of imported expression", "[rule_map]") { }; SECTION("via file") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } @@ -200,11 +218,13 @@ TEST_CASE("Fail due to unknown ID", "[rule_map]") { }; SECTION("via file") { - CHECK_FALSE(ReadUserRule(name, consumer, /*use_git=*/false)); + CHECK_FALSE(ReadUserRule(name, consumer, nullptr, /*use_git=*/false)); } SECTION("via git tree") { - CHECK_FALSE(ReadUserRule(name, consumer, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadUserRule( + name, consumer, &storage_config.Get(), /*use_git=*/true)); } } diff --git a/test/buildtool/build_engine/base_maps/source_map.test.cpp b/test/buildtool/build_engine/base_maps/source_map.test.cpp index 08f6149d..d63271b8 100644 --- a/test/buildtool/build_engine/base_maps/source_map.test.cpp +++ b/test/buildtool/build_engine/base_maps/source_map.test.cpp @@ -31,14 +31,17 @@ #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/multithreading/task_system.hpp" +#include "src/buildtool/storage/config.hpp" #include "test/buildtool/build_engine/base_maps/test_repo.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" namespace { using namespace BuildMaps::Base; // NOLINT -auto SetupConfig(bool use_git) -> RepositoryConfig { +auto SetupConfig(StorageConfig const* storage_config, + bool use_git) -> RepositoryConfig { // manually create locally a test symlink in data_src; should match the // git test_repo structure if (not use_git) { @@ -51,7 +54,9 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { if (use_git) { auto repo_path = CreateTestRepo(); REQUIRE(repo_path); - auto git_root = FileRoot::FromGit(*repo_path, kSrcTreeId); + REQUIRE(storage_config); + auto git_root = + FileRoot::FromGit(storage_config, *repo_path, kSrcTreeId); REQUIRE(git_root); root = std::move(*git_root); } @@ -63,10 +68,11 @@ auto SetupConfig(bool use_git) -> RepositoryConfig { auto ReadSourceTarget(EntityName const& id, SourceTargetMap::Consumer consumer, HashFunction::Type hash_type, + StorageConfig const* storage_config, bool use_git = false, std::optional<SourceTargetMap::FailureFunction> fail_func = std::nullopt) -> bool { - auto repo_config = SetupConfig(use_git); + auto repo_config = SetupConfig(storage_config, use_git); auto directory_entries = CreateDirectoryEntriesMap(&repo_config); auto source_artifacts = CreateSourceTargetMap(&directory_entries, &repo_config, hash_type); @@ -99,13 +105,19 @@ TEST_CASE("from file") { }; SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); + CHECK(ReadSourceTarget( + name, consumer, hash_type, nullptr, /*use_git=*/false)); CHECK(artifacts["file"]["type"] == "LOCAL"); CHECK(artifacts["file"]["data"]["path"] == "file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true)); CHECK(artifacts["file"]["type"] == "KNOWN"); CHECK( artifacts["file"]["data"]["id"] == @@ -125,14 +137,19 @@ TEST_CASE("not present at all") { SECTION("via file") { CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/false, fail_func)); + name, consumer, hash_type, nullptr, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -149,14 +166,19 @@ TEST_CASE("malformed entry") { SECTION("via git tree") { CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/false, fail_func)); + name, consumer, hash_type, nullptr, /*use_git=*/false, fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } SECTION("via git tree") { - CHECK_FALSE(ReadSourceTarget( - name, consumer, hash_type, /*use_git=*/true, fail_func)); + auto const storage_config = TestStorageConfig::Create(); + CHECK_FALSE(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true, + fail_func)); CHECK_FALSE(consumed); CHECK(failure_called); } @@ -172,13 +194,19 @@ TEST_CASE("subdir file") { }; SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); + CHECK(ReadSourceTarget( + name, consumer, hash_type, nullptr, /*use_git=*/false)); CHECK(artifacts["bar/file"]["type"] == "LOCAL"); CHECK(artifacts["bar/file"]["data"]["path"] == "foo/bar/file"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true)); CHECK(artifacts["bar/file"]["type"] == "KNOWN"); CHECK( artifacts["bar/file"]["data"]["id"] == @@ -197,13 +225,19 @@ TEST_CASE("subdir symlink") { }; SECTION("via file") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/false)); + CHECK(ReadSourceTarget( + name, consumer, hash_type, nullptr, /*use_git=*/false)); CHECK(artifacts["link"]["type"] == "LOCAL"); CHECK(artifacts["link"]["data"]["path"] == "foo/link"); } SECTION("via git tree") { - CHECK(ReadSourceTarget(name, consumer, hash_type, /*use_git=*/true)); + auto const storage_config = TestStorageConfig::Create(); + CHECK(ReadSourceTarget(name, + consumer, + hash_type, + &storage_config.Get(), + /*use_git=*/true)); CHECK(artifacts["link"]["type"] == "KNOWN"); CHECK(artifacts["link"]["data"]["id"] == (ProtocolTraits::IsNative(hash_type) ? kSrcLinkIdSha1 diff --git a/test/buildtool/common/TARGETS b/test/buildtool/common/TARGETS index 6e69c7e5..4ad87f17 100644 --- a/test/buildtool/common/TARGETS +++ b/test/buildtool/common/TARGETS @@ -41,6 +41,7 @@ , ["@", "src", "src/buildtool/execution_api/local", "local_api"] , ["@", "src", "src/buildtool/file_system", "file_root"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] + , ["@", "src", "src/buildtool/storage", "config"] , ["@", "src", "src/buildtool/storage", "storage"] , ["", "catch-main"] , ["utils", "test_storage_config"] diff --git a/test/buildtool/common/repository_config.test.cpp b/test/buildtool/common/repository_config.test.cpp index 8c1fd893..cc28a5e3 100644 --- a/test/buildtool/common/repository_config.test.cpp +++ b/test/buildtool/common/repository_config.test.cpp @@ -30,6 +30,7 @@ #include "src/buildtool/common/artifact_digest.hpp" #include "src/buildtool/file_system/file_root.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" #include "test/utils/hermeticity/test_storage_config.hpp" @@ -43,7 +44,7 @@ namespace { return FileSystemManager::GetCurrentDirectory() / "test/buildtool/common"; } -[[nodiscard]] auto GetGitRoot() -> FileRoot { +[[nodiscard]] auto GetGitRoot(StorageConfig const* storage_config) -> FileRoot { static std::atomic<int> counter{}; auto repo_path = GetTestDir() / "test_repo" / @@ -55,7 +56,8 @@ namespace { "commit --allow-empty -m'init'") == 0) { auto constexpr kEmptyTreeId = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; - if (auto root = FileRoot::FromGit(repo_path, kEmptyTreeId)) { + if (auto root = + FileRoot::FromGit(storage_config, repo_path, kEmptyTreeId)) { return std::move(*root); } } @@ -63,11 +65,12 @@ namespace { } [[nodiscard]] auto CreateFixedRepoInfo( + StorageConfig const* storage_config, std::map<std::string, std::string> const& bindings = {}, std::string const& tfn = "TARGETS", std::string const& rfn = "RULES", std::string const& efn = "EXPRESSIONS") { - static auto const kGitRoot = GetGitRoot(); + static auto const kGitRoot = GetGitRoot(storage_config); return RepositoryConfig::RepositoryInfo{ kGitRoot, kGitRoot, kGitRoot, kGitRoot, bindings, tfn, rfn, efn}; } @@ -134,7 +137,7 @@ TEST_CASE("Compute key of fixed repository", "[repository_config]") { RepositoryConfig config{}; SECTION("for single fixed repository") { - config.SetInfo("foo", CreateFixedRepoInfo()); + config.SetInfo("foo", CreateFixedRepoInfo(&storage_config.Get())); auto key = config.RepositoryKey(storage, "foo"); REQUIRE(key); @@ -144,15 +147,23 @@ TEST_CASE("Compute key of fixed repository", "[repository_config]") { } SECTION("for fixed repositories with same missing dependency") { - config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz"}})); + config.SetInfo( + "foo", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz"}})); + config.SetInfo( + "bar", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz"}})); CHECK_FALSE(config.RepositoryKey(storage, "foo")); CHECK_FALSE(config.RepositoryKey(storage, "bar")); } SECTION("for fixed repositories with different missing dependency") { - config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz0"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz1"}})); + config.SetInfo( + "foo", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz0"}})); + config.SetInfo( + "bar", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz1"}})); CHECK_FALSE(config.RepositoryKey(storage, "foo")); CHECK_FALSE(config.RepositoryKey(storage, "bar")); } @@ -170,8 +181,12 @@ TEST_CASE("Compute key of file repository", "[repository_config]") { } SECTION("for graph with leaf dependency as file") { - config.SetInfo("foo", CreateFixedRepoInfo({{"bar", "bar"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"baz", "baz"}})); + config.SetInfo( + "foo", + CreateFixedRepoInfo(&storage_config.Get(), {{"bar", "bar"}})); + config.SetInfo( + "bar", + CreateFixedRepoInfo(&storage_config.Get(), {{"baz", "baz"}})); config.SetInfo("baz", CreateFileRepoInfo()); CHECK_FALSE(config.RepositoryKey(storage, "foo")); } @@ -184,12 +199,14 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { RepositoryConfig config{}; // create two different repo infos with same content (baz should be same) - config.SetInfo("foo", CreateFixedRepoInfo({{"dep", "baz0"}})); - config.SetInfo("bar", CreateFixedRepoInfo({{"dep", "baz1"}})); + config.SetInfo( + "foo", CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz0"}})); + config.SetInfo( + "bar", CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz1"}})); SECTION("with leaf dependency") { // create duplicate leaf repo info with global name 'baz0' and 'baz1' - auto baz = CreateFixedRepoInfo(); + auto baz = CreateFixedRepoInfo(&storage_config.Get()); config.SetInfo("baz0", Copy(baz)); config.SetInfo("baz1", Copy(baz)); @@ -208,7 +225,8 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { SECTION("with cyclic dependency") { // create duplicate cyclic repo info with global name 'baz0' and 'baz1' - auto baz = CreateFixedRepoInfo({{"foo", "foo"}, {"bar", "bar"}}); + auto baz = CreateFixedRepoInfo(&storage_config.Get(), + {{"foo", "foo"}, {"bar", "bar"}}); config.SetInfo("baz0", Copy(baz)); config.SetInfo("baz1", Copy(baz)); @@ -227,8 +245,12 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { SECTION("with two separate cyclic graphs") { // create two cyclic repo infos producing two separate graphs - config.SetInfo("baz0", CreateFixedRepoInfo({{"dep", "foo"}})); - config.SetInfo("baz1", CreateFixedRepoInfo({{"dep", "bar"}})); + config.SetInfo( + "baz0", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "foo"}})); + config.SetInfo( + "baz1", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "bar"}})); // check if computed key is same auto foo_key = config.RepositoryKey(storage, "foo"); @@ -243,8 +265,12 @@ TEST_CASE("Compare key of two repos with same content", "[repository_config]") { } SECTION("for graph with leaf repos refering to themselfs") { - config.SetInfo("baz0", CreateFixedRepoInfo({{"dep", "baz0"}})); - config.SetInfo("baz1", CreateFixedRepoInfo({{"dep", "baz1"}})); + config.SetInfo( + "baz0", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz0"}})); + config.SetInfo( + "baz1", + CreateFixedRepoInfo(&storage_config.Get(), {{"dep", "baz1"}})); // check if computed key is same auto foo_key = config.RepositoryKey(storage, "foo"); diff --git a/test/buildtool/file_system/TARGETS b/test/buildtool/file_system/TARGETS index 5062ee29..7d760fc1 100644 --- a/test/buildtool/file_system/TARGETS +++ b/test/buildtool/file_system/TARGETS @@ -77,6 +77,7 @@ , ["", "catch-main"] , ["utils", "shell_quoting"] , ["utils", "test_hash_function_type"] + , ["utils", "test_storage_config"] ] , "stage": ["test", "buildtool", "file_system"] } diff --git a/test/buildtool/file_system/file_root.test.cpp b/test/buildtool/file_system/file_root.test.cpp index db0fdf11..46b52e79 100644 --- a/test/buildtool/file_system/file_root.test.cpp +++ b/test/buildtool/file_system/file_root.test.cpp @@ -32,6 +32,7 @@ #include "src/buildtool/file_system/object_type.hpp" #include "src/utils/cpp/expected.hpp" #include "test/utils/hermeticity/test_hash_function_type.hpp" +#include "test/utils/hermeticity/test_storage_config.hpp" #include "test/utils/shell_quoting.hpp" namespace { @@ -195,11 +196,14 @@ TEST_CASE("Creating file root", "[file_root]") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); CHECK(root->Exists(".")); - CHECK_FALSE(FileRoot::FromGit("does_not_exist", kTreeSymId)); + CHECK_FALSE(FileRoot::FromGit( + &storage_config.Get(), "does_not_exist", kTreeSymId)); } SECTION("local root ignore-special") { @@ -216,13 +220,18 @@ TEST_CASE("Creating file root", "[file_root]") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); CHECK(root->Exists(".")); - CHECK_FALSE(FileRoot::FromGit( - "does_not_exist", kTreeSymId, /*ignore_special=*/true)); + CHECK_FALSE(FileRoot::FromGit(&storage_config.Get(), + "does_not_exist", + kTreeSymId, + /*ignore_special=*/true)); } } @@ -237,7 +246,9 @@ TEST_CASE("Reading files", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); TestFileRootReadFilesAndSymlinks(*root); @@ -254,8 +265,11 @@ TEST_CASE("Reading files", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); TestFileRootReadFilesOnly(*root); @@ -273,7 +287,9 @@ TEST_CASE("Reading directories", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); TestFileRootReadDirectory(*root, /*with_symlinks=*/true); @@ -290,8 +306,11 @@ TEST_CASE("Reading directories", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); TestFileRootReadDirectory(*root, /*with_symlinks=*/false); @@ -309,7 +328,9 @@ TEST_CASE("Reading blobs", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); auto foo = root->ReadBlob(kFooIdGitSha1); @@ -330,8 +351,11 @@ TEST_CASE("Reading blobs", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); auto foo = root->ReadBlob(kFooIdGitSha1); @@ -353,7 +377,9 @@ TEST_CASE("Reading blob type", "[file_root]") { SECTION("git root") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = FileRoot::FromGit(*repo_path, kTreeSymId); + auto const storage_config = TestStorageConfig::Create(); + auto root = + FileRoot::FromGit(&storage_config.Get(), *repo_path, kTreeSymId); REQUIRE(root); TestFileRootReadBlobType(*root); @@ -369,8 +395,11 @@ TEST_CASE("Reading blob type", "[file_root]") { SECTION("git root ignore-special") { auto repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto root = - FileRoot::FromGit(*repo_path, kTreeSymId, /*ignore_special=*/true); + auto const storage_config = TestStorageConfig::Create(); + auto root = FileRoot::FromGit(&storage_config.Get(), + *repo_path, + kTreeSymId, + /*ignore_special=*/true); REQUIRE(root); TestFileRootReadBlobType(*root); @@ -417,7 +446,9 @@ static void CheckGitRoot(HashFunction::Type hash_type, bool ignore_special) noexcept { auto const repo_path = CreateTestRepoSymlinks(false); REQUIRE(repo_path); - auto const root = FileRoot::FromGit(*repo_path, kTreeSymId, ignore_special); + auto const storage_config = TestStorageConfig::Create(); + auto const root = FileRoot::FromGit( + &storage_config.Get(), *repo_path, kTreeSymId, ignore_special); REQUIRE(root); auto const foo = root->ToArtifactDescription(hash_type, "baz/foo", "repo"); |