Added invokable paths for role categories

This commit is contained in:
2025-07-10 18:28:39 +02:00
parent 12d833d20c
commit 74ebb375d0
6 changed files with 227 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import os
import yaml
import unittest
from pathlib import Path
from filter_plugins.invokable_paths import get_invokable_paths
ROLES_DIR = Path(__file__).resolve().parent.parent.parent / "roles"
@@ -9,7 +10,7 @@ ROLES_DIR = Path(__file__).resolve().parent.parent.parent / "roles"
class TestApplicationIdConsistency(unittest.TestCase):
def test_application_id_matches_docker_prefix(self):
failed_roles = []
prefixes = ("web-app-", "web-svc-", "desk-", "util-", "drv-")
prefixes = (get_invokable_paths(suffix="-"))
for role_path in ROLES_DIR.iterdir():
if not role_path.is_dir():

View File

@@ -28,7 +28,8 @@ class TestCategoryPaths(unittest.TestCase):
# Nested subcategories (keys other than metadata)
for sub_key in attrs:
if sub_key in ('title', 'description', 'icon', 'children'):
# Skip metadata keys
if sub_key in ('title', 'description', 'icon', 'children', 'invokable'):
continue
expected.add(f"{top_key}-{sub_key}")

View File

@@ -0,0 +1,74 @@
import unittest
import tempfile
import yaml
import os
from filter_plugins.invokable_paths import get_invokable_paths
class TestInvokablePaths(unittest.TestCase):
def write_yaml(self, data):
tmp = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.yml')
yaml.dump(data, tmp)
tmp.close()
return tmp.name
def test_empty_roles(self):
path = self.write_yaml({})
self.assertEqual(get_invokable_paths(path), [])
os.unlink(path)
def test_single_invokable_true(self):
data = {'role1': {'invokable': True}}
path = self.write_yaml(data)
self.assertEqual(get_invokable_paths(path), ['role1'])
os.unlink(path)
def test_single_invokable_false_or_missing(self):
data_false = {'role1': {'invokable': False}}
path_false = self.write_yaml(data_false)
self.assertEqual(get_invokable_paths(path_false), [])
os.unlink(path_false)
data_missing = {'role1': {}}
path_missing = self.write_yaml(data_missing)
self.assertEqual(get_invokable_paths(path_missing), [])
os.unlink(path_missing)
def test_nested_and_deeply_nested(self):
data = {
'parent': {
'invokable': True,
'child': {'invokable': True},
'other': {'invokable': False},
'sub': {
'deep': {'invokable': True}
}
}
}
path = self.write_yaml(data)
expected = ['parent', 'parent-child', 'parent-sub-deep']
self.assertEqual(sorted(get_invokable_paths(path)), sorted(expected))
os.unlink(path)
def test_ignore_metadata_and_unwrap(self):
data = {'roles': {
'role1': {
'invokable': True,
'title': {'foo': 'bar'},
'description': {'bar': 'baz'}
}
}}
path = self.write_yaml(data)
self.assertEqual(get_invokable_paths(path), ['role1'])
os.unlink(path)
def test_suffix_appended(self):
data = {'role1': {'invokable': True}}
path = self.write_yaml(data)
self.assertEqual(get_invokable_paths(path, suffix='_suf'), ['role1_suf'])
os.unlink(path)
if __name__ == '__main__':
unittest.main()