-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kyle Wigley
committed
May 27, 2021
1 parent
9e876cd
commit 1ed23b2
Showing
11 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/integration/008_schema_tests_test/local_dependency/dbt_project.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'local_dep' | ||
version: '1.0' | ||
config-version: 2 | ||
|
||
profile: 'default' | ||
|
||
macro-paths: ["macros"] |
63 changes: 63 additions & 0 deletions
63
test/integration/008_schema_tests_test/local_dependency/macros/equality.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{#-- taken from dbt-utils --#} | ||
{% test equality(model, compare_model, compare_columns=None) %} | ||
{{ return(adapter.dispatch('test_equality')(model, compare_model, compare_columns)) }} | ||
{% endtest %} | ||
|
||
{% macro default__test_equality(model, compare_model, compare_columns=None) %} | ||
|
||
{% set set_diff %} | ||
count(*) + abs( | ||
sum(case when which_diff = 'a_minus_b' then 1 else 0 end) - | ||
sum(case when which_diff = 'b_minus_a' then 1 else 0 end) | ||
) | ||
{% endset %} | ||
|
||
{#-- Needs to be set at parse time, before we return '' below --#} | ||
{{ config(fail_calc = set_diff) }} | ||
|
||
{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #} | ||
{%- if not execute -%} | ||
{{ return('') }} | ||
{% endif %} | ||
-- setup | ||
{%- do dbt_utils._is_relation(model, 'test_equality') -%} | ||
{#- | ||
If the compare_cols arg is provided, we can run this test without querying the | ||
information schema — this allows the model to be an ephemeral model | ||
-#} | ||
|
||
{%- if not compare_columns -%} | ||
{%- do dbt_utils._is_ephemeral(model, 'test_equality') -%} | ||
{%- set compare_columns = adapter.get_columns_in_relation(model) | map(attribute='quoted') -%} | ||
{%- endif -%} | ||
|
||
{% set compare_cols_csv = compare_columns | join(', ') %} | ||
|
||
with a as ( | ||
select * from {{ model }} | ||
), | ||
b as ( | ||
select * from {{ compare_model }} | ||
), | ||
a_minus_b as ( | ||
select {{compare_cols_csv}} from a | ||
{{ dbt_utils.except() }} | ||
select {{compare_cols_csv}} from b | ||
), | ||
b_minus_a as ( | ||
select {{compare_cols_csv}} from b | ||
{{ dbt_utils.except() }} | ||
select {{compare_cols_csv}} from a | ||
), | ||
|
||
unioned as ( | ||
|
||
select 'a_minus_b' as which_diff, * from a_minus_b | ||
union all | ||
select 'b_minus_a' as which_diff, * from b_minus_a | ||
|
||
) | ||
|
||
select * from unioned | ||
|
||
{% endmacro %} |
25 changes: 25 additions & 0 deletions
25
test/integration/008_schema_tests_test/macros-v2/custom-configs/test.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% test where(model, column_name) %} | ||
{{ config(where = "1 = 0") }} | ||
select * from {{ model }} | ||
{% endtest %} | ||
|
||
{% test error_if(model, column_name) %} | ||
{{ config(error_if = "<= 0", warn_if = "<= 0") }} | ||
select * from {{ model }} | ||
{% endtest %} | ||
|
||
|
||
{% test warn_if(model, column_name) %} | ||
{{ config(warn_if = "<= 0", severity = "WARN") }} | ||
select * from {{ model }} | ||
{% endtest %} | ||
|
||
{% test limit(model, column_name) %} | ||
{{ config(limit = 0) }} | ||
select * from {{ model }} | ||
{% endtest %} | ||
|
||
{% test fail_calc(model, column_name) %} | ||
{{ config(fail_calc = "count(*) - count(*)") }} | ||
select * from {{ model }} | ||
{% endtest %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ | |
select {{ validation_message }} as validation_error | ||
where {{ eq }} = 0 | ||
{% endtest %} | ||
|
12 changes: 12 additions & 0 deletions
12
test/integration/008_schema_tests_test/models-v2/custom-configs/schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: table_copy | ||
description: "A copy of the table" | ||
# passes | ||
tests: | ||
- where | ||
- error_if | ||
- warn_if | ||
- limit | ||
- fail_calc |
8 changes: 8 additions & 0 deletions
8
test/integration/008_schema_tests_test/models-v2/custom-configs/table_copy.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
{{ | ||
config( | ||
materialized='table' | ||
) | ||
}} | ||
|
||
select * from {{ this.schema }}.seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters