Skip to content

Commit

Permalink
Add tox-based Integration Testing Support (#111)
Browse files Browse the repository at this point in the history
* Standardize integration tests.

* Move profiles file.

* Update config, remove extra profiles file.

* Remove old sample profiles YAML. Modify conifg accordingly.

* Tweak CircleCI config again.

* One more try tweaking config.

* Another tweak.

* Add back other adapter profiles.

* Apply suggestions from code review

---------

Co-authored-by: Emily Rockman <[email protected]>
  • Loading branch information
peterallenwebb and emmyoop authored Oct 15, 2024
1 parent c0be07f commit 6499107
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 21 deletions.
20 changes: 11 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ jobs:
username: dbt-labs
password: ''
environment:
POSTGRES_HOST: localhost
POSTGRES_USER: root
POSTGRES_DB: circle_test
POSTGRES_PORT: 5432
POSTGRES_DATABASE: circle_test
POSTGRES_SCHEMA: dbt_utils_integration_tests_postgres
DBT_ENV_SECRET_POSTGRES_PASS: ''

steps:
- checkout
Expand All @@ -35,17 +39,15 @@ jobs:
python -m pip install --upgrade pip setuptools
python -m pip install --pre dbt-core dbt-postgres dbt-redshift dbt-snowflake dbt-bigquery dbt-databricks
mkdir -p ~/.dbt
cp integration_tests/ci/sample.profiles.yml ~/.dbt/profiles.yml
- run:
name: "Run Tests - Postgres"
environment:
POSTGRES_TEST_HOST: localhost
POSTGRES_TEST_USER: root
POSTGRES_TEST_PASS: ''
POSTGRES_TEST_PORT: 5432
POSTGRES_TEST_DBNAME: circle_test
POSTGRES_HOST: localhost
POSTGRES_USER: root
POSTGRES_PORT: 5432
POSTGRES_DATABASE: circle_test
POSTGRES_SCHEMA: dbt_utils_integration_tests_postgres
DBT_ENV_SECRET_POSTGRES_PASS: ''
command: |
. dbt_venv/bin/activate
cd integration_tests
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# **what?**
# Run tests for dbt-codegen against supported adapters

# **why?**
# To ensure that dbt-codegen works as expected with all supported adapters

# **when?**
# On every PR, and every push to main and when manually triggered

name: Package Integration Tests

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

jobs:
run-tests:
uses: dbt-labs/dbt-package-testing/.github/workflows/run_tox.yml@v1
# this just tests with postgres so no variables need to be passed through.
# When it's time to add more adapters you will need to pass through inputs for
# the other adapters as shown in the below example for redshift
# with:
# # redshift
# REDSHIFT_HOST: ${{ vars.REDSHIFT_HOST }}
# REDSHIFT_USER: ${{ vars.REDSHIFT_USER }}
# REDSHIFT_DATABASE: ${{ vars.REDSHIFT_DATABASE }}
# REDSHIFT_SCHEMA: "integration_tests_redshift_${{ github.run_number }}"
# REDSHIFT_PORT: ${{ vars.REDSHIFT_PORT }}
# secrets:
# DBT_ENV_SECRET_REDSHIFT_PASS: ${{ secrets.DBT_ENV_SECRET_REDSHIFT_PASS }}
6 changes: 6 additions & 0 deletions integration_tests/.env/postgres.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
POSTGRES_HOST=localhost
POSTGRES_USER=root
DBT_ENV_SECRET_POSTGRES_PASS=password
POSTGRES_PORT=5432
POSTGRES_DATABASE=audit_helper_test
POSTGRES_SCHEMA=audit_helper_integration_tests_postgres
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@

# HEY! This file is used in the dbt-audit-helper integrations tests with CircleCI.
# You should __NEVER__ check credentials into version control. Thanks for reading :)

integration_tests:
target: postgres
outputs:
postgres:
type: postgres
host: "{{ env_var('POSTGRES_TEST_HOST') }}"
user: "{{ env_var('POSTGRES_TEST_USER') }}"
pass: "{{ env_var('POSTGRES_TEST_PASS') }}"
port: "{{ env_var('POSTGRES_TEST_PORT') | as_number }}"
dbname: "{{ env_var('POSTGRES_TEST_DBNAME') }}"
schema: audit_helper_integration_tests_postgres
threads: 1
type: "postgres"
host: "{{ env_var('POSTGRES_HOST') }}"
user: "{{ env_var('POSTGRES_USER') }}"
pass: "{{ env_var('DBT_ENV_SECRET_POSTGRES_PASS') }}"
port: "{{ env_var('POSTGRES_PORT') | as_number }}"
dbname: "{{ env_var('POSTGRES_DATABASE') }}"
schema: "{{ env_var('POSTGRES_SCHEMA') }}"
threads: 5

redshift:
type: redshift
Expand Down Expand Up @@ -51,3 +47,4 @@ integration_tests:
http_path: "{{ env_var('DATABRICKS_TEST_HTTP_PATH') }}"
token: "{{ env_var('DATABRICKS_TEST_ACCESS_TOKEN') }}"
threads: 10

1 change: 1 addition & 0 deletions supported_adapters.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SUPPORTED_ADAPTERS=postgres
24 changes: 24 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tox]
skipsdist = True
envlist = lint_all, testenv

[testenv]
passenv =
# postgres env vars
POSTGRES_HOST
POSTGRES_USER
DBT_ENV_SECRET_POSTGRES_PASS
POSTGRES_PORT
POSTGRES_DATABASE
POSTGRES_SCHEMA

# Postgres integration tests for centralized dbt testing
# run dbt commands directly, assumes dbt is already installed in environment
[testenv:dbt_integration_postgres]
changedir = integration_tests
allowlist_externals =
dbt
skip_install = true
commands =
dbt --version
dbt debug --target postgres

0 comments on commit 6499107

Please sign in to comment.