Skip to content

Commit

Permalink
Add test which ensures bad source freshness checks raise appropriate …
Browse files Browse the repository at this point in the history
…error

This test directly tests that when a source freshness check doesn't have a
`loaded_at_field` and the adapter in use doesn't support metadata checks,
then the appropriate error message gets raised. That is, it directly tests
the change made in a162d53. This test indirectly tests the changes in both
7ec2f82 and 7b0ff31 as the appropriate error can only be raised because
we've fixed other upstream issues via those commits.
  • Loading branch information
QMalcolm committed Mar 26, 2024
1 parent a162d53 commit d9254ce
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/functional/sources/test_source_freshness.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import yaml

import dbt.version
from dbt.artifacts.schemas.freshness import FreshnessResult
from dbt.artifacts.schemas.results import FreshnessStatus
from dbt.cli.main import dbtRunner
from tests.functional.sources.common_source_setup import BaseSourcesTest
from tests.functional.sources.fixtures import (
Expand Down Expand Up @@ -385,7 +387,7 @@ class TestMetadataFreshnessFails:
def models(self):
return {"schema.yml": freshness_via_metadata_schema_yml}

def test_metadata_freshness_fails(self, project):
def test_metadata_freshness_unsupported_parse_warning(self, project):
"""Since the default test adapter (postgres) does not support metadata
based source freshness checks, trying to use that mechanism should
result in a parse-time warning."""
Expand All @@ -401,6 +403,16 @@ def warning_probe(e):

assert got_warning

def test_metadata_freshness_unsupported_error_when_run(self, project):

runner = dbtRunner()
result = runner.invoke(["source", "freshness"])
assert isinstance(result.result, FreshnessResult)
assert len(result.result.results) == 1
freshness_result = result.result.results[0]
assert freshness_result.status == FreshnessStatus.RuntimeErr
assert "Could not compute freshness for source test_table" in freshness_result.message


class TestHooksInSourceFreshness(SuccessfulSourceFreshnessTest):
@pytest.fixture(scope="class")
Expand Down

0 comments on commit d9254ce

Please sign in to comment.