From 761c74cb95776ef59ee1f58b40a1a5de745d804b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Bj=C3=B6rkevik?= Date: Fri, 20 Sep 2024 09:31:58 +0200 Subject: [PATCH] Added utility shell script to launch PostgreSQL in Docker for use with test suite --- README.md | 25 +++++++++++++ .../init-scripts/pg8000-init.sh | 36 +++++++++++++++++++ .../init-scripts/pg8000-init.sql | 3 ++ postgres_test_server/run-test-server.sh | 16 +++++++++ 4 files changed, 80 insertions(+) create mode 100644 postgres_test_server/init-scripts/pg8000-init.sh create mode 100644 postgres_test_server/init-scripts/pg8000-init.sql create mode 100755 postgres_test_server/run-test-server.sh diff --git a/README.md b/README.md index 9270b31..5af4ada 100644 --- a/README.md +++ b/README.md @@ -2061,6 +2061,21 @@ the easiest to express: - Install [tox](http://testrun.org/tox/latest/): `pip install tox` +The pg8000 test suite requires a PostgreSQL server running on the local host. + +### Running PostgreSQL server using Docker +If you have Docker installed you may use it to fire up a local PostgreSQL server +to run the tests against, using the provided shell script: +```shell +./postgres_test_server/run-test-server.sh +``` +The server will run in the foreground, logging all statements sent to it to the +terminal, until you stop it with Ctrl-C. + +### Manual configuration of PostgreSQL server +If you'd like to configure your PostgreSQL server manually instead of going +with Docker, these are the required steps: + - Enable the PostgreSQL hstore extension by running the SQL command: `create extension hstore;` @@ -2077,8 +2092,18 @@ host all all 127.0.0.1/32 trust - Set password encryption to `scram-sha-256` in `postgresql.conf`: `password_encryption = 'scram-sha-256'` +- Enable SSL in `postgresql.conf`: + `ssl = on` + +- Create a self-signed server certificate for the PostgreSQL server. + +- Make sure there is a PostgreSQL user and a database with the same name as + you logged in user. + - Set the password for the postgres user: `ALTER USER postgresql WITH PASSWORD 'pw';` +### Running the tests + - Run `tox` from the `pg8000` directory: `tox` This will run the tests against the Python version of the virtual environment, on the diff --git a/postgres_test_server/init-scripts/pg8000-init.sh b/postgres_test_server/init-scripts/pg8000-init.sh new file mode 100644 index 0000000..5844045 --- /dev/null +++ b/postgres_test_server/init-scripts/pg8000-init.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +cat > /var/lib/postgresql/data/pg_hba.conf <> /var/lib/postgresql/data/postgresql.conf <