mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Adapted discourse version to new code after the big refactoring
This commit is contained in:
36
tests/integration/test_handlers_no_vars_in_name.py
Normal file
36
tests/integration/test_handlers_no_vars_in_name.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import unittest
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
|
||||
class HandlerNameIntegrationTest(unittest.TestCase):
|
||||
"""
|
||||
Integration test to ensure that handler definitions in Ansible roles
|
||||
do not include Jinja variable interpolations in their 'name' attribute.
|
||||
"""
|
||||
|
||||
def test_handlers_have_no_variables_in_name(self):
|
||||
# Locate all handler YAML files under roles/*/handlers/
|
||||
handler_files = Path('roles').glob('*/handlers/*.yml')
|
||||
for handler_file in handler_files:
|
||||
with self.subTest(handler_file=str(handler_file)):
|
||||
content = handler_file.read_text(encoding='utf-8')
|
||||
# Load all documents in the YAML file
|
||||
documents = list(yaml.safe_load_all(content))
|
||||
for index, doc in enumerate(documents):
|
||||
if not isinstance(doc, dict):
|
||||
continue
|
||||
# Only consider entries that are handlers (they have a 'listen' key)
|
||||
if 'listen' in doc:
|
||||
name = doc.get('name', '')
|
||||
# Assert that no Jinja interpolation is present in the name
|
||||
self.assertNotRegex(
|
||||
name,
|
||||
r"{{.*}}",
|
||||
msg=(
|
||||
f"Handler 'name' in file {handler_file} document #{index} "
|
||||
f"contains a Jinja variable: {name}"
|
||||
)
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user