This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
Simplify use of Docker to run postgres for tests #49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ran into a problem with PostGIS again when recently trying to use docker-compose to stand up a postgres container for running tests locally.
This got me interested in finding the simplest possible setup for a postgres container. Since oauth2-server-pg actually doesn't need PostGIS, I was able to completely replace the "docker-compose with custom image" approach with this simple docker run command:
The standard postgres image will use the
POSTGRES_DB
env var for the default database, so no need to create theoauth2_server
db on/after startup.So I created an npm run script for this and wrapped it in a conditional pretest hook, which automates the setup and tear down of the postgres docker container locally, but doesn't get in the way when run by Travis. This means all you need to run tests locally is to have docker installed and then run
npm t
, and it will use a throw-away container for postgres for the duration of the tests.Also added these handy scripts for convenience:
npm run pg-test
: start up the dockerized postgres db and run migrationsnpm run psql
: login to the running postgres container to run some manual queriesnpm run pg-test-down
: destroy the running postgres container