diff --git a/tests/unit/parser/test_manifest.py b/tests/unit/parser/test_manifest.py index 4c887bce5c0..705b8256f24 100644 --- a/tests/unit/parser/test_manifest.py +++ b/tests/unit/parser/test_manifest.py @@ -7,10 +7,13 @@ from dbt.artifacts.resources.base import FileHash from dbt.config import RuntimeConfig from dbt.contracts.graph.manifest import Manifest, ManifestStateCheck +from dbt.events.types import UnusedResourceConfigPath from dbt.flags import set_from_args -from dbt.parser.manifest import ManifestLoader +from dbt.parser.manifest import ManifestLoader, _warn_for_unused_resource_config_paths from dbt.parser.read_files import FileDiff from dbt.tracking import User +from dbt_common.events.event_manager_client import add_callback_to_manager +from tests.utils import EventCatcher class TestPartialParse: @@ -191,3 +194,47 @@ def test_partial_parse_file_diff_flag( set_from_args(Namespace(PARTIAL_PARSE_FILE_DIFF=False), {}) ManifestLoader.get_full_manifest(config=mock_project) assert mock_file_diff.called + + +class TestWarnUnusedConfigs: + @pytest.mark.parametrize( + "resource_type,path,expect_used", + [ + ("data_tests", "unused_path", False), + ("data_tests", "minimal", True), + ("metrics", "unused_path", False), + ("metrics", "test", True), + ("models", "unused_path", False), + ("models", "pkg", True), + ("saved_queries", "unused_path", False), + ("saved_queries", "test", True), + ("seeds", "unused_path", False), + ("seeds", "pkg", True), + ("semantic_models", "unused_path", False), + ("semantic_models", "test", True), + ("sources", "unused_path", False), + ("sources", "pkg", True), + ("unit_tests", "unused_path", False), + ("unit_tests", "pkg", True), + ], + ) + def test_warn_for_unused_resource_config_paths( + self, + resource_type: str, + path: str, + expect_used: bool, + manifest: Manifest, + runtime_config: RuntimeConfig, + ) -> None: + catcher = EventCatcher(UnusedResourceConfigPath) + add_callback_to_manager(catcher.catch) + + setattr(runtime_config, resource_type, {path: {"+materialized": "table"}}) + + _warn_for_unused_resource_config_paths(manifest=manifest, config=runtime_config) + + if expect_used: + assert len(catcher.caught_events) == 0 + else: + assert len(catcher.caught_events) == 1 + assert f"{resource_type}.{path}" in str(catcher.caught_events[0].data)