from pathlib import Path from src.coordinator import Coordinator from src.env_file_helper import DependencyRule, EnvFile, sort_env_files_by_rule def test_complex_sorting() -> None: demo_rules = [ # X depends on Y DependencyRule("a", "e"), DependencyRule("b", "e"), DependencyRule("b", "f"), DependencyRule("c", "e"), DependencyRule("d", "e"), DependencyRule("f", "e"), ] demo_types = ["a", "b", "c", "d", "e", "f", "g"] env_files = [EnvFile(env_type=t, env_path=Path(), config=dict()) for t in demo_types] sorted_env_files = sort_env_files_by_rule(env_files, demo_rules) assert sorted_env_files[0].env_type == "e" def test_real_env_files() -> None: """authentik should be first""" ENV_FILES = [ Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik ] env_files: list[EnvFile] = Coordinator._getn_env_files_list(ENV_FILES) dependency_rules: list[DependencyRule] = Coordinator._get_dependency_rules(env_files) sorted_env_files = sort_env_files_by_rule(env_files, dependency_rules) assert sorted_env_files[0].env_type == "authentik"