|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import hashlib |
| 6 | +from datetime import datetime, timezone |
6 | 7 | import os |
| 8 | +import re |
7 | 9 | import sqlite3 |
8 | 10 | import stat |
9 | 11 | import sys |
@@ -80,7 +82,11 @@ def test_a_postgresql_root_stages_its_files_only(tmp_path): |
80 | 82 |
|
81 | 83 |
|
82 | 84 | def test_a_managed_root_is_refused_until_its_cluster_can_be_copied(tmp_path): |
83 | | - with pytest.raises(ManifestError, match="managed PostgreSQL"): |
| 85 | + expected = ( |
| 86 | + "a managed PostgreSQL backup needs a stopped copy or a logical dump, " |
| 87 | + "not implemented yet (issue #731)" |
| 88 | + ) |
| 89 | + with pytest.raises(ManifestError, match=f"^{re.escape(expected)}$"): |
84 | 90 | snapshot_backup(tmp_path / "root", tmp_path / "staging", "managed") |
85 | 91 | assert not (tmp_path / "staging").exists() |
86 | 92 |
|
@@ -196,3 +202,33 @@ def scan_then_delete(base, relative, kind): |
196 | 202 | monkeypatch.setattr(backup_snapshot_module, "scan_resource", scan_then_delete) |
197 | 203 | with pytest.raises(FileNotFoundError): |
198 | 204 | snapshot_backup(root, staging, "sqlite") |
| 205 | + |
| 206 | + |
| 207 | +def test_the_manifest_carries_the_given_instant(tmp_path): |
| 208 | + root, staging = tmp_path / "root", tmp_path / "staging" |
| 209 | + _live_store(root).close() |
| 210 | + now = datetime(2026, 11, 10, 11, 0, 0, tzinfo=timezone.utc) |
| 211 | + manifest = snapshot_backup(root, staging, "sqlite", now=now) |
| 212 | + assert manifest["created_at"] == "2026-11-10T11:00:00+00:00" |
| 213 | + |
| 214 | + |
| 215 | +def test_a_store_path_that_is_a_directory_is_refused(tmp_path): |
| 216 | + root = tmp_path / "root" |
| 217 | + (root / "methodology" / "memory.db").mkdir(parents=True) |
| 218 | + with pytest.raises(BackupScanError, match="expected to be a file"): |
| 219 | + snapshot_backup(root, tmp_path / "staging", "sqlite") |
| 220 | + |
| 221 | + |
| 222 | +def test_a_staging_path_that_is_a_file_is_refused(tmp_path): |
| 223 | + root, staging = tmp_path / "root", tmp_path / "staging" |
| 224 | + _live_store(root).close() |
| 225 | + staging.write_bytes(b"x") |
| 226 | + with pytest.raises(StagingError, match=r"staging is not a directory$"): |
| 227 | + snapshot_backup(root, staging, "sqlite") |
| 228 | + |
| 229 | + |
| 230 | +def test_a_staging_root_with_missing_parents_is_created(tmp_path): |
| 231 | + root, staging = tmp_path / "root", tmp_path / "a" / "b" / "staging" |
| 232 | + _live_store(root).close() |
| 233 | + snapshot_backup(root, staging, "sqlite") |
| 234 | + assert (staging / "methodology" / "memory.db").is_file() |
0 commit comments