forked from brianc/node-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-helper.js
43 lines (34 loc) · 815 Bytes
/
test-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict'
var EventEmitter = require('events').EventEmitter
var helper = require('../test-helper')
var Connection = require('../../lib/connection')
global.MemoryStream = function () {
EventEmitter.call(this)
this.packets = []
}
helper.sys.inherits(MemoryStream, EventEmitter)
var p = MemoryStream.prototype
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()
stream.readyState = 'open'
var client = new Client({
connection: new Connection({stream: stream})
})
client.connect()
return client
}
module.exports = Object.assign({}, helper, {
createClient: createClient
})