Skip to content

Commit

Permalink
Merge 5.2.x master
Browse files Browse the repository at this point in the history
  • Loading branch information
rbrw committed Aug 17, 2018
2 parents aa2c2ae + 2f7fea3 commit 243865a
Show file tree
Hide file tree
Showing 23 changed files with 742 additions and 247 deletions.
105 changes: 65 additions & 40 deletions .travis.yml
Expand Up @@ -5,63 +5,63 @@ dist: trusty
# based on when the repository testing was enabled.
sudo: required

# The test specifications are all extracted from the PDB_TEST value.

# jdk_switcher is a shell function, so we can't handle it in
# prep-os-essentials-for:
# https://github.com/travis-ci/travis-ci/issues/9927

aliases:
- &pg-ver 9.6
- &run-core-tests |
set -e
jdk="$(ext/travisci/jdk-from-spec "$PDB_TEST")"
if test "$(uname)" = Linux; then jdk_switcher use "$jdk"; fi
ext/travisci/prep-os-essentials-for "$PDB_TEST"
pgbin="$(ext/travisci/pgbin-from-spec "$PDB_TEST")"
ext/bin/boxed-core-tests --pgbin "$pgbin" -- lein test

- &run-integration-tests |
set -e
jdk="$(ext/travisci/jdk-from-spec "$PDB_TEST")"
if test "$(uname)" = Linux; then jdk_switcher use "$jdk"; fi
ext/travisci/prep-os-essentials-for "$PDB_TEST"
pgbin="$(ext/travisci/pgbin-from-spec "$PDB_TEST")"
puppet="$(ext/travisci/prefixed-ref-from-spec "$PDB_TEST" pup-)"
server="$(ext/travisci/prefixed-ref-from-spec "$PDB_TEST" srv-)"
ext/bin/boxed-integration-tests \
--pgbin "$pgbin" \
--puppet "$puppet" \
--server "$server" \
-- lein test :integration

jobs:
include:

# === core tests
- stage: ❧ pdb tests
env: PDB_TEST=core/openjdk8
addons:
postgresql: *pg-ver
services: postgresql
script: jdk_switcher use openjdk8 && ext/travisci/run-core-tests
env: PDB_TEST=core/openjdk8/pg-9.6
script: *run-core-tests

- stage: ❧ pdb tests
env: PDB_TEST=core/oraclejdk8
addons:
postgresql: *pg-ver
services: postgresql
script: jdk_switcher use oraclejdk8 && ext/travisci/run-core-tests
env: PDB_TEST=core/oraclejdk8/pg-9.6
script: *run-core-tests

# === integration tests
- stage: ❧ pdb tests
env: PDB_TEST=int/openjdk8/pup-master/srv-master
addons:
postgresql: *pg-ver
services: postgresql
script: >-
jdk_switcher use openjdk8
&& ext/travisci/run-integration-tests master master
env: PDB_TEST=int/openjdk8/pup-master/srv-master/pg-9.6
script: *run-integration-tests

- stage: ❧ pdb tests
env: PDB_TEST=int/oraclejdk8/pup-master/srv-master
addons:
postgresql: *pg-ver
services: postgresql
script: >-
jdk_switcher use oraclejdk8
&& ext/travisci/run-integration-tests master master
env: PDB_TEST=int/oraclejdk8/pup-master/srv-master/pg-9.6
script: *run-integration-tests

- stage: ❧ pdb tests
env: PDB_TEST=int/openjdk8/pup-5.5.x/srv-5.3.x
addons:
postgresql: *pg-ver
services: postgresql
script: >-
jdk_switcher use openjdk8
&& ext/travisci/run-integration-tests 5.5.x 5.3.x
env: PDB_TEST=int/openjdk8/pup-5.5.x/srv-5.3.x/pg-9.6
script: *run-integration-tests

- stage: ❧ pdb tests
env: PDB_TEST=int/oraclejdk8/pup-5.5.x/srv-5.3.x
addons:
postgresql: *pg-ver
services: postgresql
script: >-
jdk_switcher use oraclejdk8
&& ext/travisci/run-integration-tests 5.5.x 5.3.x
env: PDB_TEST=int/oraclejdk8/pup-5.5.x/srv-5.3.x/pg-9.6
script: *run-integration-tests

# === rspec tests
- stage: ❧ pdb tests
Expand All @@ -72,7 +72,26 @@ jobs:
env: PDB_TEST=rspec/pup-5.5.x
script: ext/travisci/run-rspec-tests 5.5.x

before_install: ext/bin/host-info

