mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Use TEST_DATABASE_URL for running test against a separate DB.
This commit is contained in:
parent
1aca1aac15
commit
f999388e03
@ -1,7 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
env: DATABASE_URL=postgres://postgres@localhost:5432/unleash_test
|
||||
env: TEST_DATABASE_URL=postgres://postgres@localhost:5432/unleash_test
|
||||
before_script:
|
||||
- echo '--timeout 10000' > test/mocha.opts
|
||||
- psql -c 'create database unleash_test;' -U postgres
|
||||
|
13
README.md
13
README.md
@ -13,19 +13,22 @@ Known client implementations:
|
||||
|
||||
## Development
|
||||
|
||||
### Create a local unleash-db on postgres
|
||||
### Create a local unleash databases in postgres
|
||||
|
||||
```bash
|
||||
$ psql postgres <<SQL
|
||||
CREATE USER unleash_user WITH PASSWORD 'passord';
|
||||
CREATE DATABASE unleash;
|
||||
GRANT ALL PRIVILEGES ON DATABASE unleash to unleash_user;
|
||||
CREATE DATABASE unleash_test;
|
||||
GRANT ALL PRIVILEGES ON DATABASE unleash_test to unleash_user;
|
||||
SQL
|
||||
```
|
||||
|
||||
Then set DATABASE_URI env var:
|
||||
Then set env vars:
|
||||
```
|
||||
export DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash
|
||||
export TEST_DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash_test
|
||||
```
|
||||
|
||||
### Commands
|
||||
@ -34,10 +37,13 @@ export DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash
|
||||
// Install dependencies
|
||||
npm install
|
||||
|
||||
// Make sure DATABASE_URL is set and run migrations in your local DB
|
||||
// Run migrations in your local DBs
|
||||
export DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash
|
||||
./node_modules/.bin/db-migrate up
|
||||
|
||||
export TEST_DATABASE_URL=postgres://unleash_user:passord@localhost:5432/unleash
|
||||
./node_modules/.bin/db-migrate up
|
||||
|
||||
// Start server in dev-mode:
|
||||
npm run dev
|
||||
|
||||
@ -50,7 +56,6 @@ http://localhost:4242/features
|
||||
// Execute tests:
|
||||
npm test
|
||||
|
||||
|
||||
// Run tests with postgres running in docker:
|
||||
npm run docker-test
|
||||
```
|
||||
|
@ -4,18 +4,35 @@ var fs = require('fs');
|
||||
var ini = require('ini');
|
||||
var knex = require('knex');
|
||||
|
||||
function isTestEnv() {
|
||||
return process.env.NODE_ENV === 'test';
|
||||
}
|
||||
|
||||
function getDatabaseIniUrl() {
|
||||
// Finn specific way of delivering env variables
|
||||
var databaseini = nconf.argv().get('databaseini');
|
||||
var config = ini.parse(fs.readFileSync(databaseini, 'utf-8'));
|
||||
|
||||
logger.info('unleash started with databaseini: ' + databaseini);
|
||||
|
||||
return config.DATABASE_URL;
|
||||
}
|
||||
|
||||
function getTestDatabaseUrl() {
|
||||
if (process.env.TEST_DATABASE_URL) {
|
||||
logger.info('unleash started with TEST_DATABASE_URL');
|
||||
return process.env.TEST_DATABASE_URL;
|
||||
} else {
|
||||
throw new Error('please set TEST_DATABASE_URL');
|
||||
}
|
||||
}
|
||||
|
||||
function getDatabaseUrl() {
|
||||
if (process.env.DATABASE_URL) {
|
||||
logger.info('unleash started with DATABASE_URL');
|
||||
|
||||
return process.env.DATABASE_URL;
|
||||
} else if (nconf.argv().get('databaseini') !== undefined) {
|
||||
// Finn specific way of delivering env variables
|
||||
var databaseini = nconf.argv().get('databaseini');
|
||||
logger.info('unleash started with databaseini: ' + databaseini);
|
||||
var config = ini.parse(fs.readFileSync(databaseini, 'utf-8'));
|
||||
|
||||
return config.DATABASE_URL;
|
||||
return getDatabaseIniUrl();
|
||||
}
|
||||
|
||||
throw new Error('please set DATABASE_URL or pass --databaseini');
|
||||
@ -24,7 +41,7 @@ function getDatabaseUrl() {
|
||||
function createDbPool() {
|
||||
return knex({
|
||||
client: 'pg',
|
||||
connection: getDatabaseUrl(),
|
||||
connection: isTestEnv() ? getTestDatabaseUrl() : getDatabaseUrl(),
|
||||
pool: {min: 2, max: 20}
|
||||
});
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ function destroyFeatures() {
|
||||
}
|
||||
|
||||
function resetDatabase() {
|
||||
return Promise.all([destroyStrategies(), destroyFeatures()]).then(function (values) { console.log(values); });
|
||||
return Promise.all([destroyStrategies(), destroyFeatures()]);
|
||||
}
|
||||
|
||||
function setupDatabase() {
|
||||
|
Loading…
Reference in New Issue
Block a user