Skip to content

Commit

Permalink
Add unit tests for invocation context.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterallenwebb committed Feb 1, 2024
1 parent 8ac1293 commit 374ce28
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dbt_common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_invocation_context.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 374ce28

Please sign in to comment.