# ==== osx

# === core tests
- stage: ❧ pdb tests
env: PDB_TEST=core/openjdk8/pg-9.6
script: *run-core-tests
os: osx

# === integration tests
- stage: ❧ pdb tests
env: PDB_TEST=int/openjdk8/pup-5.5.x/srv-5.3.x/pg-9.6
script: *run-integration-tests
os: osx

# === rspec tests
- stage: ❧ pdb tests
env: PDB_TEST=rspec/pup-5.5.x
script: ext/travisci/run-rspec-tests 5.5.x
os: osx

on_success: ext/travisci/on-success

Expand All @@ -86,3 +105,9 @@ notifications:
/ %{repository} %{branch} <a href="%{compare_url}">%{commit}</a> %{author}
/ <a href="%{build_url}">#%{build_number}</a> %{result} in %{elapsed_time}
format: html

cache:
directories:
- $HOME/.m2
- $HOME/Library/Caches/Homebrew
- vendor/bundle/ruby
103 changes: 82 additions & 21 deletions documentation/CONTRIBUTING.md
Expand Up @@ -55,34 +55,64 @@ top of things.

### Testing

To run the local unit or integration tests, you will need a
[configured PostgreSQL server][configure_postgres], and you will need
to create the test users:
The easiest way to run the tests until you need to do it often is to
use the built-in sandbox harness. Assuming you the PostgreSQL
binaries installed in /usr/lib/posgresql/9.6/bin, then you should be
able to run the core tests like this:

$ createuser -DRSP pdb_test
$ createuser -dRsP pdb_test_admin
$ ext/bin/boxed-core-tests \
--pgbin /usr/lib/posgresql/9.6/bin \
-- lein test

You will also need to set the following environment variables if the
default values aren't appropriate:
Copies of tools like `lein` and `pgbox` may be downloaded and
installed to a temporary directory during the process, if you don't
already have the expected versions.

* `PDB_TEST_DB_HOST` (defaults to localhost)
* `PDB_TEST_DB_PORT` (defaults to 5432)
* `PDB_TEST_DB_USER` (defaults to `pdb_test`)
* `PDB_TEST_DB_PASSWORD` (defaults to `pdb_test`)
* `PDB_TEST_DB_ADMIN` (defaults to `pdb_test_admin`)
* `PDB_TEST_DB_ADMIN_PASSWORD` (defaults to `pdb_test_admin`)
Similarly you should be able to run the integration tests against the
default Puppet and Puppetserver versions like this:

Then you can run the unit tests:
$ ext/bin/boxed-integration-tests \
--pgbin /usr/lib/posgresql/9.6/bin \
-- lein test :integration

$ lein test
You can also select the integration test versions of puppet and
puppetserver with the `--puppet REF` and `--server REF` arguments.

And if you'd like to preserve the temporary test databases on failure, you can
set `PDB_TEST_PRESERVE_DB_ON_FAIL` to true:
The sandboxes are destroyed when the commands finish, but you can
arrange to inspect the environment after a failure like this:

$ PDB_TEST_KEEP_DB_ON_FAIL=true lein test
$ ext/bin/boxed-integration-tests \
--pgbin /usr/lib/posgresql/9.6/bin \
-- bash -c 'lein test || bash'

which will drop you into a shell if anything goes wrong.

If you're running the tests all the time, you might want to set up
your own persistent sandbox instead (`ext/bin/with-pdbbox` does
something similar) so you can run them directly:

$ ext/bin/pdbbox-init \
--sandbox ./test-sandbox \
--pgbin /usr/lib/postgresql-9.6/bin \
--pgport 17961

After that you can start and stop the included database server like
this:

To run the integration tests, you'll need to ensure you have a
suitable version of Ruby and Bundler available, and then run
$ export PDBBOX="$(pwd)/test-sandbox"
$ ext/bin/pdbbox-env pg_ctl start -w
$ ext/bin/pdbbox-env pg_ctl stop

and when the database server is running you can run the tests like
this:

$ export PDBBOX="$(pwd)/test-sandbox"
$ ext/bin/pdbbox-env lein test

Before you can run the integration tests directly, you'll need to
configure the puppet and puppetserver versions you want to use.
Assuming you have suitable versions of Ruby and Bundler available, you
can do this:

