24 lines
659 B
Python
24 lines
659 B
Python
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from backup_tool.gc import purge_repository
|
|
|
|
|
|
def test_gc_keeps_manifest_when_unlink_fails(tmp_path: Path) -> None:
|
|
root = tmp_path / "repository"
|
|
manifest = root / "manifests" / "deleted.json"
|
|
manifest.parent.mkdir(parents=True)
|
|
manifest.write_text('{"entries": []}', encoding="utf-8")
|
|
|
|
with (
|
|
patch("pathlib.Path.unlink", side_effect=OSError("read-only")),
|
|
pytest.raises(OSError),
|
|
):
|
|
purge_repository(root, {"deleted"}, grace=timedelta(0))
|
|
|
|
assert manifest.exists()
|