mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 23:08:06 +02:00
Solved run_after dependency bug
This commit is contained in:
36
tests/integration/test_circular_dependencies.py
Normal file
36
tests/integration/test_circular_dependencies.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
# import the functions from your CLI script
|
||||
from cli.generate_playbook import build_dependency_graph, find_cycle
|
||||
|
||||
class TestCircularDependencies(unittest.TestCase):
|
||||
"""
|
||||
Integration test: ensure there are no circular 'run_after' dependencies
|
||||
among the roles in the roles/ directory.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# Determine the path to the repo root and the roles directory
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
repo_root = os.path.abspath(os.path.join(here, '..', '..'))
|
||||
cls.roles_dir = os.path.join(repo_root, 'roles')
|
||||
|
||||
def test_no_circular_dependencies(self):
|
||||
# Build the dependency graph using the real roles/
|
||||
graph, in_degree, roles = build_dependency_graph(self.roles_dir)
|
||||
|
||||
# Attempt to find a cycle in the run_after mapping
|
||||
cycle = find_cycle(roles)
|
||||
|
||||
if cycle:
|
||||
# Format cycle as "A -> B -> C -> A"
|
||||
cycle_str = " -> ".join(cycle)
|
||||
self.fail(f"Circular dependency detected among roles: {cycle_str}")
|
||||
|
||||
# If no cycle, this assertion will pass
|
||||
self.assertIsNone(cycle, "Expected no circular dependencies")
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in New Issue
Block a user