Skip to content

Commit 2f3d72a

Browse files
committed
Start fixing integration tests
1 parent 96b7fc3 commit 2f3d72a

File tree

5 files changed

+21
-37
lines changed

5 files changed

+21
-37
lines changed

script/create-test-tables.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,12 @@ var con = new pg.Client({
3939
});
4040
con.connect();
4141
var query = con.query("drop table if exists person");
42-
query.on('end', function() {
43-
console.log("Dropped table 'person'")
44-
});
45-
con.query("create table person(id serial, name varchar(10), age integer)").on('end', function(){
42+
con.query("create table person(id serial, name varchar(10), age integer)", (err, res) => {
4643
console.log("Created table person");
4744
console.log("Filling it with people");
48-
});
45+
})
4946
people.map(function(person) {
50-
return con.query("insert into person(name, age) values('"+person.name + "', '" + person.age + "')");
47+
return con.query(new pg.Query("insert into person(name, age) values('"+person.name + "', '" + person.age + "')"));
5148
}).pop().on('end', function(){
5249
console.log("Inserted 26 people");
5350
con.end();

test/integration/client/array-tests.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('parsing array results', function() {
3535
pg.connect(helper.config, assert.calls(function(err, client, done) {
3636
assert.isNull(err);
3737
client.query("CREATE TEMP TABLE why(names text[], numbors integer[])");
38-
client.query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')').on('error', console.log);
38+
client.query(new pg.Query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')')).on('error', console.log);
3939
test('numbers', function() {
4040
// client.connection.on('message', console.log)
4141
client.query('SELECT numbors FROM why', assert.success(function(result) {
@@ -55,7 +55,7 @@ test('parsing array results', function() {
5555
assert.equal(names[2], "a b c");
5656
}))
5757
})
58-
58+
5959
test('empty array', function(){
6060
client.query("SELECT '{}'::text[] as names", assert.success(function(result) {
6161
var names = result.rows[0].names;
@@ -142,7 +142,7 @@ test('parsing array results', function() {
142142
assert.equal(names[2][1], 100);
143143
}))
144144
})
145-
145+
146146
test('JS array parameter', function(){
147147
client.query("SELECT $1::integer[] as names", [[[1,100],[2,100],[3,100]]], assert.success(function(result) {
148148
var names = result.rows[0].names;
@@ -159,7 +159,7 @@ test('parsing array results', function() {
159159
pg.end();
160160
}))
161161
})
162-
162+
163163
}))
164164
})
165165

test/integration/client/error-handling-tests.js

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
var helper = require(__dirname + '/test-helper');
1+
var helper = require('./test-helper');
22
var util = require('util');
33

4+
const { pg } = helper
45

5-
test('non-query error with callback', function () {
6-
var client = new Client({
7-
user:'asldkfjsadlfkj'
8-
});
9-
client.connect(assert.calls(function (err) {
10-
assert(err);
11-
}));
12-
});
13-
14-
test('non-query error', function() {
15-
var client = new Client({
16-
user:'asldkfjsadlfkj'
17-
});
18-
assert.emits(client, 'error');
19-
client.connect();
20-
});
216

227
var createErorrClient = function() {
238
var client = helper.client();
@@ -33,7 +18,7 @@ test('error handling', function() {
3318
test('within a simple query', function() {
3419
var client = createErorrClient();
3520

36-
var query = client.query("select omfg from yodas_dsflsd where pixistix = 'zoiks!!!'");
21+
var query = client.query(new pg.Query("select eeeee from yodas_dsflsd where pixistix = 'zoiks!!!'"));
3722

3823
assert.emits(query, 'error', function(error) {
3924
assert.equal(error.severity, "ERROR");
@@ -52,17 +37,17 @@ test('error handling', function() {
5237

5338
var ensureFuture = function(testClient) {
5439
test("client can issue more queries successfully", function() {
55-
var goodQuery = testClient.query("select age from boom");
40+
var goodQuery = testClient.query(new pg.Query("select age from boom"));
5641
assert.emits(goodQuery, 'row', function(row) {
5742
assert.equal(row.age, 28);
5843
});
5944
});
6045
};
6146

62-
var query = client.query({
47+
var query = client.query(new pg.Query({
6348
text: "select * from bang where name = $1",
6449
values: ['0']
65-
});
50+
}));
6651

6752
test("query emits the error", function() {
6853
assert.emits(query, 'error', function(err) {
@@ -72,10 +57,10 @@ test('error handling', function() {
7257

7358
test("when a query is binding", function() {
7459

75-
var query = client.query({
60+
var query = client.query(new pg.Query({
7661
text: 'select * from boom where age = $1',
7762
values: ['asldkfjasdf']
78-
});
63+
}));
7964

8065
test("query emits the error", function() {
8166

test/integration/client/query-error-handling-tests.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
var helper = require(__dirname + '/test-helper');
1+
var helper = require('./test-helper');
22
var util = require('util');
3+
const { Query } = helper.pg;
34

45
test('error during query execution', function() {
56
var client = new Client(helper.args);
67
client.connect(assert.success(function() {
7-
var sleepQuery = 'select pg_sleep(5)';
8+
var sleepQuery = new Query('select pg_sleep(5)');
89
var pidColName = 'procpid'
910
var queryColName = 'current_query';
1011
helper.versionGTE(client, '9.2.0', assert.success(function(isGreater) {
@@ -27,13 +28,14 @@ test('error during query execution', function() {
2728
client2.connect(assert.success(function() {
2829
var killIdleQuery = "SELECT " + pidColName + ", (SELECT pg_terminate_backend(" + pidColName + ")) AS killed FROM pg_stat_activity WHERE " + queryColName + " = $1";
2930
client2.query(killIdleQuery, [sleepQuery], assert.calls(function(err, res) {
31+
console.log('\nresult', res)
3032
assert.ifError(err);
3133
assert.equal(res.rows.length, 1);
3234
client2.end();
3335
assert.emits(client2, 'end');
3436
}));
3537
}));
36-
}, 100)
38+
}, 300)
3739
}));
3840
}));
3941
});

test/integration/gh-issues/131-tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('parsing array results', function() {
55
pg.connect(helper.config, assert.calls(function(err, client, done) {
66
assert.isNull(err);
77
client.query("CREATE TEMP TABLE why(names text[], numbors integer[], decimals double precision[])");
8-
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);
8+
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);
99
test('decimals', function() {
1010
client.query('SELECT decimals FROM why', assert.success(function(result) {
1111
assert.lengthIs(result.rows[0].decimals, 3);

0 commit comments

Comments
 (0)