Reject keep values below -1

A keep below -1 made remove_old_backups() delete every backup, including the new one, and then crash.
This commit is contained in:
Fuxino
2026-10-21 22:16:47 +02:00
parent 85bce54b05
commit 535f7a33fe
2 changed files with 17 additions and 0 deletions
+12
View File
@@ -191,6 +191,18 @@ ssh_keyfile=/keys/id
assert FakeBackup.instances == []
assert 'Both SSH host and SSH user are needed' in caplog.text
@pytest.mark.parametrize('config_keep, argv', [
('keep=-2', []),
('', ['-k', '-2']),
])
def test_keep_below_minus_one(self, run_cli: RunCli, config: Callable[[str], str],
caplog: pytest.LogCaptureFixture, config_keep: str, argv: list[str]) -> None:
config_file = config(f'backup_dir=/backups\n{config_keep}')
assert run_cli('-c', config_file, *argv) == 6
assert FakeBackup.instances == []
assert 'Invalid number of backups to keep: -2' in caplog.text
def test_bad_config(self, run_cli: RunCli, config: Callable[[str], str],
caplog: pytest.LogCaptureFixture) -> None:
config_file = config('backup_dir=/backups\nkeep=abc')