Files
linux-backuper/tests/test_completions.py
T
soda64 4b3346fd74
Test, Lint and Security Gate / Security Scan and Quality Audits (push) Failing after 8s
Test, Lint and Security Gate / Unit & Security Tests (Coverage >= 80%) (push) Has been skipped
Build and Publish Release / Build Packages and Publish (push) Successful in 1m31s
feat: modernize to Software Factory standards, add AppSec suite, and bump to v2.0.0
- Refactor tests to achieve 100% Zero-Mocks compliance (remove unittest.mock, add tests.helpers.env_override and stdlib redirects)
- Extract testable parsing methods in package managers and inspector
- Add tests/test_security.py with 5 negative AppSec test cases (Zip Slip, Root Gate, Tampering SHA-256, Secret Sanitization, and AST check for zero shell=True)
- Expand is_sanitized_target to redact all private SSH/TLS keys (*.key, *.pem, id_*)
- Split Gitea CI/CD pipelines into test-and-lint.yaml and build-and-release.yaml
- Add .gitleaks.toml configuration
- Formally close v1.0.0 genesis plan in docs/plans/linux-backuper/00-status.md as immutable ADR
- Bump version to v2.0.0 across __init__.py, man page, tests, and documentation
2026-10-23 22:08:15 +02:00

60 lines
2.2 KiB
Python

"""Unit tests for shell completions and CLI help."""
from contextlib import redirect_stdout
import io
import unittest
from linux_backuper.cli import main
from linux_backuper.core.completions import generate_completion
class TestCompletions(unittest.TestCase):
"""Test shell autocompletion generator and CLI output."""
def test_generate_bash_completion(self):
script = generate_completion("bash")
self.assertIn("_linux_backuper()", script)
self.assertIn("complete -F _linux_backuper linux-backuper", script)
self.assertIn("snapshot list show diff extract restore prune push verify completion", script)
def test_generate_zsh_completion(self):
script = generate_completion("zsh")
self.assertIn("#compdef linux-backuper", script)
self.assertIn("_linux_backuper()", script)
self.assertIn("snapshot:Capture a new system state snapshot", script)
def test_generate_invalid_shell(self):
with self.assertRaises(ValueError):
generate_completion("fish")
def test_cli_completion_subcommand_bash(self):
stdout_buf = io.StringIO()
with redirect_stdout(stdout_buf):
code = main(["completion", "bash"])
self.assertEqual(code, 0)
out = stdout_buf.getvalue()
self.assertIn("complete -F _linux_backuper linux-backuper", out)
def test_cli_completion_subcommand_zsh(self):
stdout_buf = io.StringIO()
with redirect_stdout(stdout_buf):
code = main(["completion", "zsh"])
self.assertEqual(code, 0)
out = stdout_buf.getvalue()
self.assertIn("#compdef linux-backuper", out)
def test_cli_help(self):
stdout_buf = io.StringIO()
with redirect_stdout(stdout_buf):
with self.assertRaises(SystemExit) as cm:
main(["--help"])
self.assertEqual(cm.exception.code, 0)
out = stdout_buf.getvalue()
self.assertIn("Enterprise Linux system snapshot", out)
for subcmd in ["snapshot", "list", "show", "diff", "extract", "restore", "prune", "push", "verify", "completion"]:
self.assertIn(subcmd, out)
if __name__ == "__main__":
unittest.main()