Fix Git source sync failures
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
|
||||
from backend.app import git_source, main
|
||||
|
||||
|
||||
def test_clone_or_update_repo_clones_into_repo_path(monkeypatch, tmp_path):
|
||||
commands = []
|
||||
|
||||
def fake_run(command, capture_output=True, text=True):
|
||||
commands.append(command)
|
||||
|
||||
class Result:
|
||||
returncode = 0
|
||||
stdout = ""
|
||||
stderr = ""
|
||||
|
||||
return Result()
|
||||
|
||||
monkeypatch.setattr(git_source, "run", fake_run)
|
||||
|
||||
result = git_source.clone_or_update_repo(
|
||||
repo_id="neoforge-git",
|
||||
repo_url="https://github.com/neoforged/Documentation.git",
|
||||
branch="main",
|
||||
repos_base=tmp_path,
|
||||
)
|
||||
|
||||
assert result["success"] is True
|
||||
assert commands == [
|
||||
[
|
||||
"git",
|
||||
"clone",
|
||||
"--branch",
|
||||
"main",
|
||||
"--single-branch",
|
||||
"https://github.com/neoforged/Documentation.git",
|
||||
str(tmp_path / "neoforge-git"),
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sync_sources_returns_failed_result_for_source_exception(monkeypatch):
|
||||
async def fake_list_sources():
|
||||
return {
|
||||
"sources": [
|
||||
{
|
||||
"library_id": "neoforge",
|
||||
"repo_url": "https://github.com/neoforged/Documentation.git",
|
||||
"branch": "main",
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async def fake_ingest_git_source(**kwargs):
|
||||
raise RuntimeError("git is unavailable")
|
||||
|
||||
monkeypatch.setattr(main, "api_list_sources", fake_list_sources)
|
||||
monkeypatch.setattr(main, "ingest_git_source", fake_ingest_git_source)
|
||||
|
||||
result = await main.sync_sources_api()
|
||||
|
||||
assert result["success"] is False
|
||||
assert result["failed"] == 1
|
||||
assert result["results"][0]["library_id"] == "neoforge"
|
||||
assert result["results"][0]["error"] == "git is unavailable"
|
||||
Reference in New Issue
Block a user