1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/lib/options.test.js

72 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-12-01 00:42:14 +01:00
'use strict';
2018-12-17 09:24:49 +01:00
const test = require('ava');
const fs = require('fs');
2016-12-01 00:42:14 +01:00
delete process.env.DATABASE_URL;
test('should require DATABASE_URI', t => {
2016-12-04 14:09:37 +01:00
const { createOptions } = require('./options');
2016-12-01 00:42:14 +01:00
t.throws(() => {
2016-12-04 14:09:37 +01:00
createOptions({});
2016-12-01 00:42:14 +01:00
});
});
test('should set default databaseUrl for development', t => {
2019-05-22 09:29:56 +02:00
delete process.env.NODE_ENV;
2016-12-04 14:09:37 +01:00
process.env.NODE_ENV = 'development';
2016-12-01 00:42:14 +01:00
const { createOptions } = require('./options');
2016-12-04 14:09:37 +01:00
2016-12-01 00:42:14 +01:00
const options = createOptions({});
2017-06-28 10:17:14 +02:00
t.true(
options.databaseUrl ===
'postgres://unleash_user:passord@localhost:5432/unleash?ssl=true'
2017-06-28 10:17:14 +02:00
);
2016-12-01 00:42:14 +01:00
});
2019-05-22 09:29:56 +02:00
test('should use DATABASE_URL from env', t => {
const databaseUrl = 'postgres://u:p@localhost:5432/name';
delete process.env.NODE_ENV;
process.env.DATABASE_URL = databaseUrl;
const { createOptions } = require('./options');
const options = createOptions({});
t.true(options.databaseUrl === databaseUrl);
});
test('should use DATABASE_URL_FILE from env', t => {
const databaseUrl = 'postgres://u:p@localhost:5432/name';
const path = '/tmp/db_url';
fs.writeFileSync(path, databaseUrl, { mode: 0o755 });
delete process.env.NODE_ENV;
process.env.DATABASE_URL_FILE = path;
const { createOptions } = require('./options');
const options = createOptions({});
t.true(options.databaseUrl === databaseUrl);
});
2019-05-22 09:29:56 +02:00
test('should use databaseUrl from options', t => {
const databaseUrl = 'postgres://u:p@localhost:5432/name';
const { createOptions } = require('./options');
const options = createOptions({ databaseUrl });
t.true(options.databaseUrl === databaseUrl);
});
2016-12-01 00:42:14 +01:00
test('should not override provided options', t => {
2016-12-04 14:09:37 +01:00
process.env.DATABASE_URL = 'test';
2016-12-01 00:42:14 +01:00
process.env.NODE_ENV = 'production';
const { createOptions } = require('./options');
2016-12-04 14:09:37 +01:00
const options = createOptions({ databaseUrl: 'test', port: 1111 });
2016-12-01 00:42:14 +01:00
2016-12-03 13:45:22 +01:00
t.true(options.databaseUrl === 'test');
2016-12-01 00:42:14 +01:00
t.true(options.port === 1111);
2016-12-04 14:09:37 +01:00
});