Skip to content

Commit d6c7168

Browse files
committed
test(import[gitlab]) Add CLI integration test for skip_groups via real importer
why: MockImporter.fetch_repos yields repos without calling filter_repo, so CLI tests cannot catch regressions at the importer→filter_repo boundary. what: - Add test_gitlab_cli_skip_groups_excludes_from_config in test_gitlab.py - Uses mock_urlopen + real GitLabImporter + _run_import → config write path - Asserts bots-repo is absent from config when skip_groups=["bots"]
1 parent 948ac56 commit d6c7168

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

tests/_internal/remotes/test_gitlab.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
from __future__ import annotations
44

55
import json
6+
import pathlib
67
import typing as t
78
import urllib.parse
89
import urllib.request
910

1011
import pytest
12+
import yaml
1113

1214
from tests._internal.remotes.conftest import MockHTTPResponse
1315
from vcspull._internal.remotes.base import ImportMode, ImportOptions
1416
from vcspull._internal.remotes.gitlab import GitLabImporter
17+
from vcspull.cli.import_cmd._common import _run_import
1518

1619

1720
def test_gitlab_fetch_user(
@@ -1181,3 +1184,85 @@ def urlopen_capture(
11811184
assert repo_names == {"top-repo", "external-repo"}, (
11821185
f"Unexpected repos returned: {repo_names}"
11831186
)
1187+
1188+
1189+
def test_gitlab_cli_skip_groups_excludes_from_config(
1190+
mock_urlopen: t.Callable[..., None],
1191+
tmp_path: pathlib.Path,
1192+
monkeypatch: pytest.MonkeyPatch,
1193+
) -> None:
1194+
"""Integration: _run_import + GitLabImporter + filter_repo writes correct config.
1195+
1196+
MockImporter.fetch_repos bypasses filter_repo, so CLI tests using it cannot
1197+
catch regressions in the importer→filter boundary. This test uses a real
1198+
GitLabImporter with mocked HTTP and verifies bots-repo is absent from the
1199+
written config.
1200+
"""
1201+
monkeypatch.setenv("HOME", str(tmp_path))
1202+
1203+
response_json: list[dict[str, t.Any]] = [
1204+
{
1205+
"path": "top-repo",
1206+
"name": "top-repo",
1207+
"http_url_to_repo": "https://gitlab.com/testgroup/top-repo.git",
1208+
"ssh_url_to_repo": "git@gitlab.com:testgroup/top-repo.git",
1209+
"web_url": "https://gitlab.com/testgroup/top-repo",
1210+
"description": None,
1211+
"topics": [],
1212+
"star_count": 0,
1213+
"archived": False,
1214+
"default_branch": "main",
1215+
"namespace": {"path": "testgroup", "full_path": "testgroup"},
1216+
},
1217+
{
1218+
"path": "bots-repo",
1219+
"name": "bots-repo",
1220+
"http_url_to_repo": "https://gitlab.com/testgroup/bots/bots-repo.git",
1221+
"ssh_url_to_repo": "git@gitlab.com:testgroup/bots/bots-repo.git",
1222+
"web_url": "https://gitlab.com/testgroup/bots/bots-repo",
1223+
"description": None,
1224+
"topics": [],
1225+
"star_count": 0,
1226+
"archived": False,
1227+
"default_branch": "main",
1228+
"namespace": {"path": "bots", "full_path": "testgroup/bots"},
1229+
},
1230+
]
1231+
mock_urlopen([(json.dumps(response_json).encode(), {}, 200)])
1232+
1233+
workspace = tmp_path / "repos"
1234+
workspace.mkdir()
1235+
config_file = tmp_path / ".vcspull.yaml"
1236+
1237+
result = _run_import(
1238+
GitLabImporter(),
1239+
service_name="gitlab",
1240+
target="testgroup",
1241+
workspace=str(workspace),
1242+
mode="org",
1243+
language=None,
1244+
topics=None,
1245+
min_stars=0,
1246+
include_archived=False,
1247+
include_forks=False,
1248+
limit=100,
1249+
config_path_str=str(config_file),
1250+
dry_run=False,
1251+
yes=True,
1252+
output_json=False,
1253+
output_ndjson=False,
1254+
color="never",
1255+
skip_groups=["bots"],
1256+
)
1257+
1258+
assert result == 0
1259+
assert config_file.exists()
1260+
config = yaml.safe_load(config_file.read_text())
1261+
1262+
all_repo_names: set[str] = set()
1263+
for section in config.values():
1264+
if isinstance(section, dict):
1265+
all_repo_names.update(section.keys())
1266+
1267+
assert "top-repo" in all_repo_names
1268+
assert "bots-repo" not in all_repo_names

0 commit comments

Comments
 (0)