Skip to content

Commit 9c4b328

Browse files
jcolemanjcoleman
authored andcommitted
Add Docker test environment for easy development.
Add a Dockerfile with a Postgres build environment as well as simple scripting to make it easy for contributors to quickly iterate on extension development without needing to configure a build environment. Unfortunately I can't easily add the Docker setup to the Makefile (as it's normally common to do) since the existing Makefile requires the full Postgres extension build environment, which would defeat a lot of the purpose of the Docker environment in the first place.
1 parent 9d2ba5f commit 9c4b328

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM postgres:14
2+
3+
RUN apt-get update \
4+
&& apt-get -y install \
5+
build-essential \
6+
postgresql-server-dev-all \
7+
postgresql-server-dev-14
8+
9+
RUN apt-get update && apt-get -y install postgresql-14-pgtap
10+
11+
COPY build_for_tests.sh /
12+
13+
RUN echo "max_locks_per_transaction = 128" >> /postgresql.conf
14+
15+
# The image docs tell you this isn't recommended, but this is image is only
16+
# intended for locally running the test suite anyway, so it's appropriate
17+
# for ease of use in this case.
18+
ENV POSTGRES_HOST_AUTH_METHOD=trust

build_for_tests.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /bin/bash
2+
3+
set -e
4+
5+
cd /home/pg_partman
6+
7+
make && make install
8+
9+
psql -U postgres -c "DROP DATABASE IF EXISTS partman_test"
10+
psql -U postgres -c "CREATE DATABASE partman_test"
11+
psql -U postgres -d partman_test -c "CREATE EXTENSION pgtap"
12+
psql -U postgres -d partman_test -c "CREATE SCHEMA partman"
13+
psql -U postgres -d partman_test -c "CREATE EXTENSION pg_partman SCHEMA partman"

test/README_test.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ Once that's done, it's best to use the **pg_prove** script that pgTAP comes with
2626

2727
Most tests must be run by a superuser since roles & schemas are created & dropped as part of the test. There is a separate test script for each of the partitioning types. The tests are not required to run pg_partman, so if you don't feel safe doing this you don't need to run the tests. But if you are running into problems and report any issues without a clear explanation of what is wrong, I will ask that you run the test suite so you can try and narrow down where the problem may be. You are free to look through to tests to see exactly what they're doing. All tests in the top level of the test folder are run inside a transaction that is rolled back, so they should not change anything (except jobmon logging as mentioned).
2828

29+
## Docker Environment
30+
31+
If you don't have a build environment setup on your local machine, the project provides a docker container setup for your convenience. As long as Docker is installer, you can use the following commands to run tests:
32+
33+
# Build and start container (must be run in the project root):
34+
docker build -t partman_test_image .
35+
docker run -d --name partman_test -v $(pwd):/home/pg_partman partman_test_image
36+
37+
# Logon to container shell:
38+
docker exec -it partman_test bash
39+
40+
# For each test cycle (on the container shell):
41+
/build_for_tests.sh
42+
pg_prove -ovf -U postgres -d partman_test /home/pg_partman/test/<test_file_path>.sql
43+
44+
# Tear down container:
45+
docker stop partman_test
46+
docker rm partman_test
47+
48+
The Docker container volumizes the project working directory so that any changes to your local copy of the project are reflected immediately on the container. This volumization allows rapid iteration without stopping and starting the container frequently. The [build_for_tests.sh](build_for_tests.sh) script automatically rebuilds the extension, installs it, and creates a fresh database with both pgTAP and the project extension installed.
49+
2950
## Specific Test Types
3051

3152
Tests for the time-custom partition type are in their own folder. The 30second test frequently errors out if run in certain 30 second blocks. Waiting for the next 30 second block and running it again should allow it to pass. Same goes for the 30 second test in the native folder.

0 commit comments

Comments
 (0)