From 374ce28b690c0a3b627d6f931b74fcfd9e3ce45c Mon Sep 17 00:00:00 2001 From: Peter Allen Webb Date: Thu, 1 Feb 2024 12:07:46 -0500 Subject: [PATCH] Add unit tests for invocation context. --- dbt_common/context.py | 6 +++--- tests/unit/test_invocation_context.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_invocation_context.py diff --git a/dbt_common/context.py b/dbt_common/context.py index 1d0b28b0..35223c35 100644 --- a/dbt_common/context.py +++ b/dbt_common/context.py @@ -6,9 +6,9 @@ class InvocationContext: - def __init__(self): - self._env: Mapping[str, str] = None - self._env_secrets: List[str] + def __init__(self, env: Mapping[str, str]): + self._env = env + self._env_secrets: List[str] = None # This class will also eventually manage the invocation_id, flags, event manager, etc. @property diff --git a/tests/unit/test_invocation_context.py b/tests/unit/test_invocation_context.py new file mode 100644 index 00000000..9653996f --- /dev/null +++ b/tests/unit/test_invocation_context.py @@ -0,0 +1,17 @@ +from dbt_common.constants import SECRET_ENV_PREFIX +from dbt_common.context import InvocationContext + +def test_invocation_context_env(): + test_env = {"VAR_1": "value1", "VAR_2": "value2"} + ic = InvocationContext(env=test_env) + assert ic.env == test_env + +def test_invocation_context_secrets(): + test_env = { + f"{SECRET_ENV_PREFIX}_VAR_1": "secret1", + f"{SECRET_ENV_PREFIX}VAR_2": "secret2", + f"NON_SECRET": "nonsecret", + f"foo{SECRET_ENV_PREFIX}": "nonsecret", + } + ic = InvocationContext(env=test_env) + assert set(ic.env_secrets) == set(["secret1", "secret2"]) \ No newline at end of file