Skip to content

Commit fbe3edf

Browse files
committed
merge in #216
1 parent f6d8821 commit fbe3edf

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

test/postgresql.initialization.test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,51 @@
44
// License text available at https://opensource.org/licenses/Artistic-2.0
55

66
'use strict';
7+
require('./init');
78

89
var connector = require('..');
910
var DataSource = require('loopback-datasource-juggler').DataSource;
1011
var should = require('should');
11-
var db;
1212

13-
before(function() {
14-
db = getDBConfig();
15-
});
13+
// simple wrapper that uses JSON.parse(JSON.stringify()) as cheap clone
14+
function newConfig(withURL) {
15+
return JSON.parse(JSON.stringify(getDBConfig(withURL)));
16+
}
1617

1718
describe('initialization', function() {
1819
it('honours user-defined pg-pool settings', function() {
19-
var dataSource = new DataSource(connector, {});
20+
var dataSource = new DataSource(connector, newConfig());
2021
var pool = dataSource.connector.pg.pool;
2122
pool._factory.max.should.not.equal(999);
2223

23-
var settings = {max: 999}; // non-default value
24+
var settings = newConfig();
25+
settings.max = 999; // non-default value
2426
var dataSource = new DataSource(connector, settings);
2527
var pool = dataSource.connector.pg.pool;
2628
pool._factory.max.should.equal(999);
2729
});
2830

2931
it('honours user-defined url settings', function() {
30-
var settings = {url: 'postgres://' + db.username + ':' + db.password + '@' +
31-
db.host + ':' + db.port + '/' + db.database};
32+
var settings = newConfig();
3233

33-
var dataSource = new DataSource(connector, {});
34+
var dataSource = new DataSource(connector, settings);
3435
var clientConfig = dataSource.connector.clientConfig;
3536
should.not.exist(clientConfig.connectionString);
3637

38+
settings = newConfig(true);
3739
var dataSource = new DataSource(connector, settings);
3840
var clientConfig = dataSource.connector.clientConfig;
3941
clientConfig.connectionString.should.equal(settings.url);
4042
});
4143

4244
it('honours multiple user-defined settings', function() {
43-
var settings = {url: 'postgres://' + db.username + ':' + db.password + '@' +
44-
db.host + ':' + db.port + '/' + db.database, max: 999};
45+
var urlOnly = {url: newConfig(true).url, max: 999};
4546

46-
var dataSource = new DataSource(connector, settings);
47+
var dataSource = new DataSource(connector, urlOnly);
4748
var pool = dataSource.connector.pg.pool;
4849
pool._factory.max.should.equal(999);
4950

5051
var clientConfig = dataSource.connector.clientConfig;
51-
clientConfig.connectionString.should.equal(settings.url);
52+
clientConfig.connectionString.should.equal(urlOnly.url);
5253
});
5354
});

0 commit comments

Comments
 (0)