mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
refactor: improve get_service_name suffix handling and handler usage
- Updated filter_plugins/get_service_name.py: * Default suffix handling: auto-select .service (no '@') or .timer (with '@') * Explicit False disables suffix entirely * Explicit string suffix still supported - Updated sys-systemctl handler to use new filter instead of SYS_SERVICE_SUFFIX - Extended unit tests to cover new suffix behavior Ref: https://chat.openai.com/share/8c2de9e6-daa0-44dd-ae13-d7a7d8d8b6d9
This commit is contained in:
@@ -2,30 +2,32 @@ import unittest
|
||||
from filter_plugins import get_service_name
|
||||
|
||||
class TestGetServiceName(unittest.TestCase):
|
||||
def test_normal_service(self):
|
||||
# Expect a dot between id and software name
|
||||
def test_default_suffix_service(self):
|
||||
self.assertEqual(
|
||||
get_service_name.get_service_name("sys-ctl-cln-backups", "nginx"),
|
||||
"sys-ctl-cln-backups.nginx.service"
|
||||
)
|
||||
|
||||
def test_normal_service_custom_suffix(self):
|
||||
self.assertEqual(
|
||||
get_service_name.get_service_name("sys-ctl-cln-backups", "nginx", "timer"),
|
||||
"sys-ctl-cln-backups.nginx.timer"
|
||||
)
|
||||
|
||||
def test_with_at_suffix(self):
|
||||
# If systemctl_id ends with '@', @ is moved behind software name
|
||||
def test_default_suffix_timer(self):
|
||||
self.assertEqual(
|
||||
get_service_name.get_service_name("sys-ctl-bkp@", "postgres"),
|
||||
"sys-ctl-bkp.postgres@.service"
|
||||
"sys-ctl-bkp.postgres@.timer"
|
||||
)
|
||||
|
||||
def test_with_at_and_custom_suffix(self):
|
||||
def test_explicit_custom_suffix(self):
|
||||
self.assertEqual(
|
||||
get_service_name.get_service_name("sys-ctl-bkp@", "postgres", "timer"),
|
||||
"sys-ctl-bkp.postgres@.timer"
|
||||
get_service_name.get_service_name("sys-ctl-bkp@", "postgres", "special"),
|
||||
"sys-ctl-bkp.postgres@.special"
|
||||
)
|
||||
|
||||
def test_explicit_false_suffix(self):
|
||||
self.assertEqual(
|
||||
get_service_name.get_service_name("sys-ctl-bkp@", "postgres", False),
|
||||
"sys-ctl-bkp.postgres@"
|
||||
)
|
||||
self.assertEqual(
|
||||
get_service_name.get_service_name("sys-ctl-cln-backups", "nginx", False),
|
||||
"sys-ctl-cln-backups.nginx"
|
||||
)
|
||||
|
||||
def test_case_is_lowered(self):
|
||||
|
Reference in New Issue
Block a user