|
79 | 79 | TEST_CI_REPO_URL = f"https://user:[email protected]/ci-org/{TEST_CI_REPO}" |
80 | 80 | TEST_CI_BRANCH = "test_ci_branch" |
81 | 81 | TEST_BASE_DIRECTORY = "/repos" |
| 82 | +TEST_MIRROR_DIRECTORY = "/mirror" |
82 | 83 | TEST_BRANCH = "test-branch" |
83 | 84 | TEST_CONFIG: Dict[str, Any] = { |
84 | 85 | "version": 2, |
@@ -135,6 +136,8 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: |
135 | 136 | "ci_branch": TEST_CI_BRANCH, |
136 | 137 | "log_extractor": DefaultGithubLogExtractor(), |
137 | 138 | "base_directory": TEST_BASE_DIRECTORY, |
| 139 | + "mirror_dir": None, |
| 140 | + "mirror_fallback_repo": None, |
138 | 141 | } |
139 | 142 | presets.update(kwargs) |
140 | 143 |
|
@@ -482,6 +485,69 @@ def test_fetch_repo_path_exists_git_exception(self) -> None: |
482 | 485 | self._bw.fetch_repo(*fetch_params) |
483 | 486 | fr.assert_called_once_with(*fetch_params) |
484 | 487 |
|
| 488 | + def test_full_sync_with_mirror_dir(self) -> None: |
| 489 | + bw = BranchWorkerMock(mirror_dir=TEST_MIRROR_DIRECTORY) |
| 490 | + mirror_path = os.path.join( |
| 491 | + TEST_MIRROR_DIRECTORY, os.path.basename(TEST_UPSTREAM_REPO_URL) |
| 492 | + ) |
| 493 | + with ( |
| 494 | + patch("kernel_patches_daemon.branch_worker.os.path.exists") as exists, |
| 495 | + patch("kernel_patches_daemon.branch_worker.shutil.rmtree") as rm, |
| 496 | + ): |
| 497 | + exists.side_effect = lambda p: p == mirror_path |
| 498 | + bw.upstream_url = TEST_UPSTREAM_REPO_URL |
| 499 | + bw.full_sync("somepath", "giturl", "branch") |
| 500 | + self._git_repo_mock.clone_from.assert_called_once_with( |
| 501 | + "giturl", |
| 502 | + "somepath", |
| 503 | + multi_options=["--reference-if-able", mirror_path], |
| 504 | + ) |
| 505 | + |
| 506 | + def test_full_sync_with_mirror_fallback_repo(self) -> None: |
| 507 | + fallback_repo = "linux.git" |
| 508 | + bw = BranchWorkerMock( |
| 509 | + mirror_dir=TEST_MIRROR_DIRECTORY, mirror_fallback_repo=fallback_repo |
| 510 | + ) |
| 511 | + primary_mirror_path = os.path.join( |
| 512 | + TEST_MIRROR_DIRECTORY, os.path.basename(TEST_UPSTREAM_REPO_URL) |
| 513 | + ) |
| 514 | + fallback_mirror_path = os.path.join(TEST_MIRROR_DIRECTORY, fallback_repo) |
| 515 | + with ( |
| 516 | + patch("kernel_patches_daemon.branch_worker.os.path.exists") as exists, |
| 517 | + patch("kernel_patches_daemon.branch_worker.shutil.rmtree") as rm, |
| 518 | + ): |
| 519 | + # Primary mirror doesn't exist, but fallback does |
| 520 | + exists.side_effect = lambda p: p == fallback_mirror_path |
| 521 | + bw.upstream_url = TEST_UPSTREAM_REPO_URL |
| 522 | + bw.full_sync("somepath", "giturl", "branch") |
| 523 | + # Should use fallback mirror path for reference |
| 524 | + self._git_repo_mock.clone_from.assert_called_once_with( |
| 525 | + "giturl", |
| 526 | + "somepath", |
| 527 | + multi_options=["--reference-if-able", fallback_mirror_path], |
| 528 | + ) |
| 529 | + |
| 530 | + def test_full_sync_without_mirror_fallback_repo(self) -> None: |
| 531 | + bw = BranchWorkerMock( |
| 532 | + mirror_dir=TEST_MIRROR_DIRECTORY, mirror_fallback_repo=None |
| 533 | + ) |
| 534 | + mirror_path = os.path.join( |
| 535 | + TEST_MIRROR_DIRECTORY, os.path.basename(TEST_UPSTREAM_REPO_URL) |
| 536 | + ) |
| 537 | + with ( |
| 538 | + patch("kernel_patches_daemon.branch_worker.os.path.exists") as exists, |
| 539 | + patch("kernel_patches_daemon.branch_worker.shutil.rmtree") as rm, |
| 540 | + ): |
| 541 | + # Mirror doesn't exist, and no fallback repo specified - should not use reference |
| 542 | + exists.side_effect = lambda p: False |
| 543 | + bw.upstream_url = TEST_UPSTREAM_REPO_URL |
| 544 | + bw.full_sync("somepath", "giturl", "branch") |
| 545 | + # Should clone without reference |
| 546 | + self._git_repo_mock.clone_from.assert_called_once_with( |
| 547 | + "giturl", |
| 548 | + "somepath", |
| 549 | + ) |
| 550 | + |
485 | 551 | def test_expire_branches(self) -> None: |
486 | 552 | """Only the branch that matches pattern and is expired should be deleted""" |
487 | 553 | not_expired_time = datetime.fromtimestamp(3 * BRANCH_TTL) |
|
0 commit comments