Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/pg/test/integration/client/error-handling-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,11 @@ suite.test('re-using connections results in error callback', (done) => {
})
})

suite.test('re-using connections results in promise rejection', () => {
suite.test('re-using connections results in promise rejection', async () => {
const client = new Client()
return client.connect().then(() => {
return helper.rejection(client.connect()).then((err) => {
assert(err instanceof Error)
return client.end()
})
})
await client.connect()
await assert.rejects(client.connect(), Error)
await client.end()
})

suite.test('using a client after closing it results in error', (done) => {
Expand Down
16 changes: 0 additions & 16 deletions packages/pg/test/suite.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
'use strict'

const async = require('async')
const { deprecate } = require('util')

const deprecatedTestAsync = deprecate(function (name, cb) {
this.test(name, cb)
}, 'Suite#testAsync is deprecated. Use Suite#test instead - it handles promises & async functions just fine.')

class Test {
constructor(name, cb) {
Expand Down Expand Up @@ -75,17 +70,6 @@ class Suite {
const test = new Test(name, cb)
this._queue.push(test)
}

testAsync(name, cb) {
return deprecatedTestAsync.call(this, name, cb)
}
}

process.on('unhandledRejection', (e) => {
setImmediate(() => {
console.error('Unhandled promise rejection')
throw e
})
})

module.exports = Suite
61 changes: 2 additions & 59 deletions packages/pg/test/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ process.on('uncaughtException', function (d) {
} else {
console.log(d)
}
process.exit(-1)
// causes xargs to abort right away
process.exit(255)
})
const expect = function (callback, timeout) {
const executed = false
Expand Down Expand Up @@ -66,12 +67,6 @@ process.on('exit', function () {
console.log('')
})

process.on('uncaughtException', function (err) {
console.error('\n %s', err.stack || err.toString())
// causes xargs to abort right away
process.exit(255)
})

const getTimezoneOffset = Date.prototype.getTimezoneOffset

const setTimezoneOffset = function (minutesOffset) {
Expand All @@ -84,14 +79,6 @@ const resetTimezoneOffset = function () {
Date.prototype.getTimezoneOffset = getTimezoneOffset
}

const rejection = (promise) =>
promise.then(
(value) => {
throw new Error(`Promise resolved when rejection was expected; value: ${sys.inspect(value)}`)
},
(error) => error
)

if (Object.isExtensible(assert)) {
assert.same = function (actual, expected) {
for (const key in expected) {
Expand Down Expand Up @@ -124,49 +111,6 @@ if (Object.isExtensible(assert)) {
})
}

assert.UTCDate = function (actual, year, month, day, hours, min, sec, milisecond) {
const actualYear = actual.getUTCFullYear()
assert.equal(actualYear, year, 'expected year ' + year + ' but got ' + actualYear)

const actualMonth = actual.getUTCMonth()
assert.equal(actualMonth, month, 'expected month ' + month + ' but got ' + actualMonth)

const actualDate = actual.getUTCDate()
assert.equal(actualDate, day, 'expected day ' + day + ' but got ' + actualDate)

const actualHours = actual.getUTCHours()
assert.equal(actualHours, hours, 'expected hours ' + hours + ' but got ' + actualHours)

const actualMin = actual.getUTCMinutes()
assert.equal(actualMin, min, 'expected min ' + min + ' but got ' + actualMin)

const actualSec = actual.getUTCSeconds()
assert.equal(actualSec, sec, 'expected sec ' + sec + ' but got ' + actualSec)

const actualMili = actual.getUTCMilliseconds()
assert.equal(actualMili, milisecond, 'expected milisecond ' + milisecond + ' but got ' + actualMili)
}

const spit = function (actual, expected) {
console.log('')
console.log('actual ' + sys.inspect(actual))
console.log('expect ' + sys.inspect(expected))
console.log('')
}

assert.equalBuffers = function (actual, expected) {
if (actual.length != expected.length) {
spit(actual, expected)
assert.equal(actual.length, expected.length)
}
for (let i = 0; i < actual.length; i++) {
if (actual[i] != expected[i]) {
spit(actual, expected)
}
assert.equal(actual[i], expected[i])
}
}

assert.empty = function (actual) {
assert.lengthIs(actual, 0)
}
Expand Down Expand Up @@ -257,6 +201,5 @@ module.exports = {
Client: Client,
setTimezoneOffset: setTimezoneOffset,
resetTimezoneOffset: resetTimezoneOffset,
rejection: rejection,
createPersonTable: createPersonTable,
}
2 changes: 1 addition & 1 deletion packages/pg/test/unit/client/cleartext-password-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ suite.test('cleartext password auth responds with password', function () {
const packets = client.connection.stream.packets
assert.lengthIs(packets, 1)
const packet = packets[0]
assert.equalBuffers(packet, [0x70, 0, 0, 0, 6, 33, 0])
assert.deepStrictEqual(packet, Buffer.from([0x70, 0, 0, 0, 6, 33, 0]))
})

suite.test('cleartext password auth does not crash with null password using pg-pass', function () {
Expand Down
5 changes: 4 additions & 1 deletion packages/pg/test/unit/client/md5-password-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ test('md5 authentication', async function () {
test('should have correct encrypted data', async function () {
const password = await crypto.postgresMd5PasswordHash(client.user, client.password, salt)
// how do we want to test this?
assert.equalBuffers(client.connection.stream.packets[0], new BufferList().addCString(password).join(true, 'p'))
assert.deepStrictEqual(
client.connection.stream.packets[0],
new BufferList().addCString(password).join(true, 'p')
)
})
})
)
Expand Down
Loading