|
68 | 68 | TEST_CI_REPO_URL = f"https://user:[email protected]/ci-org/{TEST_CI_REPO}" |
69 | 69 | TEST_CI_BRANCH = "test_ci_branch" |
70 | 70 | TEST_BASE_DIRECTORY = "/repos" |
| 71 | +TEST_MIRROR_DIRECTORY = "/mirror" |
71 | 72 | TEST_BRANCH = "test-branch" |
72 | 73 | TEST_CONFIG: Dict[str, Any] = { |
73 | 74 | "version": 2, |
@@ -124,6 +125,8 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: |
124 | 125 | "ci_branch": TEST_CI_BRANCH, |
125 | 126 | "log_extractor": DefaultGithubLogExtractor(), |
126 | 127 | "base_directory": TEST_BASE_DIRECTORY, |
| 128 | + "mirror_dir": None, |
| 129 | + "mirror_fallback_repo": None, |
127 | 130 | } |
128 | 131 | presets.update(kwargs) |
129 | 132 |
|
@@ -464,6 +467,69 @@ def test_fetch_repo_path_exists_git_exception(self) -> None: |
464 | 467 | self._bw.fetch_repo(*fetch_params) |
465 | 468 | fr.assert_called_once_with(*fetch_params) |
466 | 469 |
|
| 470 | + def test_full_sync_with_mirror_dir(self) -> None: |
| 471 | + bw = BranchWorkerMock(mirror_dir=TEST_MIRROR_DIRECTORY) |
| 472 | + mirror_path = os.path.join( |
| 473 | + TEST_MIRROR_DIRECTORY, os.path.basename(TEST_UPSTREAM_REPO_URL) |
| 474 | + ) |
| 475 | + with ( |
| 476 | + patch("kernel_patches_daemon.branch_worker.os.path.exists") as exists, |
| 477 | + patch("kernel_patches_daemon.branch_worker.shutil.rmtree") as rm, |
| 478 | + ): |
| 479 | + exists.side_effect = lambda p: p == mirror_path |
| 480 | + bw.upstream_url = TEST_UPSTREAM_REPO_URL |
| 481 | + bw.full_sync("somepath", "giturl", "branch") |
| 482 | + self._git_repo_mock.clone_from.assert_called_once_with( |
| 483 | + "giturl", |
| 484 | + "somepath", |
| 485 | + multi_options=["--reference-if-able", mirror_path], |
| 486 | + ) |
| 487 | + |
| 488 | + def test_full_sync_with_mirror_fallback_repo(self) -> None: |
| 489 | + fallback_repo = "linux.git" |
| 490 | + bw = BranchWorkerMock( |
| 491 | + mirror_dir=TEST_MIRROR_DIRECTORY, mirror_fallback_repo=fallback_repo |
| 492 | + ) |
| 493 | + primary_mirror_path = os.path.join( |
| 494 | + TEST_MIRROR_DIRECTORY, os.path.basename(TEST_UPSTREAM_REPO_URL) |
| 495 | + ) |
| 496 | + fallback_mirror_path = os.path.join(TEST_MIRROR_DIRECTORY, fallback_repo) |
| 497 | + with ( |
| 498 | + patch("kernel_patches_daemon.branch_worker.os.path.exists") as exists, |
| 499 | + patch("kernel_patches_daemon.branch_worker.shutil.rmtree") as rm, |
| 500 | + ): |
| 501 | + # Primary mirror doesn't exist, but fallback does |
| 502 | + exists.side_effect = lambda p: p == fallback_mirror_path |
| 503 | + bw.upstream_url = TEST_UPSTREAM_REPO_URL |
| 504 | + bw.full_sync("somepath", "giturl", "branch") |
| 505 | + # Should use fallback mirror path for reference |
| 506 | + self._git_repo_mock.clone_from.assert_called_once_with( |
| 507 | + "giturl", |
| 508 | + "somepath", |
| 509 | + multi_options=["--reference-if-able", fallback_mirror_path], |
| 510 | + ) |
| 511 | + |
| 512 | + def test_full_sync_without_mirror_fallback_repo(self) -> None: |
| 513 | + bw = BranchWorkerMock( |
| 514 | + mirror_dir=TEST_MIRROR_DIRECTORY, mirror_fallback_repo=None |
| 515 | + ) |
| 516 | + mirror_path = os.path.join( |
| 517 | + TEST_MIRROR_DIRECTORY, os.path.basename(TEST_UPSTREAM_REPO_URL) |
| 518 | + ) |
| 519 | + with ( |
| 520 | + patch("kernel_patches_daemon.branch_worker.os.path.exists") as exists, |
| 521 | + patch("kernel_patches_daemon.branch_worker.shutil.rmtree") as rm, |
| 522 | + ): |
| 523 | + # Mirror doesn't exist, and no fallback repo specified - should not use reference |
| 524 | + exists.side_effect = lambda p: False |
| 525 | + bw.upstream_url = TEST_UPSTREAM_REPO_URL |
| 526 | + bw.full_sync("somepath", "giturl", "branch") |
| 527 | + # Should clone without reference |
| 528 | + self._git_repo_mock.clone_from.assert_called_once_with( |
| 529 | + "giturl", |
| 530 | + "somepath", |
| 531 | + ) |
| 532 | + |
467 | 533 | def test_expire_branches(self) -> None: |
468 | 534 | """Only the branch that matches pattern and is expired should be deleted""" |
469 | 535 | not_expired_time = datetime.fromtimestamp(3 * BRANCH_TTL) |
|
0 commit comments