From ee4a65b9237bfe9f5f83be3de26226e8648b5da4 Mon Sep 17 00:00:00 2001 From: brianc Date: Sun, 24 Oct 2010 14:43:25 -0500 Subject: [PATCH] support for 'notice' messages --- lib/connection.js | 4 ++++ test/test-buffers.js | 13 ++++++++++--- test/unit/connection/inbound-parser-tests.js | 9 +++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 0e30af4c..28874850 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -186,6 +186,7 @@ var messageNames = { T: 'rowDescription', D: 'dataRow', E: 'error', + N: 'notice', 1: 'parseComplete', 2: 'bindComplete', A: 'notificationResponse' @@ -321,6 +322,9 @@ p.parseE = function(msg) { return msg; }; +//same thing, different name +p.parseN = p.parseE; + //parses parseComplete p.parse1 = function(msg) { return msg; diff --git a/test/test-buffers.js b/test/test-buffers.js index 184fa55b..e83aca87 100644 --- a/test/test-buffers.js +++ b/test/test-buffers.js @@ -80,15 +80,22 @@ buffers.dataRow = function(columns) { }; buffers.error = function(fields) { + return errorOrNotice(fields).join(true, 'E'); +}; + +buffers.notice = function(fields) { + return errorOrNotice(fields).join(true, 'N'); +}; + +var errorOrNotice = function(fields) { fields = fields || []; var buf = new BufferList(); fields.forEach(function(field) { buf.addChar(field.type); buf.addCString(field.value); }); - buf.add(Buffer([0]));//terminator - return buf.join(true, 'E'); -}; + return buf.add(Buffer([0]));//terminator +} buffers.parseComplete = function() { return new BufferList().join(true, '1'); diff --git a/test/unit/connection/inbound-parser-tests.js b/test/unit/connection/inbound-parser-tests.js index f8d482c4..94865b38 100644 --- a/test/unit/connection/inbound-parser-tests.js +++ b/test/unit/connection/inbound-parser-tests.js @@ -256,6 +256,15 @@ test('Connection', function() { }); + test('notice message', function() { + //this uses the same logic as error message + var buff = buffers.notice([{type: 'C', value: 'code'}]); + testForMessage(buff, { + name: 'notice', + code: 'code' + }); + }); + test('error messages', function() { test('with no fields', function() { var msg = testForMessage(buffers.error(),{