node-postgres/packages/pg/test/unit/test-helper.js
Brian C 50c06f9bc6
Remove test globals (#3264)
* Remove assert from globals

* Remove Client from globals

* Remove global test function

* Remove MemoryStream from globals

* Require assert in SASL integration tests

* Attempt to use a postgres with ssl?

* Use latest image

* Remove connection tests - they test internals that are better covered by testint the client
2024-06-19 13:46:16 -05:00

51 lines
909 B
JavaScript

'use strict'
var EventEmitter = require('events').EventEmitter
var helper = require('../test-helper')
var Connection = require('../../lib/connection')
const { Client } = helper
const MemoryStream = function () {
EventEmitter.call(this)
this.packets = []
}
helper.sys.inherits(MemoryStream, EventEmitter)
var p = MemoryStream.prototype
p.connect = function () {
// NOOP
}
p.setNoDelay = () => {}
p.write = function (packet, cb) {
this.packets.push(packet)
if (cb) {
cb()
}
}
p.end = function () {
p.closed = true
}
p.setKeepAlive = function () {}
p.closed = false
p.writable = true
const createClient = function () {
var stream = new MemoryStream()
var client = new Client({
connection: new Connection({ stream: stream }),
})
client.connect()
return client
}
module.exports = Object.assign({}, helper, {
createClient: createClient,
MemoryStream: MemoryStream,
})