|
| 1 | +'use strict' |
| 2 | +var helper = require('../test-helper') |
| 3 | +var Client = require('../../lib/native') |
| 4 | +const suite = new helper.Suite() |
| 5 | + |
| 6 | +suite.test('respects nativeConnectionString in config', function (done) { |
| 7 | + const realPort = helper.config.port |
| 8 | + const nativeConnectionString = `host=${helper.config.host} port=${helper.config.port} dbname=${helper.config.database} user=${helper.config.user} password=${helper.config.password}` |
| 9 | + |
| 10 | + // setting wrong port to make sure config is take from nativeConnectionString and not env |
| 11 | + helper.config.port = '90929' |
| 12 | + |
| 13 | + var client = new Client({ |
| 14 | + ...helper.config, |
| 15 | + nativeConnectionString, |
| 16 | + }) |
| 17 | + |
| 18 | + client.connect(function (err) { |
| 19 | + assert(!err) |
| 20 | + client.query( |
| 21 | + 'SELECT 1 as num', |
| 22 | + assert.calls(function (err, result) { |
| 23 | + assert(!err) |
| 24 | + assert.equal(result.rows[0].num, 1) |
| 25 | + assert.strictEqual(result.rowCount, 1) |
| 26 | + // restore post in case helper config will be reused |
| 27 | + helper.config.port = realPort |
| 28 | + client.end(done) |
| 29 | + }) |
| 30 | + ) |
| 31 | + }) |
| 32 | +}) |
| 33 | + |
| 34 | +suite.test('respects nativeConnectionString in config even when it is corrupted', function (done) { |
| 35 | + const nativeConnectionString = `foobar` |
| 36 | + |
| 37 | + var client = new Client({ |
| 38 | + nativeConnectionString, |
| 39 | + }) |
| 40 | + |
| 41 | + client.connect(function (err) { |
| 42 | + assert(err) |
| 43 | + assert.equal( |
| 44 | + err.message, |
| 45 | + 'missing "=" after "foobar" in connection info string\n', |
| 46 | + 'Connection error should have been thrown' |
| 47 | + ) |
| 48 | + client.end(done) |
| 49 | + }) |
| 50 | +}) |
0 commit comments