feat(profiles): implement slice 3 profile system, flock concurrency, and sanitize archiver

This commit is contained in:
soda64 committed 2026-10-09 18:59:49 +02:00
1 parent 66ca179937
commit 646bd9d145
8 files changed
+536 -69

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
import json
import os
import tempfile
import unittest
from linux_backuper.core.profiles import ProfileManager
from linux_backuper.models import ProfileConfig
class TestProfileManager(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.mkdtemp(prefix="test_profiles_")
def tearDown(self):
import shutil
shutil.rmtree(self.temp_dir, ignore_errors=True)
def test_builtin_profiles_exist(self):
mgr = ProfileManager()
profiles = mgr.list_profiles()
names = [p.name for p in profiles]
self.assertIn("quick", names)
self.assertIn("system", names)
self.assertIn("full", names)
def test_quick_profile_paths(self):
mgr = ProfileManager()
quick = mgr.get_profile("quick")
self.assertEqual(quick.name, "quick")
self.assertIn("/etc", quick.included_paths)
self.assertNotIn("/boot", quick.included_paths)
def test_system_profile_paths(self):
mgr = ProfileManager()
system = mgr.get_profile("system")
self.assertIn("/etc", system.included_paths)
self.assertIn("/boot", system.included_paths)
def test_full_profile_paths(self):
mgr = ProfileManager()
full = mgr.get_profile("full")
self.assertIn("/etc", full.included_paths)
self.assertIn("/boot", full.included_paths)
self.assertIn("/var/spool/cron", full.included_paths)
self.assertIn("/var/lib/systemd", full.included_paths)
def test_custom_profile_from_config(self):
config_path = os.path.join(self.temp_dir, "linux-backuper.json")
custom_data = {
"profiles": {
"custom_web": {
"description": "Web server custom profile",
"included_paths": ["/etc", "/var/www/html"],
"exclude_patterns": ["*.log", "*.tmp"],
"collect_packages": True
}
}
}
with open(config_path, "w") as f:
json.dump(custom_data, f)
mgr = ProfileManager(config_path=config_path)
p = mgr.get_profile("custom_web")
self.assertEqual(p.name, "custom_web")
self.assertIn("/var/www/html", p.included_paths)
self.assertIn("*.log", p.exclude_patterns)
def test_unknown_profile_raises_key_error(self):
mgr = ProfileManager()
with self.assertRaises(KeyError):
mgr.get_profile("non_existent_profile_xyz")
if __name__ == "__main__":
unittest.main()