mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Start fixing integration tests
This commit is contained in:
parent
96b7fc38a6
commit
2f3d72a28c
@ -39,15 +39,12 @@ var con = new pg.Client({
|
||||
});
|
||||
con.connect();
|
||||
var query = con.query("drop table if exists person");
|
||||
query.on('end', function() {
|
||||
console.log("Dropped table 'person'")
|
||||
});
|
||||
con.query("create table person(id serial, name varchar(10), age integer)").on('end', function(){
|
||||
con.query("create table person(id serial, name varchar(10), age integer)", (err, res) => {
|
||||
console.log("Created table person");
|
||||
console.log("Filling it with people");
|
||||
});
|
||||
})
|
||||
people.map(function(person) {
|
||||
return con.query("insert into person(name, age) values('"+person.name + "', '" + person.age + "')");
|
||||
return con.query(new pg.Query("insert into person(name, age) values('"+person.name + "', '" + person.age + "')"));
|
||||
}).pop().on('end', function(){
|
||||
console.log("Inserted 26 people");
|
||||
con.end();
|
||||
|
||||
@ -35,7 +35,7 @@ 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('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')').on('error', console.log);
|
||||
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) {
|
||||
@ -55,7 +55,7 @@ test('parsing array results', function() {
|
||||
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;
|
||||
@ -142,7 +142,7 @@ test('parsing array results', function() {
|
||||
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;
|
||||
@ -159,7 +159,7 @@ test('parsing array results', function() {
|
||||
pg.end();
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
}))
|
||||
})
|
||||
|
||||
|
||||
@ -1,23 +1,8 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var helper = require('./test-helper');
|
||||
var util = require('util');
|
||||
|
||||
const { pg } = helper
|
||||
|
||||
test('non-query error with callback', function () {
|
||||
var client = new Client({
|
||||
user:'asldkfjsadlfkj'
|
||||
});
|
||||
client.connect(assert.calls(function (err) {
|
||||
assert(err);
|
||||
}));
|
||||
});
|
||||
|
||||
test('non-query error', function() {
|
||||
var client = new Client({
|
||||
user:'asldkfjsadlfkj'
|
||||
});
|
||||
assert.emits(client, 'error');
|
||||
client.connect();
|
||||
});
|
||||
|
||||
var createErorrClient = function() {
|
||||
var client = helper.client();
|
||||
@ -33,7 +18,7 @@ test('error handling', function() {
|
||||
test('within a simple query', function() {
|
||||
var client = createErorrClient();
|
||||
|
||||
var query = client.query("select omfg from yodas_dsflsd where pixistix = 'zoiks!!!'");
|
||||
var query = client.query(new pg.Query("select eeeee from yodas_dsflsd where pixistix = 'zoiks!!!'"));
|
||||
|
||||
assert.emits(query, 'error', function(error) {
|
||||
assert.equal(error.severity, "ERROR");
|
||||
@ -52,17 +37,17 @@ test('error handling', function() {
|
||||
|
||||
var ensureFuture = function(testClient) {
|
||||
test("client can issue more queries successfully", function() {
|
||||
var goodQuery = testClient.query("select age from boom");
|
||||
var goodQuery = testClient.query(new pg.Query("select age from boom"));
|
||||
assert.emits(goodQuery, 'row', function(row) {
|
||||
assert.equal(row.age, 28);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var query = client.query({
|
||||
var query = client.query(new pg.Query({
|
||||
text: "select * from bang where name = $1",
|
||||
values: ['0']
|
||||
});
|
||||
}));
|
||||
|
||||
test("query emits the error", function() {
|
||||
assert.emits(query, 'error', function(err) {
|
||||
@ -72,10 +57,10 @@ test('error handling', function() {
|
||||
|
||||
test("when a query is binding", function() {
|
||||
|
||||
var query = client.query({
|
||||
var query = client.query(new pg.Query({
|
||||
text: 'select * from boom where age = $1',
|
||||
values: ['asldkfjasdf']
|
||||
});
|
||||
}));
|
||||
|
||||
test("query emits the error", function() {
|
||||
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var helper = require('./test-helper');
|
||||
var util = require('util');
|
||||
const { Query } = helper.pg;
|
||||
|
||||
test('error during query execution', function() {
|
||||
var client = new Client(helper.args);
|
||||
client.connect(assert.success(function() {
|
||||
var sleepQuery = 'select pg_sleep(5)';
|
||||
var sleepQuery = new Query('select pg_sleep(5)');
|
||||
var pidColName = 'procpid'
|
||||
var queryColName = 'current_query';
|
||||
helper.versionGTE(client, '9.2.0', assert.success(function(isGreater) {
|
||||
@ -27,13 +28,14 @@ test('error during query execution', function() {
|
||||
client2.connect(assert.success(function() {
|
||||
var killIdleQuery = "SELECT " + pidColName + ", (SELECT pg_terminate_backend(" + pidColName + ")) AS killed FROM pg_stat_activity WHERE " + queryColName + " = $1";
|
||||
client2.query(killIdleQuery, [sleepQuery], assert.calls(function(err, res) {
|
||||
console.log('\nresult', res)
|
||||
assert.ifError(err);
|
||||
assert.equal(res.rows.length, 1);
|
||||
client2.end();
|
||||
assert.emits(client2, 'end');
|
||||
}));
|
||||
}));
|
||||
}, 100)
|
||||
}, 300)
|
||||
}));
|
||||
}));
|
||||
});
|
||||
|
||||
@ -5,7 +5,7 @@ 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[], decimals double precision[])");
|
||||
client.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);
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user