Skip to content

Commit

Permalink
test(pg): set fallback when PGUSER is absent
Browse files Browse the repository at this point in the history
  • Loading branch information
Qard committed Oct 19, 2019
1 parent 126da47 commit 86210cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 8 additions & 2 deletions test/instrumentation/modules/pg/_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ exports.reset = reset
exports.loadData = loadData

function reset (cb) {
var client = new Client({ database: 'postgres' })
var client = new Client({
database: 'postgres',
user: process.env.PGUSER || 'postgres'
})

client.connect(function (err) {
if (err) throw err
Expand All @@ -22,7 +25,10 @@ function reset (cb) {
}

function loadData (cb) {
var client = new Client({ database: 'test_elastic_apm' })
var client = new Client({
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
})

client.connect(function (err) {
if (err) throw err
Expand Down
5 changes: 4 additions & 1 deletion test/instrumentation/modules/pg/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ function createClient (cb) {
setup(function () {
knex = Knex({
client: 'pg',
connection: 'postgres:///test_elastic_apm'
connection: {
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
}
})
cb()
})
Expand Down
11 changes: 8 additions & 3 deletions test/instrumentation/modules/pg/pg.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,8 @@ function assertSpan (t, span, sql) {
function createClient (cb) {
setup(function () {
queryable = new pg.Client({
database: 'test_elastic_apm'
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
})
queryable.connect(function (err) {
if (err) throw err
Expand All @@ -513,11 +514,15 @@ function createPool (cb) {
if (semver.satisfies(pgVersion, '<6.0.0')) {
queryable = pg
connector = function connector (cb) {
return pg.connect('postgres:///test_elastic_apm', cb)
return pg.connect({
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
}, cb)
}
} else {
var pool = new pg.Pool({
database: 'test_elastic_apm'
database: 'test_elastic_apm',
user: process.env.PGUSER || 'postgres'
})
queryable = pool
connector = function connector (cb) {
Expand Down

0 comments on commit 86210cc

Please sign in to comment.