mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-12-07 09:56:41 +00:00
Optimized test and added more output
This commit is contained in:
@@ -57,17 +57,37 @@ class TestIncludeImportRoleExistence(unittest.TestCase):
|
||||
self.fail(f"Failed to parse YAML in {file_path}")
|
||||
|
||||
for doc in docs:
|
||||
# Skip empty YAML documents (e.g. only "---")
|
||||
if doc is None:
|
||||
continue
|
||||
|
||||
for role_name in self._collect_includes(doc):
|
||||
|
||||
# NEW: Validate that role_name is a proper string
|
||||
if not isinstance(role_name, str) or not role_name.strip():
|
||||
self.fail(
|
||||
"Invalid include_role/import_role name detected.\n"
|
||||
f" • File: {file_path}\n"
|
||||
f" • Extracted name value: {repr(role_name)}\n"
|
||||
"The 'name:' field must contain a non-empty string.\n"
|
||||
"Example:\n"
|
||||
" include_role:\n"
|
||||
" name: my-role-name\n"
|
||||
)
|
||||
|
||||
# Convert Jinja2 templates and wildcards to glob patterns
|
||||
pattern = re.sub(r"\{\{.*?\}\}", '*', role_name)
|
||||
glob_path = os.path.join(self.roles_dir, pattern)
|
||||
# Check for matching role directories
|
||||
|
||||
matches = [p for p in glob.glob(glob_path) if os.path.isdir(p)]
|
||||
if not matches:
|
||||
missing.append((file_path, role_name))
|
||||
|
||||
if missing:
|
||||
messages = [f"File '{fp}' references missing role '{rn}'" for fp, rn in missing]
|
||||
messages = [
|
||||
f"File '{fp}' references missing role '{rn}'"
|
||||
for fp, rn in missing
|
||||
]
|
||||
self.fail("\n".join(messages))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user