From 730321dbd4d2ed5174d23c25b17d33d13cb02d40 Mon Sep 17 00:00:00 2001 From: brianc Date: Sun, 3 Oct 2010 00:45:10 -0500 Subject: [PATCH] added connection/disconnection tests --- lib/index.js | 7 ++++++- test/api-tests.js | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/index.js b/lib/index.js index 08c80cdd..23afd65d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,7 @@ var sys = require('sys'); var net = require('net'); var NUL = '\0'; -var chars = ['R','S','K','Z','Q','C','T','D']; +var chars = ['R','S','K','Z','Q','C','T','D','X']; var charBuff = Buffer(chars.join(''),'utf8'); var UTF8 = {}; for(var i = 0; i < charBuff.length; i++){ @@ -51,6 +51,11 @@ Client.prototype.connect = function() { this.con = con; }; +Client.prototype.disconnect = function() { + var terminationBuffer = new Buffer([UTF8.X,0,0,0,4]); + this.con.write(terminationBuffer); +}; + var Parser = function(buffer) { this.offset = 0; this.buffer = buffer; diff --git a/test/api-tests.js b/test/api-tests.js index 33643896..c6092f7f 100644 --- a/test/api-tests.js +++ b/test/api-tests.js @@ -8,9 +8,13 @@ var client = new Client({ database: 'pgjstest' }); client.connect(); - -client.query('create temporary table bang (id integer)'); -client.query('insert into bang(id) VALUES(1)'); -client.query('select * from bang',function(err, results, fields) { - assert.equal(err, null); +client.on('ReadyForQuery', function() { + assert.ok(true, 'Connected'); + client.disconnect(); }); + +// client.query('create temporary table bang (id integer)'); +// client.query('insert into bang(id) VALUES(1)'); +// client.query('select * from bang',function(err, results, fields) { +// assert.equal(err, null); +// });