Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
chore: simplify use of docker to run postgres for tests (#49)
Browse files Browse the repository at this point in the history
* chore: use docker for postgres by default

 replace compose and custom image  with simple run command

* use postgres 9.4 in travis

* test against node 4, which npm uses in production

* npm run release instead of npm run version

* more useful npm run scripts

* add notes about Docker and Postgres to README [skip ci]
  • Loading branch information
nexdrew committed Oct 5, 2016
1 parent d6ee89c commit d355481
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 614 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
sudo: false
language: node_js
services:
- postgres
addons:
postgresql: "9.4"
node_js:
- "5"
- "4"
before_script:
- psql -c 'create database oauth2_server;' -U postgres
after_success: npm run coverage
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ POST /client
POST /client/:client_id/token
```

## Development and Testing

For convenience, this project can leverage Docker to run Postgres for you. If you have Docker installed (and the daemon running), then a Postgres db will automatically be created and destroyed when running tests via `npm test`. If you _don't_ have Docker installed, you will need to run Postgres manually before testing.

When developing and testing locally (outside of just running `npm t`) with Docker installed, you can use the following npm run scripts for convenience:

- `npm run pg-test`: Initialize a Postgres db within a Docker container and leave it running
- `npm run psql`: Login to the running Postgres container to run some manual queries
- `npm run pg-test-down`: Destroy the running Postgres container

## License

ISC
14 changes: 0 additions & 14 deletions docker-compose.yml

This file was deleted.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
"main": "./lib/server.js",
"bin": "./bin/oauth2-server-pg.js",
"scripts": {
"pretest": "standard",
"pretest": "standard; if pgrep \"docker\" > /dev/null; then (npm run pg-test-down || true) && npm run pg-test-up; sleep 5; fi",
"test": "nyc mocha --timeout=5000 test/*.js",
"posttest": "if pgrep \"docker\" > /dev/null; then npm run pg-test-down; fi",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"migrate-test": "db-migrate --config=./config-test.json --env=connection",
"pg-test-up": "docker run --name oauth2serverpg_postgres_1 -e POSTGRES_DB=oauth2_server -p 5432:5432/tcp -d postgres:9.4 postgres",
"pg-test-down": "docker rm -f oauth2serverpg_postgres_1",
"pg-test": "npm run pg-test-up; sleep 5; npm run migrate-test",
"migrate-test": "db-migrate --config=./config-test.json --env=connection up",
"psql": "docker exec -it oauth2serverpg_postgres_1 psql -U postgres -d oauth2_server",
"migrate": "db-migrate --config=./config.json --env=connection",
"version": "standard-version"
"release": "standard-version"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -58,4 +63,4 @@
"**/test/**"
]
}
}
}
16 changes: 0 additions & 16 deletions roles/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions roles/postgres/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions roles/postgres/initdb.sh

This file was deleted.

0 comments on commit d355481

Please sign in to comment.