Skip to content

Commit 8844e12

Browse files
committed
dockerize tests
1 parent dc578b8 commit 8844e12

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
FROM ubuntu:20.04
3+
4+
RUN apt-get update && apt-get -y install git make python3 python3-pip python3-venv sqlite3 vim virtualenvwrapper wget
5+
6+
RUN mkdir /root/dbt-sqlite
7+
8+
WORKDIR /root/dbt-sqlite
9+
10+
RUN mkdir -p /tmp/dbt-sqlite-tests
11+
12+
RUN cd /tmp/dbt-sqlite-tests && wget https://github.com/nalgeon/sqlean/releases/download/0.12.2/crypto.so
13+
14+
RUN pip install dbt==0.21.1
15+
16+
# NOTE: dbt 0.19.x doesn't work with pytest-dbt-adapter >= 0.5.0; use 0.4.0
17+
# see https://github.com/dbt-labs/dbt-adapter-tests/issues/20
18+
#
19+
# pytest-dbt-adapter 0.6.0 doesn't seem to work with dbt 0.21.1,
20+
# I think it's intended for the forthcoming 1.0.0 dbt release?
21+
RUN pip install pytest-dbt-adapter==0.5.1
22+
23+
ENTRYPOINT ["./run_tests.sh"]

README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -173,33 +173,10 @@ git push --tags
173173

174174
## Running Tests
175175

176-
On Windows, you'll need to make adjustments to the commands below.
177-
178176
```
179-
workon dbt-sqlite-test
180-
181-
pip install dbt==0.20.0
182-
183-
# install adapter test suite
184-
# NOTE: dbt 0.19.x doesn't work with >= 0.5.0; use 0.4.0
185-
# see https://github.com/dbt-labs/dbt-adapter-tests/issues/20
186-
pip install pytest-dbt-adapter==0.5.1
187-
188-
# install dbt-sqlite in development mode
189-
pip install -e .
190-
191-
# this path needs to exist for tests to write database file
192-
mkdir -p /tmp/dbt-sqlite-tests
193-
194-
# adjust paths in test/sqlite.dbtspec before running this
195-
pytest test/sqlite.dbtspec
196-
197-
# remember to test 'dbt docs generate': this isn't covered in test suite
177+
./run_tests_docker.sh
198178
```
199179

200-
Remember to delete the database file referenced in `test/sqlite.dbtspec`
201-
between runs of pytest, otherwise leftover state from failures can mess up subsequent test runs.
202-
203180
## Credits
204181

205182
Inspired by this initial work by stephen1000: https://github.com/stephen1000/dbt_sqlite

run_tests.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
pip install -e .
4+
5+
# Leaving the database file between runs of pytest can mess up subsequent test runs.
6+
# Since this runs in a fresh container each time, it's not an issue.
7+
8+
pytest test/sqlite.dbtspec
9+
10+
####
11+
12+
# dbt-sqlite overrides some stuff pertaining to 'docs generate'
13+
# so exercise it using jaffle_shop repo
14+
15+
cd /tmp
16+
17+
git clone https://github.com/dbt-labs/jaffle_shop.git
18+
19+
cd /tmp/jaffle_shop
20+
21+
mkdir -p /root/.dbt
22+
23+
cat >> /root/.dbt/profiles.yml <<EOF
24+
25+
jaffle_shop:
26+
27+
target: dev
28+
outputs:
29+
dev:
30+
type: sqlite
31+
threads: 1
32+
# database MUST exist in order for macros to work. its value is arbitrary.
33+
database: "database"
34+
schema: 'main'
35+
schemas_and_paths:
36+
main: '/tmp/jaffle_shop/jaffle_shop.db'
37+
schema_directory: '/tmp/jaffle_shop'
38+
extensions:
39+
- "/tmp/dbt-sqlite-tests/crypto.so"
40+
41+
EOF
42+
43+
dbt docs generate

run_tests_docker.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
docker build . -t dbt-sqlite-test
4+
5+
docker run \
6+
--rm \
7+
--name dbt-sqlite-test-container \
8+
-v "$(pwd)":"/root/dbt-sqlite" \
9+
dbt-sqlite-test

0 commit comments

Comments
 (0)