mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2026-08-20 21:22:54 +00:00
A finished generation cannot show whether a volume held a database, nor whether a dump was produced for it: under --only-sql a failed dump falls back to a file copy, and the resulting files/ tree looks like any other copy. The run knows both and threw the knowledge away as a printed warning, leaving every reader to guess from file names. Each generation now carries a manifest.json stating its layout and, per volume, database / dumped / engine. baudolo.generation is the single place those names are spelled; restore/paths.py, backup/db.py and backup/volume.py stop repeating them. It is deliberately import-free so a consumer can read the manifest with nothing but json, on hosts where this package is not installed. BREAKING CHANGE: BackupException is renamed BackupError. The rename is atomic across the ten modules that define or import it, three of which also carry the manifest change, so it lands in this commit rather than a separate one that could not import. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from baudolo.backup import docker as docker_mod
|
|
from baudolo.backup.shell import BackupError
|
|
|
|
|
|
class TestIsSwarmTask(unittest.TestCase):
|
|
@patch.object(docker_mod, "execute_shell_command", return_value=["task-id-123"])
|
|
def test_true_when_task_label_present(self, _mock) -> None:
|
|
self.assertTrue(docker_mod.is_swarm_task("c1"))
|
|
|
|
@patch.object(docker_mod, "execute_shell_command", return_value=[""])
|
|
def test_false_when_label_empty(self, _mock) -> None:
|
|
self.assertFalse(docker_mod.is_swarm_task("c1"))
|
|
|
|
@patch.object(docker_mod, "execute_shell_command", return_value=[])
|
|
def test_false_when_no_output(self, _mock) -> None:
|
|
self.assertFalse(docker_mod.is_swarm_task("c1"))
|
|
|
|
@patch.object(
|
|
docker_mod,
|
|
"execute_shell_command",
|
|
side_effect=[BackupError("gone"), []],
|
|
)
|
|
def test_vanished_container_counts_as_not_stoppable(self, _mock) -> None:
|
|
# A container removed between listing and inspect must not abort the
|
|
# whole backup run; treating it as a swarm task keeps it out of every
|
|
# stop/start and image-inspect path.
|
|
self.assertTrue(docker_mod.is_swarm_task("gone-container"))
|
|
|
|
@patch.object(
|
|
docker_mod,
|
|
"execute_shell_command",
|
|
side_effect=[BackupError("daemon hiccup"), ["still-here"]],
|
|
)
|
|
def test_inspect_failure_on_existing_container_still_fails(self, _mock) -> None:
|
|
# If the container still exists, an inspect failure must keep failing
|
|
# the run: silently skipping the stop would back up a hot volume and
|
|
# report green without the stop guarantee.
|
|
with self.assertRaises(BackupError):
|
|
docker_mod.is_swarm_task("still-here")
|
|
|
|
|
|
class TestFilterStoppable(unittest.TestCase):
|
|
@patch.object(docker_mod, "is_swarm_task", side_effect=[False, True, False])
|
|
def test_mixed_list_keeps_order_and_drops_tasks(self, _mock) -> None:
|
|
result = docker_mod.filter_stoppable(["plain-1", "swarm-task", "plain-2"])
|
|
self.assertEqual(result, ["plain-1", "plain-2"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|