$ ext/bin/config-puppet-test-ref
$ ext/bin/config-puppetserver-test-ref
Expand All @@ -100,14 +130,45 @@ distclean` will completely undo the configurations.
After configuration you should be able to run the tests by specifying
the `:integration` selector:

$ lein test :integration
$ export PDBBOX="$(pwd)/test-sandbox"
$ ext/bin/pdbbox-env lein test :integration

You can also run puppetdb itself with the config file included in the
sandbox:

$ export PDBBOX="$(pwd)/test-sandbox"
$ ext/bin/pdbbox-env lein run services \
-c test-sandbox/pdb.ini

To run the local rspec tests (e.g. for the PuppetDB terminus code),
you must have run `config-puppet-test-ref` as described above, and
then from within the `puppet/` directory run:

$ bundle exec rspec spec

If you'd like to preserve the temporary test databases on failure, you can
set `PDB_TEST_PRESERVE_DB_ON_FAIL` to true:

$ PDB_TEST_KEEP_DB_ON_FAIL=true lein test

And finally, you can of course set up and [configure your own
PostgreSQL server][configure_postgres] for testing, but then you'll
need to create the test users:

$ createuser -DRSP pdb_test
$ createuser -dRsP pdb_test_admin

and do the other things that `pdbbox-init` normally handles, like
setting environment variables if the default values aren't
appropriate, etc.:

* `PDB_TEST_DB_HOST` (defaults to localhost)
* `PDB_TEST_DB_PORT` (defaults to 5432)
* `PDB_TEST_DB_USER` (defaults to `pdb_test`)
* `PDB_TEST_DB_PASSWORD` (defaults to `pdb_test`)
* `PDB_TEST_DB_ADMIN` (defaults to `pdb_test_admin`)
* `PDB_TEST_DB_ADMIN_PASSWORD` (defaults to `pdb_test_admin`)

### Cleaning up

Running `lein clean` will clean up the relevant items related to
Expand Down
40 changes: 40 additions & 0 deletions ext/bin/boxed-core-tests
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -uxeo pipefail

usage() { echo 'Usage: $(basename "$0") --pgbin DIR -- CMD ...'; }
misuse() { usage 1>&2; exit 2; }

pgbin=''

while test $# -gt 0; do
case "$1" in
--pgbin)
shift
test $# -gt 0 || misuse
pgbin="$1"
shift
;;
--)
shift
break
;;
*)
misuse
esac
done
cmd=("$@")

test "$pgbin" || misuse

tmpdir="$(mktemp -d "core-test-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
mkdir -p "$tmpdir/local"

ext/bin/require-leiningen default "$tmpdir/local"
ext/bin/require-pgbox default "$tmpdir/local"
export PATH="$tmpdir/local/bin:$PATH"
ext/bin/host-info
ext/bin/with-pdbbox --box "$tmpdir/box" --pgbin "$pgbin" --pgport 34335 \
-- "${cmd[@]}"
63 changes: 63 additions & 0 deletions ext/bin/boxed-integration-tests
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -ueo pipefail

usage() {
echo 'Usage: $(basename "$0") --pgbin DIR --puppet REF --server REF -- CMD ...'
}

misuse() { usage 1>&2; exit 2; }

pup_ref=''
pupsrv_ref=''
pgbin=''

while test $# -gt 0; do
case "$1" in
--pgbin)
shift
test $# -gt 0 || misuse
pgbin="$1"
shift
;;
--puppet)
shift
test $# -gt 0 || misuse
pup_ref="$1"
shift
;;
--server)
shift
test $# -gt 0 || misuse
pupsrv_ref="$1"
shift
;;
--)
shift
break
;;
*)
misuse
esac
done
cmd=("$@")

test "$pup_ref" || misuse
test "$pupsrv_ref" || misuse
test "$pgbin" || misuse

set -x

tmpdir="$(mktemp -d "int-test-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
mkdir -p "$tmpdir/local"

ext/bin/require-leiningen default "$tmpdir/local"
ext/bin/require-pgbox default "$tmpdir/local"
export PATH="$tmpdir/local/bin:$PATH"
ext/bin/host-info
ext/bin/config-puppet-test-ref "$pup_ref"
ext/bin/config-puppetserver-test-ref "$pupsrv_ref"
ext/bin/with-pdbbox --box "$tmpdir/box" --pgbin "$pgbin" --pgport 34335 \
-- "${cmd[@]}"
1 change: 1 addition & 0 deletions ext/bin/config-puppet-test-ref
Expand Up @@ -37,6 +37,7 @@ esac

bundle install --without acceptance --path vendor/bundle
bundle update
bundle info puppet

# Symlink vendor/puppet to the git tree bundler checked out. Use a
# relative path so that moving the pdb tree around won't break things.
Expand Down

0 comments on commit 243865a

Please sign in to comment.