From f155899570f51d700c9f7a89d1ff5f48076b6503 Mon Sep 17 00:00:00 2001 From: jeromew Date: Thu, 28 Jul 2016 20:15:59 +0200 Subject: [PATCH] Add a test for NoticeResponse handling (#51) --- test/copy-to.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/copy-to.js b/test/copy-to.js index bff6d64..0982fc8 100644 --- a/test/copy-to.js +++ b/test/copy-to.js @@ -73,5 +73,37 @@ var testInternalPostgresError = function() { queryClient.end() }) } - testInternalPostgresError() + +var testNoticeResponse = function() { + // we use a special trick to generate a warning + // on the copy stream. + var queryClient = client() + var set = ''; + set += 'SET SESSION client_min_messages = WARNING;' + set += 'SET SESSION standard_conforming_strings = off;' + set += 'SET SESSION escape_string_warning = on;' + queryClient.query(set, function(err, res) { + assert.equal(err, null, 'testNoticeResponse - could not SET parameters') + var runStream = function(callback) { + var txt = "COPY (SELECT '\\\n') TO STDOUT" + var stream = queryClient.query(copy(txt)) + stream.on('data', function(data) { + }) + stream.on('error', callback) + + // make sure stream is pulled from + stream.pipe(concat(callback.bind(null,null))) + } + + runStream(function(err) { + assert.equal(err, null, err) + queryClient.end() + }) + + }) +} + +testNoticeResponse(); + +