Format more tests

This commit is contained in:
Brian M. Carlson 2017-06-13 21:24:44 -05:00 committed by Brian C
parent d615ebee17
commit f12eb0a6fd
5 changed files with 47 additions and 36 deletions

View File

@ -1,6 +1,8 @@
var helper = require('./test-helper');
const suite = new helper.Suite()
test("noData message handling", function() {
suite.test("noData message handling", function() {
var client = helper.client();

View File

@ -1,12 +1,8 @@
var helper = require(__dirname + '/test-helper');
var pg = helper.pg;
var config = helper.config;
const suite = new helper.Suite()
test('can access results when no rows are returned', function() {
if(config.native) {
console.log('maybe fix this?', __filename)
return false
}
suite.test('can access results when no rows are returned', function() {
var checkResult = function(result) {
assert(result.fields, 'should have fields definition');
assert.equal(result.fields.length, 1);
@ -15,7 +11,7 @@ test('can access results when no rows are returned', function() {
pg.end();
};
pg.connect(config, assert.success(function(client, done) {
pg.connect(assert.success(function(client, done) {
const q = new pg.Query('select $1::text as val limit 0', ['hi'])
var query = client.query(q, assert.success(function(result) {
checkResult(result);

View File

@ -1,40 +1,27 @@
var helper = require(__dirname + '/test-helper');
var helper = require('./test-helper');
const suite = new helper.Suite()
test('emits notice message', function() {
//TODO this doesn't work on all versions of postgres
return false;
suite.test('emits notify message', function (done) {
var client = helper.client();
client.query('create temp table boom(id serial, size integer)');
assert.emits(client, 'notice', function(notice) {
assert.ok(notice != null);
//TODO ending connection after notice generates weird errors
process.nextTick(function() {
client.end();
})
});
})
test('emits notify message', function() {
var client = helper.client();
client.query('LISTEN boom', assert.calls(function() {
client.query('LISTEN boom', assert.calls(function () {
var otherClient = helper.client();
otherClient.query('LISTEN boom', assert.calls(function() {
assert.emits(client, 'notification', function(msg) {
var bothEmitted = -1
otherClient.query('LISTEN boom', assert.calls(function () {
assert.emits(client, 'notification', function (msg) {
//make sure PQfreemem doesn't invalidate string pointers
setTimeout(function() {
setTimeout(function () {
assert.equal(msg.channel, 'boom');
assert.ok(msg.payload == 'omg!' /*9.x*/ || msg.payload == '' /*8.x*/, "expected blank payload or correct payload but got " + msg.message)
client.end()
client.end(++bothEmitted ? done : undefined)
}, 100)
});
assert.emits(otherClient, 'notification', function(msg) {
assert.emits(otherClient, 'notification', function (msg) {
assert.equal(msg.channel, 'boom');
otherClient.end();
otherClient.end(++bothEmitted ? done : undefined);
});
client.query("NOTIFY boom, 'omg!'", function(err, q) {
if(err) {
client.query("NOTIFY boom, 'omg!'", function (err, q) {
if (err) {
//notify not supported with payload on 8.x
client.query("NOTIFY boom")
}
@ -43,3 +30,26 @@ test('emits notify message', function() {
}));
})
suite.test('emits notice message', function (done) {
if (helper.args.native) {
return console.error('need to get notice message working on native')
}
//TODO this doesn't work on all versions of postgres
var client = helper.client();
const text = `
DO language plpgsql $$
BEGIN
RAISE NOTICE 'hello, world!';
END
$$;
`
client.query(text, () => {
client.end();
});
assert.emits(client, 'notice', function (notice) {
assert.ok(notice != null);
done();
});
})

View File

@ -1,7 +1,9 @@
var helper = require(__dirname + '/../test-helper');
var helper = require('../test-helper');
var pg = helper.pg;
test('ability to turn on and off parser', function() {
const suite = new helper.Suite()
suite.test('ability to turn on and off parser', function() {
if(helper.args.binary) return false;
pg.connect(helper.config, assert.success(function(client, done) {
pg.defaults.parseInt8 = true;

View File

@ -52,6 +52,7 @@ class Suite {
const tid = setTimeout(() => {
const err = Error(`test: ${test.name} did not complete withint ${test.timeout}ms`)
console.log('\n' + err.stack)
process.exit(-1)
}, test.timeout)