mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-07-18 06:24:25 +02:00
Validated use of correct applications in group_names
This commit is contained in:
parent
d43fdc63ea
commit
80d26ca068
@ -8,7 +8,6 @@
|
|||||||
label: "{{ item }}-roles.yml"
|
label: "{{ item }}-roles.yml"
|
||||||
|
|
||||||
- name: general host setup
|
- name: general host setup
|
||||||
when: ("personal_computers" in group_names)
|
|
||||||
include_role:
|
include_role:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
loop:
|
loop:
|
@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: Setup server base
|
- name: Setup server base
|
||||||
when: ("servers" in group_names)
|
|
||||||
include_role:
|
include_role:
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
loop:
|
loop:
|
||||||
|
47
tests/integration/test_group_applications.py
Normal file
47
tests/integration/test_group_applications.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import unittest
|
||||||
|
from cli.meta.applications import find_application_ids
|
||||||
|
|
||||||
|
# ensure project root is on PYTHONPATH so we can import your CLI code
|
||||||
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
|
||||||
|
sys.path.insert(0, ROOT)
|
||||||
|
|
||||||
|
class TestGroupApplications(unittest.TestCase):
|
||||||
|
# regex to capture any literal check in group_names: 'name' in/not in group_names
|
||||||
|
GROUP_CHECK_RE = re.compile(r"['\"](?P<name>[^'\"]+)['\"]\s*(?:in|not in)\s*group_names")
|
||||||
|
|
||||||
|
def test_group_name_checks_use_valid_application_ids(self):
|
||||||
|
"""
|
||||||
|
Ensures that any string checked against group_names corresponds to a valid application ID.
|
||||||
|
"""
|
||||||
|
valid_apps = find_application_ids()
|
||||||
|
|
||||||
|
# walk the entire project tree
|
||||||
|
for dirpath, _, filenames in os.walk(ROOT):
|
||||||
|
for filename in filenames:
|
||||||
|
if not filename.lower().endswith(('.yml', '.yaml')):
|
||||||
|
continue
|
||||||
|
filepath = os.path.join(dirpath, filename)
|
||||||
|
try:
|
||||||
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
|
text = f.read()
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# find all group_names checks in the file
|
||||||
|
for match in self.GROUP_CHECK_RE.finditer(text):
|
||||||
|
name = match.group('name')
|
||||||
|
# the checked name must be one of the valid application IDs
|
||||||
|
self.assertIn(
|
||||||
|
name,
|
||||||
|
valid_apps,
|
||||||
|
msg=(
|
||||||
|
f"{filepath}: group_names check uses '{name}', "
|
||||||
|
f"which is not a known application ID {valid_apps}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user