Add client connectionString tests (#1310)

* Remove redundant tests

* Add client connectionString test

Add test to ensure { connectionString } is respected as an argument to the client constructor

* Add test for connection string property

Also fixed some legacy require statements.
This commit is contained in:
Brian C 2017-06-07 22:58:03 -05:00 committed by GitHub
parent 3757ff7300
commit f2b87e02f1
14 changed files with 25 additions and 41 deletions

View File

@ -3,7 +3,6 @@ var util = require('util');
var Pool = require('pg-pool'); var Pool = require('pg-pool');
module.exports = function(Client) { module.exports = function(Client) {
var BoundPool = function(options) { var BoundPool = function(options) {
var config = { Client: Client }; var config = { Client: Client };
for (var key in options) { for (var key in options) {

View File

@ -1,2 +1,2 @@
var helper = require(__dirname + "/test-helper") var helper = require("./test-helper")
helper.testPoolSize(2); helper.testPoolSize(2);

View File

@ -1,4 +1,4 @@
var helper = require(__dirname + '/test-helper') var helper = require('./test-helper')
var called = false; var called = false;
test('disconnects', function() { test('disconnects', function() {

View File

@ -1,6 +1,7 @@
var helper = require(__dirname + '/test-helper') var helper = require('./test-helper')
var called = false; var called = false;
test('disconnects', function() { test('disconnects', function() {
var sink = new helper.Sink(4, function() { var sink = new helper.Sink(4, function() {
called = true; called = true;

View File

@ -1,5 +1,5 @@
var helper = require(__dirname + "/../test-helper"); var helper = require("../test-helper");
var pg = require(__dirname + "/../../../lib"); var pg = require("../../../lib");
//first make pool hold 2 clients //first make pool hold 2 clients
pg.defaults.poolSize = 2; pg.defaults.poolSize = 2;

View File

@ -1,4 +1,4 @@
var helper = require(__dirname + '/test-helper'); var helper = require('./test-helper');
var _ = require('lodash') var _ = require('lodash')
const config = _.extend({ }, helper.config, { idleTimeoutMillis: 50 }) const config = _.extend({ }, helper.config, { idleTimeoutMillis: 50 })

View File

@ -1,2 +1,2 @@
var helper = require(__dirname + "/test-helper") var helper = require("./test-helper")
helper.testPoolSize(40); helper.testPoolSize(40);

View File

@ -1,4 +1,4 @@
var helper = require(__dirname + "/../test-helper") var helper = require("./../test-helper")
var pg = helper.pg var pg = helper.pg
var native = helper.args.native var native = helper.args.native

View File

@ -1,4 +1,4 @@
var helper = require(__dirname + '/test-helper'); var helper = require('./test-helper');
//setup defaults //setup defaults
helper.pg.defaults.user = helper.args.user; helper.pg.defaults.user = helper.args.user;

View File

@ -1,2 +1,2 @@
var helper = require(__dirname + "/test-helper") var helper = require("./test-helper")
helper.testPoolSize(1); helper.testPoolSize(1);

View File

@ -1,5 +1,5 @@
var helper = require(__dirname + "/../test-helper"); var helper = require("../test-helper");
var pg = require(__dirname + "/../../../lib"); var pg = require("../../../lib");
pg.connect(helper.config, assert.success(function(client, done) { pg.connect(helper.config, assert.success(function(client, done) {
assert.equal(Object.keys(pg._pools).length, 1); assert.equal(Object.keys(pg._pools).length, 1);

View File

@ -1,2 +1,2 @@
var helper = require(__dirname + "/test-helper") var helper = require("./test-helper")
helper.testPoolSize(200); helper.testPoolSize(200);

View File

@ -59,6 +59,17 @@ test('client settings', function() {
test('initializing from a config string', function() { test('initializing from a config string', function() {
test('uses connectionString property', function () {
var client = new Client({
connectionString: 'postgres://brian:pass@host1:333/databasename'
})
assert.equal(client.user, 'brian');
assert.equal(client.password, "pass");
assert.equal(client.host, "host1");
assert.equal(client.port, 333);
assert.equal(client.database, "databasename");
})
test('uses the correct values from the config string', function() { test('uses the correct values from the config string', function() {
var client = new Client("postgres://brian:pass@host1:333/databasename") var client = new Client("postgres://brian:pass@host1:333/databasename")
assert.equal(client.user, 'brian'); assert.equal(client.user, 'brian');

View File

@ -1,27 +0,0 @@
require(__dirname + '/test-helper');
/*
* Perhaps duplicate of test named 'initializing from a config string' in
* configuration-tests.js
*/
test("using connection string in client constructor", function() {
var client = new Client("postgres://brian:pw@boom:381/lala");
test("parses user", function() {
assert.equal(client.user,'brian');
});
test("parses password", function() {
assert.equal(client.password, 'pw');
});
test("parses host", function() {
assert.equal(client.host, 'boom');
});
test('parses port', function() {
assert.equal(client.port, 381)
});
test('parses database', function() {
assert.equal(client.database, 'lala')
});
});