Skip to content

Commit 6499107

Browse files
Add tox-based Integration Testing Support (#111)
* 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 <ebuschang@gmail.com>
1 parent c0be07f commit 6499107

File tree

6 files changed

+84
-21
lines changed

6 files changed

+84
-21
lines changed

.circleci/config.yml

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ jobs:
1010
username: dbt-labs
1111
password: ''
1212
environment:
13+
POSTGRES_HOST: localhost
1314
POSTGRES_USER: root
14-
POSTGRES_DB: circle_test
15+
POSTGRES_PORT: 5432
16+
POSTGRES_DATABASE: circle_test
17+
POSTGRES_SCHEMA: dbt_utils_integration_tests_postgres
18+
DBT_ENV_SECRET_POSTGRES_PASS: ''
1519

1620
steps:
1721
- checkout
@@ -35,17 +39,15 @@ jobs:
3539
python -m pip install --upgrade pip setuptools
3640
python -m pip install --pre dbt-core dbt-postgres dbt-redshift dbt-snowflake dbt-bigquery dbt-databricks
3741
38-
mkdir -p ~/.dbt
39-
cp integration_tests/ci/sample.profiles.yml ~/.dbt/profiles.yml
40-
4142
- run:
4243
name: "Run Tests - Postgres"
4344
environment:
44-
POSTGRES_TEST_HOST: localhost
45-
POSTGRES_TEST_USER: root
46-
POSTGRES_TEST_PASS: ''
47-
POSTGRES_TEST_PORT: 5432
48-
POSTGRES_TEST_DBNAME: circle_test
45+
POSTGRES_HOST: localhost
46+
POSTGRES_USER: root
47+
POSTGRES_PORT: 5432
48+
POSTGRES_DATABASE: circle_test
49+
POSTGRES_SCHEMA: dbt_utils_integration_tests_postgres
50+
DBT_ENV_SECRET_POSTGRES_PASS: ''
4951
command: |
5052
. dbt_venv/bin/activate
5153
cd integration_tests

.github/workflows/ci.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# **what?**
2+
# Run tests for dbt-codegen against supported adapters
3+
4+
# **why?**
5+
# To ensure that dbt-codegen works as expected with all supported adapters
6+
7+
# **when?**
8+
# On every PR, and every push to main and when manually triggered
9+
10+
name: Package Integration Tests
11+
12+
on:
13+
push:
14+
branches:
15+
- main
16+
pull_request:
17+
workflow_dispatch:
18+
19+
jobs:
20+
run-tests:
21+
uses: dbt-labs/dbt-package-testing/.github/workflows/run_tox.yml@v1
22+
# this just tests with postgres so no variables need to be passed through.
23+
# When it's time to add more adapters you will need to pass through inputs for
24+
# the other adapters as shown in the below example for redshift
25+
# with:
26+
# # redshift
27+
# REDSHIFT_HOST: ${{ vars.REDSHIFT_HOST }}
28+
# REDSHIFT_USER: ${{ vars.REDSHIFT_USER }}
29+
# REDSHIFT_DATABASE: ${{ vars.REDSHIFT_DATABASE }}
30+
# REDSHIFT_SCHEMA: "integration_tests_redshift_${{ github.run_number }}"
31+
# REDSHIFT_PORT: ${{ vars.REDSHIFT_PORT }}
32+
# secrets:
33+
# DBT_ENV_SECRET_REDSHIFT_PASS: ${{ secrets.DBT_ENV_SECRET_REDSHIFT_PASS }}

integration_tests/.env/postgres.env

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
POSTGRES_HOST=localhost
2+
POSTGRES_USER=root
3+
DBT_ENV_SECRET_POSTGRES_PASS=password
4+
POSTGRES_PORT=5432
5+
POSTGRES_DATABASE=audit_helper_test
6+
POSTGRES_SCHEMA=audit_helper_integration_tests_postgres

integration_tests/ci/sample.profiles.yml integration_tests/profiles.yml

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
2-
# HEY! This file is used in the dbt-audit-helper integrations tests with CircleCI.
3-
# You should __NEVER__ check credentials into version control. Thanks for reading :)
4-
51
integration_tests:
62
target: postgres
73
outputs:
84
postgres:
9-
type: postgres
10-
host: "{{ env_var('POSTGRES_TEST_HOST') }}"
11-
user: "{{ env_var('POSTGRES_TEST_USER') }}"
12-
pass: "{{ env_var('POSTGRES_TEST_PASS') }}"
13-
port: "{{ env_var('POSTGRES_TEST_PORT') | as_number }}"
14-
dbname: "{{ env_var('POSTGRES_TEST_DBNAME') }}"
15-
schema: audit_helper_integration_tests_postgres
16-
threads: 1
5+
type: "postgres"
6+
host: "{{ env_var('POSTGRES_HOST') }}"
7+
user: "{{ env_var('POSTGRES_USER') }}"
8+
pass: "{{ env_var('DBT_ENV_SECRET_POSTGRES_PASS') }}"
9+
port: "{{ env_var('POSTGRES_PORT') | as_number }}"
10+
dbname: "{{ env_var('POSTGRES_DATABASE') }}"
11+
schema: "{{ env_var('POSTGRES_SCHEMA') }}"
12+
threads: 5
1713

1814
redshift:
1915
type: redshift
@@ -51,3 +47,4 @@ integration_tests:
5147
http_path: "{{ env_var('DATABRICKS_TEST_HTTP_PATH') }}"
5248
token: "{{ env_var('DATABRICKS_TEST_ACCESS_TOKEN') }}"
5349
threads: 10
50+

supported_adapters.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SUPPORTED_ADAPTERS=postgres

tox.ini

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[tox]
2+
skipsdist = True
3+
envlist = lint_all, testenv
4+
5+
[testenv]
6+
passenv =
7+
# postgres env vars
8+
POSTGRES_HOST
9+
POSTGRES_USER
10+
DBT_ENV_SECRET_POSTGRES_PASS
11+
POSTGRES_PORT
12+
POSTGRES_DATABASE
13+
POSTGRES_SCHEMA
14+
15+
# Postgres integration tests for centralized dbt testing
16+
# run dbt commands directly, assumes dbt is already installed in environment
17+
[testenv:dbt_integration_postgres]
18+
changedir = integration_tests
19+
allowlist_externals =
20+
dbt
21+
skip_install = true
22+
commands =
23+
dbt --version
24+
dbt debug --target postgres

0 commit comments

Comments
 (0)