From 959d89e043bfba0fd3e16e48483dbd10d25e29fb Mon Sep 17 00:00:00 2001 From: brianc Date: Wed, 7 Jun 2017 22:35:55 -0500 Subject: [PATCH] Add test for connectionString property delegation --- index.js | 2 +- test/connection-strings.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/connection-strings.js diff --git a/index.js b/index.js index aec3a1ec..ccad9686 100644 --- a/index.js +++ b/index.js @@ -96,7 +96,7 @@ Pool.prototype._create = function (cb) { client.connect(function (err) { if (err) { this.log('client connection error:', err) - cb(err) + cb(err, client) } else { this.log('client connected') this.emit('connect', client) diff --git a/test/connection-strings.js b/test/connection-strings.js new file mode 100644 index 00000000..cc624a14 --- /dev/null +++ b/test/connection-strings.js @@ -0,0 +1,22 @@ +var expect = require('expect.js') +var describe = require('mocha').describe +var it = require('mocha').it +var Pool = require('../') + +describe('Connection strings', function () { + it('pool delegates connectionString property to client', function () { + var pool = new Pool({ + connectionString: 'postgres://foo:bar@baz:1234/xur' + }) + pool.connect(function (err, client) { + expect(err).to.not.be(undefined) + expect(client).to.not.be(undefined) + expect(client.username).to.equal('foo') + expect(client.password).to.equal('bar') + expect(client.database).to.equal('baz') + expect(client.port).to.equal(1234) + expect(client.database).to.equal('xur') + }) + }) +}) +