Skip to content

Commit

Permalink
Fix singular tests (#17)
Browse files Browse the repository at this point in the history
* Add test paths

* Add singular test

* Fix refs for singular tests

* Bump version
  • Loading branch information
LewisDavies authored Jul 22, 2023
1 parent b7c9bb0 commit d9ee967
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'upstream_prod'
version: '0.6.1'
version: '0.6.2'
config-version: 2

require-dbt-version: [">=1.5.0", "<2.0.0"]
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/_template/tests/singular_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*
from
{{ ref('defer_prod') }}
where
this_model = 'This test should run but not fail'
1 change: 1 addition & 0 deletions integration_tests/create_symlinks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ do
ln -f _template/macros/* $proj/macros
ln -f _template/models/production/* $proj/models/production
ln -f _template/models/staging/* $proj/models/staging
ln -f _template/tests/singular_test.sql $proj/tests
done
1 change: 1 addition & 0 deletions integration_tests/dev_db/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config-version: 2
profile: 'upstream_prod_db'

model-paths: ["models"]
test-paths: ["tests"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/dev_db/tests/singular_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*
from
{{ ref('defer_prod') }}
where
this_model = 'This test should run but not fail'
1 change: 1 addition & 0 deletions integration_tests/dev_db_dev_sch/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config-version: 2
profile: 'upstream_prod_db_sch'

model-paths: ["models"]
test-paths: ["tests"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/dev_db_dev_sch/tests/singular_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*
from
{{ ref('defer_prod') }}
where
this_model = 'This test should run but not fail'
1 change: 1 addition & 0 deletions integration_tests/dev_db_env_sch/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config-version: 2
profile: 'upstream_prod_db_sch'

model-paths: ["models"]
test-paths: ["tests"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/dev_db_env_sch/tests/singular_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*
from
{{ ref('defer_prod') }}
where
this_model = 'This test should run but not fail'
1 change: 1 addition & 0 deletions integration_tests/dev_sch/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config-version: 2
profile: 'upstream_prod_sch'

model-paths: ["models"]
test-paths: ["tests"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/dev_sch/tests/singular_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*
from
{{ ref('defer_prod') }}
where
this_model = 'This test should run but not fail'
1 change: 1 addition & 0 deletions integration_tests/env_sch/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ config-version: 2
profile: 'upstream_prod_sch'

model-paths: ["models"]
test-paths: ["tests"]
macro-paths: ["macros"]

target-path: "target" # directory which will store compiled SQL files
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/env_sch/tests/singular_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
*
from
{{ ref('defer_prod') }}
where
this_model = 'This test should run but not fail'
12 changes: 7 additions & 5 deletions macros/ref.sql
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ The package can be disabled by setting the variable upstream_prod_enabled = Fals

-- Find models being tested
{% for test in selected_tests %}
{% set tested_model = graph.nodes[test].file_key_name.split(".")[1] %}
-- Return dev relation for explicitly selected models
{% if parent_model == tested_model %}
{{ return(parent_ref) }}
{% endif %}
{% set test_node = graph.nodes[test] %}
{% for test_ref in test_node.refs %}
-- Return dev relation for explicitly selected models
{% if parent_model == test_ref.name %}
{{ return(parent_ref) }}
{% endif %}
{% endfor %}
{% endfor %}

-- Use dev relations for models being built during the current run
Expand Down

0 comments on commit d9ee967

Please sign in to comment.