From ef57217e26e7db94bbbdce37e019d320babdda85 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Thu, 31 Oct 2024 16:31:56 -0400 Subject: [PATCH] Add test and changie --- .../unreleased/Features-20241031-163149.yaml | 6 +++ .../snapshots/test_snapshot_empty.py | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .changes/unreleased/Features-20241031-163149.yaml create mode 100644 tests/functional/snapshots/test_snapshot_empty.py diff --git a/.changes/unreleased/Features-20241031-163149.yaml b/.changes/unreleased/Features-20241031-163149.yaml new file mode 100644 index 00000000000..209f2180daa --- /dev/null +++ b/.changes/unreleased/Features-20241031-163149.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Support --empty for snapshots +time: 2024-10-31T16:31:49.926164-04:00 +custom: + Author: gshank + Issue: "10372" diff --git a/tests/functional/snapshots/test_snapshot_empty.py b/tests/functional/snapshots/test_snapshot_empty.py new file mode 100644 index 00000000000..a3f648a968f --- /dev/null +++ b/tests/functional/snapshots/test_snapshot_empty.py @@ -0,0 +1,40 @@ +import pytest + +from dbt.tests.util import run_dbt + +my_model_sql = """ +select 1 as id, {{ dbt.current_timestamp() }} as updated_at +""" + +snapshots_yml = """ +snapshots: + - name: my_snapshot + relation: "ref('my_model')" + config: + unique_key: id + strategy: check + check_cols: all + dbt_valid_to_current: "date('9999-12-31')" +""" + + +class TestSnapshotEmpty: + @pytest.fixture(scope="class") + def models(self): + return { + "my_model.sql": my_model_sql, + "snapshots.yml": snapshots_yml, + } + + def test_check(self, project): + run_dbt(["run"]) + run_dbt(["snapshot", "--empty"]) + + query = "select id, updated_at, dbt_valid_from, dbt_valid_to from {database}.{schema}.my_snapshot order by updated_at asc" + snapshot_out1 = project.run_sql(query, fetch="all") + assert snapshot_out1 == [] + + run_dbt(["run"]) + run_dbt(["snapshot", "--empty"]) + snapshot_out2 = project.run_sql(query, fetch="all") + assert snapshot_out2 == []