-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add connection parameter nativeConnectionString (#2941)
Co-authored-by: Evgeniy Novikov <e.p.novikov@tinkoff.ru>
- Loading branch information
1 parent
c38ecf3
commit dee3ae5
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict' | ||
var helper = require('../test-helper') | ||
var Client = require('../../lib/native') | ||
const suite = new helper.Suite() | ||
|
||
suite.test('respects nativeConnectionString in config', function (done) { | ||
const realPort = helper.config.port | ||
const nativeConnectionString = `host=${helper.config.host} port=${helper.config.port} dbname=${helper.config.database} user=${helper.config.user} password=${helper.config.password}` | ||
|
||
// setting wrong port to make sure config is take from nativeConnectionString and not env | ||
helper.config.port = '90929' | ||
|
||
var client = new Client({ | ||
...helper.config, | ||
nativeConnectionString, | ||
}) | ||
|
||
client.connect(function (err) { | ||
assert(!err) | ||
client.query( | ||
'SELECT 1 as num', | ||
assert.calls(function (err, result) { | ||
assert(!err) | ||
assert.equal(result.rows[0].num, 1) | ||
assert.strictEqual(result.rowCount, 1) | ||
// restore post in case helper config will be reused | ||
helper.config.port = realPort | ||
client.end(done) | ||
}) | ||
) | ||
}) | ||
}) | ||
|
||
suite.test('respects nativeConnectionString in config even when it is corrupted', function (done) { | ||
const nativeConnectionString = `foobar` | ||
|
||
var client = new Client({ | ||
nativeConnectionString, | ||
}) | ||
|
||
client.connect(function (err) { | ||
assert(err) | ||
assert.equal( | ||
err.message, | ||
'missing "=" after "foobar" in connection info string\n', | ||
'Connection error should have been thrown' | ||
) | ||
client.end(done) | ||
}) | ||
}) |