Skip to content

Commit 3b203f1

Browse files
committed
tests/add_from_fs(feat[enhanced-output]): Add comprehensive tests for existing repo reporting
why: Ensure the enhanced output functionality works correctly across different scenarios. what: - Update existing test to verify new detailed output format - Add test for multiple existing repositories with detailed listing - Add test for mixed scenario with both existing and new repositories - Verify count, individual repo details, and final status messages - Test output includes repo name, URL, config path, and file location
1 parent 392e80c commit 3b203f1

File tree

1 file changed

+138
-6
lines changed

1 file changed

+138
-6
lines changed

tests/cli/test_add_from_fs.py

Lines changed: 138 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,10 @@ def test_skip_existing_repos(
333333
yes=True,
334334
)
335335

336-
# Verify repo was skipped
337-
assert (
338-
f"Repository {scan_dir!s}/{repo_name} ({remote_url}) already exists. "
339-
f"Skipping." in caplog.text
340-
)
341-
assert "Nothing to do" in caplog.text
336+
# Verify enhanced output for existing repos
337+
assert "Found 1 existing repositories in configuration:" in caplog.text
338+
assert f" - {repo_name} ({remote_url}) at {str(scan_dir)}/{repo_name} in {config_file}" in caplog.text
339+
assert "All found repositories already exist in the configuration. Nothing to do." in caplog.text
342340

343341
def test_user_confirmation(
344342
self,
@@ -451,3 +449,137 @@ def test_repo_without_origin(
451449
in caplog.text
452450
)
453451
assert not config_file.exists() # No repos added, so no file created
452+
453+
def test_detailed_existing_repos_output(
454+
self,
455+
create_git_remote_repo: CreateRepoPytestFixtureFn,
456+
tmp_path: pathlib.Path,
457+
git_commit_envvars: dict[str, str],
458+
caplog: LogCaptureFixture,
459+
) -> None:
460+
"""Test detailed output when multiple repositories already exist."""
461+
caplog.set_level("INFO")
462+
463+
# Create scan directory with multiple repos
464+
scan_dir = tmp_path / "existing_repos"
465+
scan_dir.mkdir()
466+
467+
# Create multiple repositories
468+
repos_data = []
469+
for i, repo_name in enumerate(["repo1", "repo2", "repo3"]):
470+
remote_path = create_git_remote_repo()
471+
remote_url = f"file://{remote_path}"
472+
local_repo_path = scan_dir / repo_name
473+
474+
subprocess.run(
475+
["git", "clone", remote_url, str(local_repo_path)],
476+
check=True,
477+
capture_output=True,
478+
env=git_commit_envvars,
479+
)
480+
repos_data.append((repo_name, remote_url))
481+
482+
# Pre-create config with all repos
483+
config_file = tmp_path / ".vcspull.yaml"
484+
config_data = {
485+
str(scan_dir) + "/": {
486+
repo_name: remote_url for repo_name, remote_url in repos_data
487+
}
488+
}
489+
save_config_yaml(config_file, config_data)
490+
491+
# Run add_from_filesystem
492+
add_from_filesystem(
493+
scan_dir_str=str(scan_dir),
494+
config_file_path_str=str(config_file),
495+
recursive=True,
496+
base_dir_key_arg=None,
497+
yes=True,
498+
)
499+
500+
# Verify detailed output
501+
assert "Found 3 existing repositories in configuration:" in caplog.text
502+
503+
# Check each repository is listed with correct details
504+
for repo_name, remote_url in repos_data:
505+
expected_line = f" - {repo_name} ({remote_url}) at {str(scan_dir)}/{repo_name} in {config_file}"
506+
assert expected_line in caplog.text
507+
508+
# Verify final message
509+
assert "All found repositories already exist in the configuration. Nothing to do." in caplog.text
510+
511+
def test_mixed_existing_and_new_repos(
512+
self,
513+
create_git_remote_repo: CreateRepoPytestFixtureFn,
514+
tmp_path: pathlib.Path,
515+
git_commit_envvars: dict[str, str],
516+
caplog: LogCaptureFixture,
517+
) -> None:
518+
"""Test output when some repos exist and some are new."""
519+
caplog.set_level("INFO")
520+
521+
# Create scan directory
522+
scan_dir = tmp_path / "mixed_repos"
523+
scan_dir.mkdir()
524+
525+
# Create repositories
526+
existing_repo_data = []
527+
new_repo_data = []
528+
529+
# Create two existing repos
530+
for i, repo_name in enumerate(["existing1", "existing2"]):
531+
remote_path = create_git_remote_repo()
532+
remote_url = f"file://{remote_path}"
533+
local_repo_path = scan_dir / repo_name
534+
535+
subprocess.run(
536+
["git", "clone", remote_url, str(local_repo_path)],
537+
check=True,
538+
capture_output=True,
539+
env=git_commit_envvars,
540+
)
541+
existing_repo_data.append((repo_name, remote_url))
542+
543+
# Create two new repos
544+
for i, repo_name in enumerate(["new1", "new2"]):
545+
remote_path = create_git_remote_repo()
546+
remote_url = f"file://{remote_path}"
547+
local_repo_path = scan_dir / repo_name
548+
549+
subprocess.run(
550+
["git", "clone", remote_url, str(local_repo_path)],
551+
check=True,
552+
capture_output=True,
553+
env=git_commit_envvars,
554+
)
555+
new_repo_data.append((repo_name, remote_url))
556+
557+
# Pre-create config with only existing repos
558+
config_file = tmp_path / ".vcspull.yaml"
559+
config_data = {
560+
str(scan_dir) + "/": {
561+
repo_name: remote_url for repo_name, remote_url in existing_repo_data
562+
}
563+
}
564+
save_config_yaml(config_file, config_data)
565+
566+
# Run add_from_filesystem
567+
add_from_filesystem(
568+
scan_dir_str=str(scan_dir),
569+
config_file_path_str=str(config_file),
570+
recursive=True,
571+
base_dir_key_arg=None,
572+
yes=True,
573+
)
574+
575+
# Verify existing repos are listed
576+
assert "Found 2 existing repositories in configuration:" in caplog.text
577+
for repo_name, remote_url in existing_repo_data:
578+
expected_line = f" - {repo_name} ({remote_url}) at {str(scan_dir)}/{repo_name} in {config_file}"
579+
assert expected_line in caplog.text
580+
581+
# Verify new repos are added
582+
for repo_name, remote_url in new_repo_data:
583+
assert f"Adding '{repo_name}' ({remote_url})" in caplog.text
584+
585+
assert "Successfully updated" in caplog.text

0 commit comments

Comments
 (0)