Skip to content

Commit

Permalink
Merge pull request #53 from Kwaizer/ch-clone-exept
Browse files Browse the repository at this point in the history
Raise an exception if the cacher can't clone a git repository
  • Loading branch information
Korulag authored May 2, 2024
2 parents 20eafaa + 7cb38db commit 3f0185f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion alma_tests_cacher/cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ async def process_repo(
repo_dir = Path(workdir, repo_dirname)
if not repo_dir.exists():
self.logger.info('Start cloning git repo: %s', repo.url)
exit_code, stdout, stderr = clone_git_repo(workdir, repo.url)
try:
exit_code, stdout, stderr = clone_git_repo(workdir, repo.url)
except Exception:
self.logger.exception('Cannot clone git repo:')
return
self.logger.debug(
'Clone result:\nexit_code: %s\nstdout: %s\nstderr: %s',
exit_code,
Expand Down
1 change: 0 additions & 1 deletion alma_tests_cacher/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def clone_git_repo(
.with_cwd(workdir_path)
.run(
['clone', repo_url],
retcode=None,
)
)

Expand Down
19 changes: 19 additions & 0 deletions tests/test_cacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,30 @@ async def func(*args, **kwargs):
monkeypatch.setattr(AlmaTestsCacher, 'bulk_create_test_folders', func)


@pytest.fixture
def mock_clone_git_repo(
monkeypatch: pytest.MonkeyPatch,
repo_payload: TestRepository,
):
def func(workdir: str, repo_url: str):
tests_dir = Path(
workdir,
repo_url.split('/')[-1].replace('.git', ''),
repo_payload.tests_dir,
)
for i in range(1, 5):
Path(tests_dir, f'{repo_payload.tests_prefix}{i}').mkdir(parents=True, exist_ok=True)
return 0, '', ''

monkeypatch.setattr('alma_tests_cacher.cacher.clone_git_repo', func)


@pytest.mark.anyio
@pytest.mark.usefixtures(
'mock_get_test_repos',
'mock_bulk_create',
'mock_bulk_remove',
'mock_clone_git_repo'
)
async def test_cacher_run(
cacher: AlmaTestsCacher,
Expand Down

0 comments on commit 3f0185f

Please sign in to comment.