From 290b3f879a0e453392c66e5fe9e931a1973322c3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 14 Dec 2023 10:44:08 +0100 Subject: [PATCH] add missing key assertion in _get_dependency_rules and add test case --- pytest_abra/env_manager.py | 1 + tests/test_env_resolution.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pytest_abra/env_manager.py b/pytest_abra/env_manager.py index ab3754a..8664624 100644 --- a/pytest_abra/env_manager.py +++ b/pytest_abra/env_manager.py @@ -44,6 +44,7 @@ class EnvManager: def _get_dependency_rules(env_files: list[EnvFile], RUNNER_DICT: dict[str, type["Runner"]]) -> list[DependencyRule]: dependency_rules: list[DependencyRule] = [] for env_file in env_files: + assert env_file.env_type in RUNNER_DICT, f"no runner for env_type={env_file.env_type} found in RUNNER_DICT" child_runner_class = RUNNER_DICT[env_file.env_type] for dependency in child_runner_class.dependencies: dependency_rule = DependencyRule(child=child_runner_class.env_type, dependency=dependency) diff --git a/tests/test_env_resolution.py b/tests/test_env_resolution.py index ddb5fc4..bbdf8f0 100644 --- a/tests/test_env_resolution.py +++ b/tests/test_env_resolution.py @@ -102,3 +102,17 @@ def test_env_manager() -> None: assert ENV.env_files[0].env_type == "authentik" assert ENV.env_files[1].env_type == "authentik" assert ENV.env_files[2].env_type == "wordpress" + + +def test_RUNNER_DICT_missing_key() -> None: + """RUNNER_DICT missing wordpress key while .env file with TYPE=wordpress given""" + env_paths_list = [ + Path("envfiles/blog.test.dev.local-it.cloud.env"), # wordpress + Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik + Path("envfiles/login.test.dev.local-it.cloud.env"), # authentik + ] + RUNNER_DICT_COPY = RUNNER_DICT.copy() + del RUNNER_DICT_COPY["wordpress"] + with pytest.raises(AssertionError) as excinfo: + EnvManager(env_paths_list, RUNNER_DICT_COPY) + assert "no runner for" in str(excinfo.value)