diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..950792d1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,38 @@ +language: go + +go: + - 1.x + - tip + +# Derived from https://github.com/lib/pq/blob/master/.travis.yml +before_install: + - ./travis/before_install.bash + +env: + global: + - 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=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=9.5 + - PGVERSION=9.4 + - PGVERSION=9.3 + +before_script: + - ./travis/before_script.bash + +install: + - ./travis/install.bash + +script: + - ./travis/script.bash + +matrix: + allow_failures: + - go: tip diff --git a/travis/before_install.bash b/travis/before_install.bash new file mode 100755 index 00000000..23c7d9cf --- /dev/null +++ b/travis/before_install.bash @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +set -eux + +if [ "${PGVERSION-}" != "" ] +then + sudo apt-get remove -y --purge postgresql libpq-dev libpq5 postgresql-client-common postgresql-common + sudo rm -rf /var/lib/postgresql + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - + sudo sh -c "echo deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main $PGVERSION >> /etc/apt/sources.list.d/postgresql.list" + sudo apt-get update -qq + sudo apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::="--force-confnew" install postgresql-$PGVERSION postgresql-server-dev-$PGVERSION postgresql-contrib-$PGVERSION + sudo chmod 777 /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "local all postgres trust" > /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "local all all trust" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "host all pgx_md5 127.0.0.1/32 md5" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "host all pgx_pw 127.0.0.1/32 password" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "hostssl all pgx_ssl 127.0.0.1/32 md5" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "host replication pgx_replication 127.0.0.1/32 md5" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf + echo "host pgx_test pgx_replication 127.0.0.1/32 md5" >> /etc/postgresql/$PGVERSION/main/pg_hba.conf + sudo chmod 777 /etc/postgresql/$PGVERSION/main/postgresql.conf + if $(dpkg --compare-versions $PGVERSION ge 9.6) ; then + echo "wal_level='logical'" >> /etc/postgresql/$PGVERSION/main/postgresql.conf + echo "max_wal_senders=5" >> /etc/postgresql/$PGVERSION/main/postgresql.conf + echo "max_replication_slots=5" >> /etc/postgresql/$PGVERSION/main/postgresql.conf + fi + sudo /etc/init.d/postgresql restart +fi + +if [ "${CRATEVERSION-}" != "" ] +then + docker run \ + -p "6543:5432" \ + -d \ + crate:"$CRATEVERSION" \ + crate \ + -Cnetwork.host=0.0.0.0 \ + -Ctransport.host=localhost \ + -Clicense.enterprise=false +fi diff --git a/travis/before_script.bash b/travis/before_script.bash new file mode 100755 index 00000000..bcf748a1 --- /dev/null +++ b/travis/before_script.bash @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +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 diff --git a/travis/install.bash b/travis/install.bash new file mode 100755 index 00000000..63ba875d --- /dev/null +++ b/travis/install.bash @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -eux + +go get -u github.com/cockroachdb/apd +go get -u github.com/shopspring/decimal +go get -u gopkg.in/inconshreveable/log15.v2 +go get -u github.com/jackc/fake +go get -u github.com/lib/pq +go get -u github.com/hashicorp/go-version +go get -u github.com/satori/go.uuid +go get -u github.com/sirupsen/logrus +go get -u github.com/pkg/errors +go get -u go.uber.org/zap +go get -u github.com/rs/zerolog diff --git a/travis/script.bash b/travis/script.bash new file mode 100755 index 00000000..5bf1b77e --- /dev/null +++ b/travis/script.bash @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -eux + +if [ "${PGVERSION-}" != "" ] +then + go test -v -race ./... +elif [ "${CRATEVERSION-}" != "" ] +then + go test -v -race -run 'TestCrateDBConnect' +fi