mirror of
https://github.com/FlipsideCrypto/polygon-models.git
synced 2026-02-06 18:56:48 +00:00
Add test macros (#261)
This commit is contained in:
parent
512281a711
commit
424fbfcf09
35
macros/tests/udfs.sql
Normal file
35
macros/tests/udfs.sql
Normal file
@ -0,0 +1,35 @@
|
||||
{% macro base_test_udf(model, udf, args, assertions) %}
|
||||
{#
|
||||
Generates a test for a UDF.
|
||||
#}
|
||||
{% if execute %}
|
||||
{%- set context -%}
|
||||
SET LIVEQUERY_CONTEXT = '{"userId":"{{ var("STUDIO_TEST_USER_ID") }}"}';
|
||||
{%- endset -%}
|
||||
{%- do run_query(context) -%}
|
||||
{%- endif -%}
|
||||
{%- set call -%}
|
||||
{{ target.database }}.{{ udf }}({{ args }})
|
||||
{%- endset -%}
|
||||
,
|
||||
test AS
|
||||
(
|
||||
SELECT
|
||||
'{{ udf }}' AS test_name
|
||||
,[{{ args }}] as parameters
|
||||
,{{ call }} AS result
|
||||
)
|
||||
{% for assertion in assertions %}
|
||||
SELECT
|
||||
test_name,
|
||||
parameters,
|
||||
result,
|
||||
$${{ assertion }}$$ AS assertion,
|
||||
$${{ context ~ "\n" }}SELECT {{ call ~ "\n" }};$$ AS sql
|
||||
FROM test
|
||||
WHERE NOT {{ assertion }}
|
||||
{%- if not loop.last -%}
|
||||
UNION ALL
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
{%- endmacro -%}
|
||||
12
tests/generic/test_udf.sql
Normal file
12
tests/generic/test_udf.sql
Normal file
@ -0,0 +1,12 @@
|
||||
{% test test_udf(model, column_name, args, assertions) %}
|
||||
{#
|
||||
This is a generic test for UDFs.
|
||||
The udfs are deployed using ephemeral models, so we need to
|
||||
use the ephemeral model name to get the udf name.
|
||||
#}
|
||||
{%- set schema = model | replace("__dbt__cte__", "") -%}
|
||||
{%- set schema = schema.split("__") | first -%}
|
||||
{%- set udf = schema ~ "." ~ column_name -%}
|
||||
|
||||
{{ base_test_udf(model, udf, args, assertions) }}
|
||||
{% endtest %}
|
||||
Loading…
Reference in New Issue
Block a user