From d40d76c181b6bc04daca325fe2c38bcc9cb3357c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 25 May 2019 10:42:23 -0500 Subject: [PATCH] Update and simplify test instructions --- .travis.yml | 12 ++---- README.md | 79 +++++++++------------------------------ travis/before_script.bash | 7 ---- 3 files changed, 21 insertions(+), 77 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84515b0c..01b3febf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,16 +12,12 @@ env: global: - GO111MODULE=on - PGX_TEST_DATABASE=postgres://pgx_md5:secret@127.0.0.1/pgx_test - - PGX_TEST_UNIX_SOCKET_CONN_STRING="host=/var/run/postgresql database=pgx_test" - - PGX_TEST_TCP_CONN_STRING=postgres://pgx_md5:secret@127.0.0.1/pgx_test - - PGX_TEST_TLS_CONN_STRING=postgres://pgx_md5:secret@127.0.0.1/pgx_test?sslmode=require - - PGX_TEST_MD5_PASSWORD_CONN_STRING=postgres://pgx_md5:secret@127.0.0.1/pgx_test - - PGX_TEST_PLAIN_PASSWORD_CONN_STRING=postgres://pgx_pw:secret@127.0.0.1/pgx_test + matrix: - CRATEVERSION=2.1 PGX_TEST_CRATEDB_CONN_STRING="host=127.0.0.1 port=6543 user=pgx database=pgx_test" - - PGVERSION=11 PGX_TEST_REPLICATION_CONN_STRING="host=127.0.0.1 port=6543 user=pgx_replication password=secret database=pgx_test" - - PGVERSION=10 PGX_TEST_REPLICATION_CONN_STRING="host=127.0.0.1 port=6543 user=pgx_replication password=secret database=pgx_test" - - PGVERSION=9.6 PGX_TEST_REPLICATION_CONN_STRING="host=127.0.0.1 port=6543 user=pgx_replication password=secret database=pgx_test" + - PGVERSION=11 + - PGVERSION=10 + - PGVERSION=9.6 - PGVERSION=9.5 - PGVERSION=9.4 diff --git a/README.md b/README.md index 8db2011f..04a723ab 100644 --- a/README.md +++ b/README.md @@ -70,75 +70,30 @@ pgx includes extensive documentation in the godoc format. It is viewable online ## Testing -pgx supports multiple connection and authentication types. Setting up a test -environment that can test all of them can be cumbersome. In particular, -Windows cannot test Unix domain socket connections. Because of this pgx will -skip tests for connection types that are not configured. +pgx tests need a PostgreSQL database. It will connect to the database specified in the `PGX_TEST_DATABASE` environment +variable. The `PGX_TEST_DATABASE` environment variable can be a URL or DSN. In addition, the standard `PG*` environment +variables will be respected. Consider using [direnv](https://github.com/direnv/direnv) to simplify environment variable +handling. -pgx uses environment variables to configure the test database connections. Consider using [direnv](https://github.com/direnv/direnv) to simplify this. +### Example Test Environment -### Normal Test Environment +Connect to your PostgreSQL server and run: -To setup the normal test environment, first install these dependencies: +``` +create database pgx_test; +``` - go get github.com/cockroachdb/apd - go get github.com/hashicorp/go-version - go get github.com/jackc/fake - go get github.com/lib/pq - go get github.com/pkg/errors - go get github.com/satori/go.uuid - go get github.com/shopspring/decimal - go get github.com/sirupsen/logrus - go get go.uber.org/zap - go get gopkg.in/inconshreveable/log15.v2 +Connect to the newly created database and run: -Then run the following SQL: +``` +create domain uint64 as numeric(20,0); +``` - create user pgx_md5 password 'secret'; - create user " tricky, ' } "" \ test user " password 'secret'; - create database pgx_test; +Now you can run the tests: -Connect to database pgx_test and run: - - create extension hstore; - create domain uint64 as numeric(20,0); - -Run the tests with environment variable PGX_TEST_DATABASE set to your test database. - - PGX_TEST_DATABASE="host=/var/run/postgresql database=pgx_test" go test ./... - -### Connection and Authentication Test Environment - -Additional tests are available for specific connection types (e.g. TCP, Unix domain sockets, no password, plain password, MD5 password, etc). - -Complete the normal test environment setup and also do the following. - -Run the following SQL: - - create user pgx_none; - create user pgx_pw password 'secret'; - -Add the following to your pg_hba.conf: - -If you are developing on Unix with domain socket connections: - - local pgx_test pgx_none trust - local pgx_test pgx_pw password - local pgx_test pgx_md5 md5 - -If you are developing on Windows with TCP connections: - - host pgx_test pgx_none 127.0.0.1/32 trust - host pgx_test pgx_pw 127.0.0.1/32 password - host pgx_test pgx_md5 127.0.0.1/32 md5 - -Each different test connection type uses a different connection string in an environment variable. - - export PGX_TEST_UNIX_SOCKET_CONN_STRING="host=/var/run/postgresql database=pgx_test" - export PGX_TEST_TCP_CONN_STRING="host=127.0.0.1 user=pgx_md5 password=secret database=pgx_test" - export PGX_TEST_TLS_CONN_STRING="host=127.0.0.1 user=pgx_md5 password=secret database=pgx_test sslmode=require" - export PGX_TEST_MD5_PASSWORD_CONN_STRING="host=127.0.0.1 user=pgx_md5 password=secret database=pgx_test" - export PGX_TEST_PLAIN_PASSWORD_CONN_STRING="host=127.0.0.1 user=pgx_pw password=secret database=pgx_test" +``` +PGX_TEST_DATABASE="host=/var/run/postgresql database=pgx_test" go test ./... +``` ## Version Policy diff --git a/travis/before_script.bash b/travis/before_script.bash index bcf748a1..74bbbd30 100755 --- a/travis/before_script.bash +++ b/travis/before_script.bash @@ -3,14 +3,7 @@ set -eux if [ "${PGVERSION-}" != "" ] then - # The tricky test user, below, has to actually exist so that it can be used in a test - # of aclitem formatting. It turns out aclitems cannot contain non-existing users/roles. psql -U postgres -c 'create database pgx_test' - psql -U postgres pgx_test -c 'create extension hstore' psql -U postgres pgx_test -c 'create domain uint64 as numeric(20,0)' - psql -U postgres -c "create user pgx_ssl SUPERUSER PASSWORD 'secret'" psql -U postgres -c "create user pgx_md5 SUPERUSER PASSWORD 'secret'" - psql -U postgres -c "create user pgx_pw SUPERUSER PASSWORD 'secret'" - psql -U postgres -c "create user pgx_replication with replication password 'secret'" - psql -U postgres -c "create user \" tricky, ' } \"\" \\ test user \" superuser password 'secret'" fi