mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Start cleaning up tests
This commit is contained in:
parent
3074436236
commit
d615ebee17
@ -28,7 +28,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"async": "0.9.0",
|
||||
"co": "4.6.0",
|
||||
"jshint": "2.5.2",
|
||||
"pg-copy-streams": "0.3.0"
|
||||
},
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
return;
|
||||
var helper = require('./test-helper');
|
||||
var Client = helper.Client;
|
||||
|
||||
var suite = new helper.Suite();
|
||||
|
||||
var conInfo = helper.config;
|
||||
|
||||
function getConInfo(override) {
|
||||
@ -26,34 +27,37 @@ function getAppName(conf, cb) {
|
||||
}));
|
||||
}
|
||||
|
||||
test('No default appliation_name ', function(){
|
||||
suite.test('No default appliation_name ', function(done) {
|
||||
var conf = getConInfo();
|
||||
getAppName(conf, function(res){
|
||||
getAppName({ }, function(res){
|
||||
assert.strictEqual(res, '');
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
test('fallback_application_name is used', function(){
|
||||
suite.test('fallback_application_name is used', function(done) {
|
||||
var fbAppName = 'this is my app';
|
||||
var conf = getConInfo({
|
||||
'fallback_application_name' : fbAppName
|
||||
});
|
||||
getAppName(conf, function(res){
|
||||
assert.strictEqual(res, fbAppName);
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
test('application_name is used', function(){
|
||||
suite.test('application_name is used', function(done) {
|
||||
var appName = 'some wired !@#$% application_name';
|
||||
var conf = getConInfo({
|
||||
'application_name' : appName
|
||||
});
|
||||
getAppName(conf, function(res){
|
||||
assert.strictEqual(res, appName);
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
test('application_name has precedence over fallback_application_name', function(){
|
||||
suite.test('application_name has precedence over fallback_application_name', function(done) {
|
||||
var appName = 'some wired !@#$% application_name';
|
||||
var fbAppName = 'some other strange $$test$$ appname';
|
||||
var conf = getConInfo({
|
||||
@ -62,10 +66,11 @@ test('application_name has precedence over fallback_application_name', function(
|
||||
});
|
||||
getAppName(conf, function(res){
|
||||
assert.strictEqual(res, appName);
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
test('application_name from connection string', function(){
|
||||
suite.test('application_name from connection string', function(done) {
|
||||
var appName = 'my app';
|
||||
var conParams = require(__dirname + '/../../../lib/connection-parameters');
|
||||
var conf;
|
||||
@ -76,6 +81,7 @@ test('application_name from connection string', function(){
|
||||
}
|
||||
getAppName(conf, function(res){
|
||||
assert.strictEqual(res, appName);
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
@ -83,14 +89,12 @@ test('application_name from connection string', function(){
|
||||
|
||||
// TODO: make the test work for native client too
|
||||
if (!helper.args.native) {
|
||||
test('application_name is read from the env', function(){
|
||||
suite.test('application_name is read from the env', function(done) {
|
||||
var appName = process.env.PGAPPNAME = 'testest';
|
||||
var conf = getConInfo({
|
||||
'just some bla' : 'to fool the pool'
|
||||
});
|
||||
getAppName(conf, function(res){
|
||||
getAppName({ }, function(res){
|
||||
delete process.env.PGAPPNAME;
|
||||
assert.strictEqual(res, appName);
|
||||
done()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,166 +1,176 @@
|
||||
var helper = require(__dirname + "/test-helper");
|
||||
var pg = helper.pg;
|
||||
|
||||
test('serializing arrays', function() {
|
||||
pg.connect(helper.config, assert.calls(function(err, client, done) {
|
||||
assert.isNull(err);
|
||||
var suite = new helper.Suite()
|
||||
|
||||
test('nulls', function() {
|
||||
client.query('SELECT $1::text[] as array', [[null]], assert.success(function(result) {
|
||||
var array = result.rows[0].array;
|
||||
assert.lengthIs(array, 1);
|
||||
assert.isNull(array[0]);
|
||||
}));
|
||||
});
|
||||
pg.connect(assert.calls(function(err, client, release) {
|
||||
assert.isNull(err);
|
||||
|
||||
test('elements containing JSON-escaped characters', function() {
|
||||
var param = '\\"\\"';
|
||||
suite.test('nulls', function(done) {
|
||||
client.query('SELECT $1::text[] as array', [[null]], assert.success(function(result) {
|
||||
var array = result.rows[0].array;
|
||||
assert.lengthIs(array, 1);
|
||||
assert.isNull(array[0]);
|
||||
done()
|
||||
}));
|
||||
});
|
||||
|
||||
for (var i = 1; i <= 0x1f; i++) {
|
||||
param += String.fromCharCode(i);
|
||||
}
|
||||
suite.test('elements containing JSON-escaped characters', function(done) {
|
||||
var param = '\\"\\"';
|
||||
|
||||
client.query('SELECT $1::text[] as array', [[param]], assert.success(function(result) {
|
||||
var array = result.rows[0].array;
|
||||
assert.lengthIs(array, 1);
|
||||
assert.equal(array[0], param);
|
||||
}));
|
||||
for (var i = 1; i <= 0x1f; i++) {
|
||||
param += String.fromCharCode(i);
|
||||
}
|
||||
|
||||
client.query('SELECT $1::text[] as array', [[param]], assert.success(function(result) {
|
||||
var array = result.rows[0].array;
|
||||
assert.lengthIs(array, 1);
|
||||
assert.equal(array[0], param);
|
||||
done()
|
||||
}));
|
||||
});
|
||||
|
||||
suite.test('cleanup', () => release())
|
||||
}));
|
||||
|
||||
pg.connect(assert.calls(function (err, client, release) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE why(names text[], numbors integer[])");
|
||||
client.query(new pg.Query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')')).on('error', console.log);
|
||||
suite.test('numbers', function (done) {
|
||||
// client.connection.on('message', console.log)
|
||||
client.query('SELECT numbors FROM why', assert.success(function (result) {
|
||||
assert.lengthIs(result.rows[0].numbors, 3);
|
||||
assert.equal(result.rows[0].numbors[0], 1);
|
||||
assert.equal(result.rows[0].numbors[1], 2);
|
||||
assert.equal(result.rows[0].numbors[2], 3);
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('parses string arrays', function (done) {
|
||||
client.query('SELECT names FROM why', assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0], 'aaron');
|
||||
assert.equal(names[1], 'brian');
|
||||
assert.equal(names[2], "a b c");
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('empty array', function (done) {
|
||||
client.query("SELECT '{}'::text[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 0);
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('element containing comma', function (done) {
|
||||
client.query("SELECT '{\"joe,bob\",jim}'::text[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 2);
|
||||
assert.equal(names[0], 'joe,bob');
|
||||
assert.equal(names[1], 'jim');
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('bracket in quotes', function (done) {
|
||||
client.query("SELECT '{\"{\",\"}\"}'::text[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 2);
|
||||
assert.equal(names[0], '{');
|
||||
assert.equal(names[1], '}');
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('null value', function (done) {
|
||||
client.query("SELECT '{joe,null,bob,\"NULL\"}'::text[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 4);
|
||||
assert.equal(names[0], 'joe');
|
||||
assert.equal(names[1], null);
|
||||
assert.equal(names[2], 'bob');
|
||||
assert.equal(names[3], 'NULL');
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('element containing quote char', function (done) {
|
||||
client.query("SELECT ARRAY['joe''', 'jim', 'bob\"'] AS names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0], 'joe\'');
|
||||
assert.equal(names[1], 'jim');
|
||||
assert.equal(names[2], 'bob"');
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('nested array', function (done) {
|
||||
client.query("SELECT '{{1,joe},{2,bob}}'::text[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 2);
|
||||
|
||||
assert.lengthIs(names[0], 2);
|
||||
assert.equal(names[0][0], '1');
|
||||
assert.equal(names[0][1], 'joe');
|
||||
|
||||
assert.lengthIs(names[1], 2);
|
||||
assert.equal(names[1][0], '2');
|
||||
assert.equal(names[1][1], 'bob');
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('integer array', function (done) {
|
||||
client.query("SELECT '{1,2,3}'::integer[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0], 1);
|
||||
assert.equal(names[1], 2);
|
||||
assert.equal(names[2], 3);
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('integer nested array', function (done) {
|
||||
client.query("SELECT '{{1,100},{2,100},{3,100}}'::integer[] as names", assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0][0], 1);
|
||||
assert.equal(names[0][1], 100);
|
||||
|
||||
assert.equal(names[1][0], 2);
|
||||
assert.equal(names[1][1], 100);
|
||||
|
||||
assert.equal(names[2][0], 3);
|
||||
assert.equal(names[2][1], 100);
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('JS array parameter', function (done) {
|
||||
client.query("SELECT $1::integer[] as names", [[[1, 100], [2, 100], [3, 100]]], assert.success(function (result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0][0], 1);
|
||||
assert.equal(names[0][1], 100);
|
||||
|
||||
assert.equal(names[1][0], 2);
|
||||
assert.equal(names[1][1], 100);
|
||||
|
||||
assert.equal(names[2][0], 3);
|
||||
assert.equal(names[2][1], 100);
|
||||
release();
|
||||
pg.end();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
}))
|
||||
})
|
||||
|
||||
test('parsing array results', function() {
|
||||
pg.connect(helper.config, assert.calls(function(err, client, done) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE why(names text[], numbors integer[])");
|
||||
client.query(new pg.Query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')')).on('error', console.log);
|
||||
test('numbers', function() {
|
||||
// client.connection.on('message', console.log)
|
||||
client.query('SELECT numbors FROM why', assert.success(function(result) {
|
||||
assert.lengthIs(result.rows[0].numbors, 3);
|
||||
assert.equal(result.rows[0].numbors[0], 1);
|
||||
assert.equal(result.rows[0].numbors[1], 2);
|
||||
assert.equal(result.rows[0].numbors[2], 3);
|
||||
}))
|
||||
})
|
||||
|
||||
test('parses string arrays', function() {
|
||||
client.query('SELECT names FROM why', assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0], 'aaron');
|
||||
assert.equal(names[1], 'brian');
|
||||
assert.equal(names[2], "a b c");
|
||||
}))
|
||||
})
|
||||
|
||||
test('empty array', function(){
|
||||
client.query("SELECT '{}'::text[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 0);
|
||||
}))
|
||||
})
|
||||
|
||||
test('element containing comma', function(){
|
||||
client.query("SELECT '{\"joe,bob\",jim}'::text[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 2);
|
||||
assert.equal(names[0], 'joe,bob');
|
||||
assert.equal(names[1], 'jim');
|
||||
}))
|
||||
})
|
||||
|
||||
test('bracket in quotes', function(){
|
||||
client.query("SELECT '{\"{\",\"}\"}'::text[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 2);
|
||||
assert.equal(names[0], '{');
|
||||
assert.equal(names[1], '}');
|
||||
}))
|
||||
})
|
||||
|
||||
test('null value', function(){
|
||||
client.query("SELECT '{joe,null,bob,\"NULL\"}'::text[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 4);
|
||||
assert.equal(names[0], 'joe');
|
||||
assert.equal(names[1], null);
|
||||
assert.equal(names[2], 'bob');
|
||||
assert.equal(names[3], 'NULL');
|
||||
}))
|
||||
})
|
||||
|
||||
test('element containing quote char', function(){
|
||||
client.query("SELECT ARRAY['joe''', 'jim', 'bob\"'] AS names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0], 'joe\'');
|
||||
assert.equal(names[1], 'jim');
|
||||
assert.equal(names[2], 'bob"');
|
||||
}))
|
||||
})
|
||||
|
||||
test('nested array', function(){
|
||||
client.query("SELECT '{{1,joe},{2,bob}}'::text[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 2);
|
||||
|
||||
assert.lengthIs(names[0], 2);
|
||||
assert.equal(names[0][0], '1');
|
||||
assert.equal(names[0][1], 'joe');
|
||||
|
||||
assert.lengthIs(names[1], 2);
|
||||
assert.equal(names[1][0], '2');
|
||||
assert.equal(names[1][1], 'bob');
|
||||
|
||||
}))
|
||||
})
|
||||
|
||||
test('integer array', function(){
|
||||
client.query("SELECT '{1,2,3}'::integer[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0], 1);
|
||||
assert.equal(names[1], 2);
|
||||
assert.equal(names[2], 3);
|
||||
}))
|
||||
})
|
||||
|
||||
test('integer nested array', function(){
|
||||
client.query("SELECT '{{1,100},{2,100},{3,100}}'::integer[] as names", assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0][0], 1);
|
||||
assert.equal(names[0][1], 100);
|
||||
|
||||
assert.equal(names[1][0], 2);
|
||||
assert.equal(names[1][1], 100);
|
||||
|
||||
assert.equal(names[2][0], 3);
|
||||
assert.equal(names[2][1], 100);
|
||||
}))
|
||||
})
|
||||
|
||||
test('JS array parameter', function(){
|
||||
client.query("SELECT $1::integer[] as names", [[[1,100],[2,100],[3,100]]], assert.success(function(result) {
|
||||
var names = result.rows[0].names;
|
||||
assert.lengthIs(names, 3);
|
||||
assert.equal(names[0][0], 1);
|
||||
assert.equal(names[0][1], 100);
|
||||
|
||||
assert.equal(names[1][0], 2);
|
||||
assert.equal(names[1][1], 100);
|
||||
|
||||
assert.equal(names[2][0], 3);
|
||||
assert.equal(names[2][1], 100);
|
||||
done();
|
||||
pg.end();
|
||||
}))
|
||||
})
|
||||
|
||||
}))
|
||||
})
|
||||
}))
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
var helper = require("./test-helper");
|
||||
var Query = helper.pg.Query
|
||||
|
||||
const suite = new helper.Suite();
|
||||
|
||||
/*
|
||||
Test to trigger a bug.
|
||||
|
||||
@ -14,31 +16,40 @@ var big_query_rows_2 = [];
|
||||
var big_query_rows_3 = [];
|
||||
|
||||
// Works
|
||||
test('big simple query 1',function() {
|
||||
suite.test('big simple query 1', function(done) {
|
||||
var client = helper.client();
|
||||
client.query(new Query("select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as bla from person where name = '' or 1 = 1"))
|
||||
.on('row', function(row) { big_query_rows_1.push(row); })
|
||||
.on('error', function(error) { console.log("big simple query 1 error"); console.log(error); });
|
||||
client.on('drain', client.end.bind(client));
|
||||
client.on('drain', () => {
|
||||
client.end()
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
// Works
|
||||
test('big simple query 2',function() {
|
||||
suite.test('big simple query 2', function(done) {
|
||||
var client = helper.client();
|
||||
client.query(new Query("select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as bla from person where name = $1 or 1 = 1",['']))
|
||||
.on('row', function(row) { big_query_rows_2.push(row); })
|
||||
.on('error', function(error) { console.log("big simple query 2 error"); console.log(error); });
|
||||
client.on('drain', client.end.bind(client));
|
||||
client.on('drain', () => {
|
||||
client.end()
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
// Fails most of the time with 'invalid byte sequence for encoding "UTF8": 0xb9' or 'insufficient data left in message'
|
||||
// If test 1 and 2 are commented out it works
|
||||
test('big simple query 3',function() {
|
||||
suite.test('big simple query 3',function(done) {
|
||||
var client = helper.client();
|
||||
client.query(new Query("select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as bla from person where name = $1 or 1 = 1",['']))
|
||||
.on('row', function(row) { big_query_rows_3.push(row); })
|
||||
.on('error', function(error) { console.log("big simple query 3 error"); console.log(error); });
|
||||
client.on('drain', client.end.bind(client));
|
||||
client.on('drain', () => {
|
||||
client.end()
|
||||
done()
|
||||
});
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
@ -59,7 +70,7 @@ var runBigQuery = function(client) {
|
||||
});
|
||||
}
|
||||
|
||||
test('many times', function() {
|
||||
suite.test('many times', function(done) {
|
||||
var client = helper.client();
|
||||
for(var i = 0; i < 20; i++) {
|
||||
runBigQuery(client);
|
||||
@ -67,6 +78,7 @@ test('many times', function() {
|
||||
client.on('drain', function() {
|
||||
client.end();
|
||||
setTimeout(function() {
|
||||
done()
|
||||
//let client disconnect fully
|
||||
}, 100)
|
||||
});
|
||||
|
||||
@ -2,7 +2,7 @@ var helper = require("./test-helper");
|
||||
var Query = helper.pg.Query;
|
||||
|
||||
//before running this test make sure you run the script create-test-tables
|
||||
test("cancellation of a query", function() {
|
||||
new helper.Suite().test("cancellation of a query", function() {
|
||||
|
||||
var client = helper.client();
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var helper = require('./test-helper');
|
||||
var pg = helper.pg;
|
||||
|
||||
var suite = new helper.Suite();
|
||||
|
||||
//clear process.env
|
||||
var realEnv = {};
|
||||
for(var key in process.env) {
|
||||
@ -8,8 +10,8 @@ for(var key in process.env) {
|
||||
if(!key.indexOf('PG')) delete process.env[key];
|
||||
}
|
||||
|
||||
test('default values', function() {
|
||||
assert.same(pg.defaults,{
|
||||
suite.test('default values are used in new clients', function() {
|
||||
assert.same(pg.defaults, {
|
||||
user: process.env.USER,
|
||||
database: process.env.USER,
|
||||
password: null,
|
||||
@ -17,42 +19,37 @@ test('default values', function() {
|
||||
rows: 0,
|
||||
poolSize: 10
|
||||
})
|
||||
test('are used in new clients', function() {
|
||||
var client = new pg.Client();
|
||||
assert.same(client,{
|
||||
user: process.env.USER,
|
||||
database: process.env.USER,
|
||||
password: null,
|
||||
port: 5432
|
||||
})
|
||||
|
||||
var client = new pg.Client();
|
||||
assert.same(client, {
|
||||
user: process.env.USER,
|
||||
database: process.env.USER,
|
||||
password: null,
|
||||
port: 5432
|
||||
})
|
||||
})
|
||||
|
||||
if(!helper.args.native) {
|
||||
test('modified values', function() {
|
||||
pg.defaults.user = 'boom'
|
||||
pg.defaults.password = 'zap'
|
||||
pg.defaults.database = 'pow'
|
||||
pg.defaults.port = 1234
|
||||
pg.defaults.host = 'blam'
|
||||
pg.defaults.rows = 10
|
||||
pg.defaults.poolSize = 0
|
||||
|
||||
test('are passed into created clients', function() {
|
||||
var client = new Client();
|
||||
assert.same(client,{
|
||||
user: 'boom',
|
||||
password: 'zap',
|
||||
database: 'pow',
|
||||
port: 1234,
|
||||
host: 'blam'
|
||||
})
|
||||
})
|
||||
suite.test('modified values are passed to created clients', function() {
|
||||
pg.defaults.user = 'boom'
|
||||
pg.defaults.password = 'zap'
|
||||
pg.defaults.database = 'pow'
|
||||
pg.defaults.port = 1234
|
||||
pg.defaults.host = 'blam'
|
||||
|
||||
var client = new Client();
|
||||
assert.same(client,{
|
||||
user: 'boom',
|
||||
password: 'zap',
|
||||
database: 'pow',
|
||||
port: 1234,
|
||||
host: 'blam'
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
//restore process.env
|
||||
for(var key in realEnv) {
|
||||
process.env[key] = realEnv[key];
|
||||
}
|
||||
suite.test('cleanup', () => {
|
||||
//restore process.env
|
||||
for (var key in realEnv) {
|
||||
process.env[key] = realEnv[key];
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,18 +1,19 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
return console.log('TODO: get this working for non-native client');
|
||||
const helper = require('./test-helper');
|
||||
const Client = helper.pg.Client;
|
||||
const suite = new helper.Suite()
|
||||
|
||||
helper.config.types = {
|
||||
getTypeParser: function() {
|
||||
return function() {
|
||||
return 'okay!'
|
||||
}
|
||||
const client = new Client({
|
||||
types: {
|
||||
getTypeParser: () => () => 'okay!'
|
||||
}
|
||||
};
|
||||
})
|
||||
|
||||
helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
client.query('SELECT NOW() as val', assert.success(function(res) {
|
||||
assert.equal(res.rows[0].val, 'okay!');
|
||||
done();
|
||||
helper.pg.end();
|
||||
}));
|
||||
}));
|
||||
suite.test('custom type parser in client config', (done) => {
|
||||
client.connect()
|
||||
.then(() => {
|
||||
client.query('SELECT NOW() as val', assert.success(function (res) {
|
||||
assert.equal(res.rows[0].val, 'okay!');
|
||||
client.end().then(done);
|
||||
}));
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,17 +1,20 @@
|
||||
var helper = require(__dirname+'/test-helper');
|
||||
var client = helper.client();
|
||||
var helper = require('./test-helper');
|
||||
const suite = new helper.Suite()
|
||||
|
||||
test("empty query message handling", function() {
|
||||
suite.test("empty query message handling", function(done) {
|
||||
const client = helper.client();
|
||||
assert.emits(client, 'drain', function() {
|
||||
client.end();
|
||||
client.end(done);
|
||||
});
|
||||
client.query({text: ""});
|
||||
});
|
||||
|
||||
test('callback supported', assert.calls(function() {
|
||||
suite.test('callback supported', function(done) {
|
||||
const client = helper.client();
|
||||
client.query("", function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.empty(result.rows);
|
||||
client.end(done)
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
var helper = require('./test-helper')
|
||||
|
||||
var client = helper.client(assert.success(function() {
|
||||
client.end(assert.success(function() {
|
||||
}))
|
||||
}))
|
||||
@ -1,39 +0,0 @@
|
||||
return;
|
||||
/**
|
||||
* helper needs to be loaded for the asserts but it alos proloads
|
||||
* client which we don't want here
|
||||
*
|
||||
*/
|
||||
var helper = require(__dirname+"/test-helper")
|
||||
, path = require('path')
|
||||
;
|
||||
|
||||
var paths = {
|
||||
'pg' : path.join(__dirname, '..', '..', '..', 'lib', 'index.js') ,
|
||||
'query_js' : path.join(__dirname, '..', '..', '..', 'lib', 'query.js') ,
|
||||
'query_native' : path.join(__dirname, '..', '..', '..', 'lib', 'native', 'query.js') ,
|
||||
};
|
||||
|
||||
/**
|
||||
* delete the modules we are concerned about from the
|
||||
* module cache, so they get loaded cleanly and the env
|
||||
* var can kick in ...
|
||||
*/
|
||||
function emptyCache(){
|
||||
Object.keys(require.cache).forEach(function(key){
|
||||
delete require.cache[key];
|
||||
});
|
||||
};
|
||||
|
||||
emptyCache();
|
||||
process.env.NODE_PG_FORCE_NATIVE = '1';
|
||||
|
||||
var pg = require( paths.pg );
|
||||
var query_native = require( paths.query_native );
|
||||
var query_js = require( paths.query_js );
|
||||
|
||||
assert.deepEqual(pg.Client.Query, query_native);
|
||||
assert.notDeepEqual(pg.Client.Query, query_js);
|
||||
|
||||
emptyCache();
|
||||
delete process.env.NODE_PG_FORCE_NATIVE
|
||||
@ -1,4 +1,4 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var helper = require('./test-helper');
|
||||
|
||||
helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
var types = require('pg-types');
|
||||
@ -18,5 +18,3 @@ helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
done();
|
||||
}))
|
||||
}));
|
||||
|
||||
//custom type converter
|
||||
|
||||
@ -1,38 +1,26 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var helper = require('./test-helper');
|
||||
var assert = require('assert');
|
||||
//if you want binary support, pull request me!
|
||||
if (helper.config.binary) {
|
||||
console.log('binary mode does not support JSON right now');
|
||||
return;
|
||||
}
|
||||
|
||||
test('can read and write json', function() {
|
||||
helper.pg.connect(helper.config, function(err, client, done) {
|
||||
assert.ifError(err);
|
||||
helper.versionGTE(client, '9.2.0', assert.success(function(jsonSupported) {
|
||||
if(!jsonSupported) {
|
||||
console.log('skip json test on older versions of postgres');
|
||||
done();
|
||||
return helper.pg.end();
|
||||
}
|
||||
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)');
|
||||
var value ={name: 'Brian', age: 250, alive: true, now: new Date()};
|
||||
client.query('INSERT INTO stuff (data) VALUES ($1)', [value]);
|
||||
client.query('SELECT * FROM stuff', assert.success(function(result) {
|
||||
assert.equal(result.rows.length, 1);
|
||||
assert.equal(typeof result.rows[0].data, 'object');
|
||||
var row = result.rows[0].data;
|
||||
assert.strictEqual(row.name, value.name);
|
||||
assert.strictEqual(row.age, value.age);
|
||||
assert.strictEqual(row.alive, value.alive);
|
||||
test('row should have "now" as a date', function() {
|
||||
return false;
|
||||
assert(row.now instanceof Date, 'row.now should be a date instance but is ' + typeof row.now);
|
||||
});
|
||||
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
|
||||
done();
|
||||
helper.pg.end();
|
||||
}));
|
||||
helper.pg.connect(assert.success(function (client, done) {
|
||||
helper.versionGTE(client, '9.2.0', assert.success(function (jsonSupported) {
|
||||
if (!jsonSupported) {
|
||||
console.log('skip json test on older versions of postgres');
|
||||
done();
|
||||
return helper.pg.end();
|
||||
}
|
||||
client.query('CREATE TEMP TABLE stuff(id SERIAL PRIMARY KEY, data JSON)');
|
||||
var value = { name: 'Brian', age: 250, alive: true, now: new Date() };
|
||||
client.query('INSERT INTO stuff (data) VALUES ($1)', [value]);
|
||||
client.query('SELECT * FROM stuff', assert.success(function (result) {
|
||||
assert.equal(result.rows.length, 1);
|
||||
assert.equal(typeof result.rows[0].data, 'object');
|
||||
var row = result.rows[0].data;
|
||||
assert.strictEqual(row.name, value.name);
|
||||
assert.strictEqual(row.age, value.age);
|
||||
assert.strictEqual(row.alive, value.alive);
|
||||
assert.equal(JSON.stringify(row.now), JSON.stringify(value.now));
|
||||
done();
|
||||
helper.pg.end();
|
||||
}));
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
var co = require('co')
|
||||
|
||||
var buffers = require('../../test-buffers')
|
||||
var helper = require('./test-helper')
|
||||
var suite = new helper.Suite()
|
||||
|
||||
var net = require('net')
|
||||
|
||||
@ -77,13 +76,12 @@ var testServer = function (server, cb) {
|
||||
})
|
||||
}
|
||||
|
||||
// test being disconnected after readyForQuery
|
||||
const respondingServer = new Server(buffers.readyForQuery())
|
||||
testServer(respondingServer, function () {
|
||||
process.stdout.write('.')
|
||||
// test being disconnected from a server that never responds
|
||||
const silentServer = new Server()
|
||||
testServer(silentServer, function () {
|
||||
process.stdout.write('.')
|
||||
})
|
||||
suite.test('readyForQuery server', (done) => {
|
||||
const respondingServer = new Server(buffers.readyForQuery())
|
||||
testServer(respondingServer, done)
|
||||
})
|
||||
|
||||
suite.test('silent server', (done) => {
|
||||
const silentServer = new Server()
|
||||
testServer(silentServer, done)
|
||||
})
|
||||
|
||||
@ -2,59 +2,48 @@ var async = require('async')
|
||||
|
||||
var helper = require('./test-helper')
|
||||
var Query = helper.pg.Query
|
||||
var suite = new helper.Suite()
|
||||
|
||||
var testWithoutDomain = function(cb) {
|
||||
test('no domain', function() {
|
||||
suite.test('no domain', function (cb) {
|
||||
assert(!process.domain)
|
||||
helper.pg.connect(assert.success(function (client, done) {
|
||||
assert(!process.domain)
|
||||
helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
assert(!process.domain)
|
||||
done()
|
||||
cb()
|
||||
done()
|
||||
cb()
|
||||
}))
|
||||
})
|
||||
|
||||
suite.test('with domain', function (cb) {
|
||||
assert(!process.domain)
|
||||
var domain = require('domain').create()
|
||||
domain.run(function () {
|
||||
var startingDomain = process.domain
|
||||
assert(startingDomain)
|
||||
helper.pg.connect(helper.config, assert.success(function (client, done) {
|
||||
assert(process.domain, 'no domain exists in connect callback')
|
||||
assert.equal(startingDomain, process.domain, 'domain was lost when checking out a client')
|
||||
var query = client.query('SELECT NOW()', assert.success(function () {
|
||||
assert(process.domain, 'no domain exists in query callback')
|
||||
assert.equal(startingDomain, process.domain, 'domain was lost when checking out a client')
|
||||
done(true)
|
||||
process.domain.exit()
|
||||
cb()
|
||||
}))
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
var testWithDomain = function(cb) {
|
||||
test('with domain', function() {
|
||||
assert(!process.domain)
|
||||
var domain = require('domain').create()
|
||||
domain.run(function() {
|
||||
var startingDomain = process.domain
|
||||
assert(startingDomain)
|
||||
helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
assert(process.domain, 'no domain exists in connect callback')
|
||||
assert.equal(startingDomain, process.domain, 'domain was lost when checking out a client')
|
||||
var query = client.query('SELECT NOW()', assert.success(function() {
|
||||
assert(process.domain, 'no domain exists in query callback')
|
||||
assert.equal(startingDomain, process.domain, 'domain was lost when checking out a client')
|
||||
done(true)
|
||||
process.domain.exit()
|
||||
cb()
|
||||
}))
|
||||
}))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
var testErrorWithDomain = function(cb) {
|
||||
test('error on domain', function() {
|
||||
var domain = require('domain').create()
|
||||
domain.on('error', function() {
|
||||
cb()
|
||||
})
|
||||
domain.run(function() {
|
||||
helper.pg.connect(helper.config, assert.success(function(client, done) {
|
||||
client.query(new Query('SELECT SLDKJFLSKDJF'))
|
||||
client.on('drain', done)
|
||||
}))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async.series([
|
||||
testWithoutDomain,
|
||||
testWithDomain,
|
||||
testErrorWithDomain
|
||||
], function() {
|
||||
helper.pg.end()
|
||||
})
|
||||
|
||||
suite.test('error on domain', function (cb) {
|
||||
var domain = require('domain').create()
|
||||
domain.on('error', function () {
|
||||
cb()
|
||||
})
|
||||
domain.run(function () {
|
||||
helper.pg.connect(helper.config, assert.success(function (client, done) {
|
||||
client.query(new Query('SELECT SLDKJFLSKDJF'))
|
||||
client.on('drain', done)
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
suite.test('cleanup', () => helper.pg.end())
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
var helper = require('../test-helper');
|
||||
var pg = helper.pg;
|
||||
|
||||
test('parsing array results', function () {
|
||||
pg.connect(helper.config, assert.calls(function (err, client, done) {
|
||||
var suite = new helper.Suite()
|
||||
|
||||
suite.test('parsing array decimal results', function (done) {
|
||||
pg.connect(helper.config, assert.calls(function (err, client, release) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE why(names text[], numbors integer[], decimals double precision[])");
|
||||
client.query(new pg.Query('INSERT INTO why(names, numbors, decimals) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\', \'{.1, 0.05, 3.654}\')')).on('error', console.log);
|
||||
test('decimals', function () {
|
||||
client.query('SELECT decimals FROM why', assert.success(function (result) {
|
||||
assert.lengthIs(result.rows[0].decimals, 3);
|
||||
assert.equal(result.rows[0].decimals[0], 0.1);
|
||||
assert.equal(result.rows[0].decimals[1], 0.05);
|
||||
assert.equal(result.rows[0].decimals[2], 3.654);
|
||||
done()
|
||||
pg.end();
|
||||
}))
|
||||
})
|
||||
client.query('SELECT decimals FROM why', assert.success(function (result) {
|
||||
assert.lengthIs(result.rows[0].decimals, 3);
|
||||
assert.equal(result.rows[0].decimals[0], 0.1);
|
||||
assert.equal(result.rows[0].decimals[1], 0.05);
|
||||
assert.equal(result.rows[0].decimals[2], 3.654);
|
||||
release()
|
||||
pg.end();
|
||||
done()
|
||||
}))
|
||||
}))
|
||||
})
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var pg = helper.pg;
|
||||
|
||||
test('parsing array results', function() {
|
||||
new helper.Suite().test('parsing array results', function(cb) {
|
||||
pg.connect(helper.config, assert.success(function(client, done) {
|
||||
client.query('CREATE TEMP TABLE test_table(bar integer, "baz\'s" integer)')
|
||||
client.query('INSERT INTO test_table(bar, "baz\'s") VALUES(1, 1), (2, 2)')
|
||||
@ -10,6 +10,7 @@ test('parsing array results', function() {
|
||||
assert.equal(res.rows[1]["baz's"], 2)
|
||||
done()
|
||||
pg.end()
|
||||
cb()
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
var async = require('async');
|
||||
var helper = require('../test-helper');
|
||||
const suite = new helper.Suite()
|
||||
|
||||
var db = helper.client();
|
||||
|
||||
@ -53,13 +54,14 @@ var steps = [
|
||||
insertDataBar
|
||||
]
|
||||
|
||||
test('test if query fails', function() {
|
||||
suite.test('test if query fails', function(done) {
|
||||
async.series(steps, assert.success(function() {
|
||||
db.end()
|
||||
done()
|
||||
}))
|
||||
})
|
||||
|
||||
test('test if prepare works but bind fails', function() {
|
||||
suite.test('test if prepare works but bind fails', function(done) {
|
||||
var client = helper.client();
|
||||
var q = {
|
||||
text: 'SELECT $1::int as name',
|
||||
@ -71,6 +73,7 @@ test('test if prepare works but bind fails', function() {
|
||||
client.query(q, assert.calls(function(err, res) {
|
||||
assert.ifError(err);
|
||||
client.end();
|
||||
done()
|
||||
}));
|
||||
}));
|
||||
});
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
var helper = require('../test-helper');
|
||||
var assert = require('assert');
|
||||
|
||||
helper.pg.connect(helper.config, function(err, client, done) {
|
||||
helper.pg.connect(function(err, client, done) {
|
||||
if (err) throw err;
|
||||
|
||||
var c = 'CREATE TEMP TABLE posts (body TEXT)';
|
||||
|
||||
@ -4,7 +4,7 @@ var copyFrom = require('pg-copy-streams').from;
|
||||
|
||||
if(helper.args.native) return;
|
||||
|
||||
helper.pg.connect(helper.config, function (err, client, done) {
|
||||
helper.pg.connect(function (err, client, done) {
|
||||
if (err) throw err;
|
||||
|
||||
var c = 'CREATE TEMP TABLE employee (id integer, fname varchar(400), lname varchar(400))';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
var helper = require(__dirname + '/../test-helper');
|
||||
var helper = require('../test-helper');
|
||||
|
||||
helper.pg.connect(helper.config, function(err,client) {
|
||||
helper.pg.connect(function(err,client) {
|
||||
var q = {
|
||||
name: 'This is a super long query name just so I can test that an error message is properly spit out to console.error without throwing an exception or anything',
|
||||
text: 'SELECT NOW()'
|
||||
|
||||
@ -8,7 +8,7 @@ if(helper.args.native) {
|
||||
|
||||
//creates a client from cli parameters
|
||||
helper.client = function(cb) {
|
||||
var client = new Client(helper.config);
|
||||
var client = new Client();
|
||||
client.connect(cb);
|
||||
return client;
|
||||
};
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
var domain = require('domain');
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var Client = require(__dirname + "/../../lib/native");
|
||||
var helper = require("./../test-helper");
|
||||
var Client = require("./../../lib/native");
|
||||
const suite = new helper.Suite()
|
||||
|
||||
test('fires callback with results', function() {
|
||||
suite.test('fires callback with results', function(done) {
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
client.query('SELECT 1 as num', assert.calls(function(err, result) {
|
||||
@ -12,12 +13,12 @@ test('fires callback with results', function() {
|
||||
client.query('SELECT * FROM person WHERE name = $1', ['Brian'], assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.equal(result.rows[0].name, 'Brian');
|
||||
client.end();
|
||||
client.end(done);
|
||||
}))
|
||||
}));
|
||||
})
|
||||
|
||||
test('preserves domain', function() {
|
||||
suite.test('preserves domain', function(done) {
|
||||
var dom = domain.create();
|
||||
|
||||
dom.run(function() {
|
||||
@ -26,7 +27,7 @@ test('preserves domain', function() {
|
||||
client.connect()
|
||||
client.query('select 1', function() {
|
||||
assert.ok(dom === require('domain').active, 'domain is still active');
|
||||
client.end();
|
||||
client.end(done);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
@ -24,11 +24,12 @@ class Test {
|
||||
}
|
||||
if (!this.action.length) {
|
||||
const result = this.action.call(this)
|
||||
if ((result || 0).then) {
|
||||
result
|
||||
.then(() => cb())
|
||||
.catch(err => cb(err || new Error('Unhandled promise rejection')))
|
||||
if (!(result || 0).then) {
|
||||
return cb()
|
||||
}
|
||||
result
|
||||
.then(() => cb())
|
||||
.catch(err => cb(err || new Error('Unhandled promise rejection')))
|
||||
} else {
|
||||
this.action.call(this, cb)
|
||||
}
|
||||
@ -51,7 +52,7 @@ class Suite {
|
||||
|
||||
const tid = setTimeout(() => {
|
||||
const err = Error(`test: ${test.name} did not complete withint ${test.timeout}ms`)
|
||||
cb(err)
|
||||
process.exit(-1)
|
||||
}, test.timeout)
|
||||
|
||||
test.run((err) => {
|
||||
@ -61,13 +62,14 @@ class Suite {
|
||||
process.exit(-1)
|
||||
} else {
|
||||
process.stdout.write('✔\n')
|
||||
cb()
|
||||
}
|
||||
cb(err)
|
||||
})
|
||||
}
|
||||
|
||||
test(name, cb) {
|
||||
this._queue.push(new Test(name, cb))
|
||||
const test = new Test(name, cb)
|
||||
this._queue.push(test)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
//make assert a global...
|
||||
assert = require('assert');
|
||||
process.noDeprecation = true;
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var sys = require('util');
|
||||
var BufferList = require(__dirname+'/buffer-list')
|
||||
|
||||
var Connection = require(__dirname + '/../lib/connection');
|
||||
process.noDeprecation = true;
|
||||
|
||||
Client = require(__dirname + '/../lib').Client;
|
||||
var BufferList = require('./buffer-list')
|
||||
const Suite = require('./suite')
|
||||
const args = require('./cli');
|
||||
|
||||
var Connection = require('./../lib/connection');
|
||||
|
||||
Client = require('./../lib').Client;
|
||||
|
||||
process.on('uncaughtException', function(d) {
|
||||
if ('stack' in d && 'message' in d) {
|
||||
@ -16,6 +20,7 @@ process.on('uncaughtException', function(d) {
|
||||
} else {
|
||||
console.log(d);
|
||||
}
|
||||
process.exit(-1);
|
||||
});
|
||||
|
||||
assert.same = function(actual, expected) {
|
||||
@ -24,7 +29,6 @@ assert.same = function(actual, expected) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
assert.emits = function(item, eventName, callback, message) {
|
||||
var called = false;
|
||||
var id = setTimeout(function() {
|
||||
@ -71,13 +75,6 @@ assert.UTCDate = function(actual, year, month, day, hours, min, sec, milisecond)
|
||||
assert.equal(actualMili, milisecond, "expected milisecond " + milisecond + " but got " + actualMili);
|
||||
};
|
||||
|
||||
var spit = function(actual, expected) {
|
||||
console.log("");
|
||||
console.log("actual " + sys.inspect(actual));
|
||||
console.log("expect " + sys.inspect(expected));
|
||||
console.log("");
|
||||
}
|
||||
|
||||
assert.equalBuffers = function(actual, expected) {
|
||||
if(actual.length != expected.length) {
|
||||
spit(actual, expected)
|
||||
@ -171,6 +168,12 @@ assert.isNull = function(item, message) {
|
||||
assert.ok(item === null, message);
|
||||
};
|
||||
|
||||
const getMode = () => {
|
||||
if (args.native) return 'native'
|
||||
if (args.binary) return 'binary'
|
||||
return ''
|
||||
}
|
||||
|
||||
test = function(name, action) {
|
||||
test.testCount ++;
|
||||
test[name] = action;
|
||||
@ -184,7 +187,6 @@ test = function(name, action) {
|
||||
|
||||
//print out the filename
|
||||
process.stdout.write(require('path').basename(process.argv[1]));
|
||||
var args = require(__dirname + '/cli');
|
||||
if(args.binary) process.stdout.write(' (binary)');
|
||||
if(args.native) process.stdout.write(' (native)');
|
||||
|
||||
@ -240,8 +242,8 @@ var resetTimezoneOffset = function() {
|
||||
|
||||
module.exports = {
|
||||
Sink: Sink,
|
||||
Suite: require('./suite'),
|
||||
pg: require(__dirname + '/../lib/'),
|
||||
Suite: Suite,
|
||||
pg: require('./../lib/'),
|
||||
args: args,
|
||||
config: args,
|
||||
sys: sys,
|
||||
|
||||
@ -4,20 +4,13 @@ var pg = require('../../..//lib/index.js');
|
||||
|
||||
/* console.log() messages show up in `make test` output. TODO: fix it. */
|
||||
var server = net.createServer(function(c) {
|
||||
console.log('server connected');
|
||||
c.destroy();
|
||||
console.log('server socket destroyed.');
|
||||
server.close(function() { console.log('server closed'); });
|
||||
server.close();
|
||||
});
|
||||
|
||||
server.listen(7777, function() {
|
||||
console.log('server listening');
|
||||
var client = new pg.Client('postgres://localhost:7777');
|
||||
console.log('client connecting');
|
||||
client.connect(assert.calls(function(err) {
|
||||
if (err) console.log("Error on connect: "+err);
|
||||
else console.log('client connected');
|
||||
assert(err);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user