From 79214e64e8e59f6b3a5a461a33094cd71b903d66 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sat, 11 Jul 2026 08:34:36 +0200 Subject: [PATCH] test(unit): mock is_swarm_task in the requires_stop tests requires_stop now probes is_swarm_task per container, which runs a real docker inspect; the unit CI container has no docker socket, so the three whitelist tests died with BackupException. Mock the probe to False so they assert the unchanged whitelist logic, and add a swarm case proving a task container never triggers a stop and skips the image check entirely. Co-Authored-By: Claude Fable 5 --- tests/unit/test_backup.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_backup.py b/tests/unit/test_backup.py index 47404ff..9a52ebb 100644 --- a/tests/unit/test_backup.py +++ b/tests/unit/test_backup.py @@ -4,10 +4,11 @@ from unittest.mock import patch from baudolo.backup.app import requires_stop +@patch("baudolo.backup.app.is_swarm_task", return_value=False) class TestRequiresStop(unittest.TestCase): @patch("baudolo.backup.app.get_image_info") def test_requires_stop_false_when_all_images_are_whitelisted( - self, mock_get_image_info + self, mock_get_image_info, _mock_is_swarm_task ): # All containers use images containing allowed substrings mock_get_image_info.side_effect = [ @@ -20,7 +21,7 @@ class TestRequiresStop(unittest.TestCase): @patch("baudolo.backup.app.get_image_info") def test_requires_stop_true_when_any_image_is_not_whitelisted( - self, mock_get_image_info + self, mock_get_image_info, _mock_is_swarm_task ): mock_get_image_info.side_effect = [ "repo/mastodon:v4", @@ -31,10 +32,23 @@ class TestRequiresStop(unittest.TestCase): self.assertTrue(requires_stop(containers, whitelist)) @patch("baudolo.backup.app.get_image_info") - def test_requires_stop_true_when_whitelist_empty(self, mock_get_image_info): + def test_requires_stop_true_when_whitelist_empty( + self, mock_get_image_info, _mock_is_swarm_task + ): mock_get_image_info.return_value = "repo/anything:latest" self.assertTrue(requires_stop(["c1"], [])) +class TestRequiresStopSwarm(unittest.TestCase): + @patch("baudolo.backup.app.get_image_info") + @patch("baudolo.backup.app.is_swarm_task", return_value=True) + def test_swarm_tasks_never_require_stop( + self, _mock_is_swarm_task, mock_get_image_info + ): + mock_get_image_info.return_value = "repo/not-whitelisted:latest" + self.assertFalse(requires_stop(["c1"], [])) + mock_get_image_info.assert_not_called() + + if __name__ == "__main__": unittest.main()