Skip to content

Commit 7dc89ce

Browse files
committed
made integration tests die faster when they cannot connect to the database
1 parent c0f37e1 commit 7dc89ce

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ port=5432
77
database=postgres
88
verbose=false
99

10+
test-connection:
11+
@node script/test-connection.js -u $(user) --password $(password) -p $(port) -d $(database) -h $(host) --verbose $(verbose)
12+
1013
test-unit:
1114
@find test/unit -name "*-tests.js" | xargs -n 1 -I file node file --verbose $(verbose)
1215

13-
test-integration:
16+
test-integration: test-connection
1417
@find test/integration -name "*-tests.js" | xargs -n 1 -I file node file -u $(user) --password $(password) -p $(port) -d $(database) -h $(host) --verbose $(verbose)
1518

1619
test-all: test-unit test-integration

script/test-connection.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var helper = require(__dirname + '/../test/test-helper');
2+
var connectionString = helper.connectionString();
3+
console.log();
4+
console.log("testing ability to connect to '%s'", connectionString);
5+
var pg = require(__dirname + '/../lib');
6+
pg.connect(connectionString, function(err, client) {
7+
if(err !== null) {
8+
console.error("Recieved connection error when attempting to contact PostgreSQL:");
9+
console.error(err);
10+
process.exit(255);
11+
}
12+
console.log("Checking for existance of required test table 'person'")
13+
client.query("SELECT COUNT(name) FROM person", function(err, callback) {
14+
if(err != null) {
15+
console.error("Recieved error when executing query 'SELECT COUNT(name) FROM person'")
16+
console.error("It is possible you have not yet run the table create script under script/create-test-tables")
17+
console.error("Consult the postgres-node wiki under the 'Testing' section for more information")
18+
console.error(err);
19+
process.exit(255);
20+
}
21+
pg.end();
22+
})
23+
})

test/integration/test-helper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
var helper = require(__dirname + '/../test-helper');
22
//export parent helper stuffs
33
module.exports = helper;
4+
5+
if(helper.args.verbose) {
6+
}

0 commit comments

Comments
 (0)