Skip to content

Commit f698ed4

Browse files
committed
use config dict in all test
instead of the connection string use the config dict in all tests to be able to specify things like binary mode
1 parent 239d8bd commit f698ed4

20 files changed

+68
-116
lines changed

script/test-connection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var helper = require(__dirname + '/../test/test-helper');
2-
var connectionString = helper.connectionString();
2+
33
console.log();
4-
console.log("testing ability to connect to '%s'", connectionString);
4+
console.log("testing ability to connect to '%j'", helper.config);
55
var pg = require(__dirname + '/../lib');
6-
pg.connect(connectionString, function(err, client) {
6+
pg.connect(helper.config, function(err, client) {
77
if(err !== null) {
88
console.error("Recieved connection error when attempting to contact PostgreSQL:");
99
console.error(err);

test/integration/client/api-tests.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ if(helper.args.native) {
55
pg = require(__dirname + '/../../../lib').native;
66
}
77

8-
var connectionString = helper.connectionString(__filename);
9-
108
var log = function() {
119
//console.log.apply(console, arguments);
1210
}
1311

1412
var sink = new helper.Sink(5, 10000, function() {
15-
log("ending connection pool: %s", connectionString);
16-
pg.end(connectionString);
13+
log("ending connection pool: %j", helper.config);
14+
pg.end(helper.config);
1715
});
1816

1917
test('api', function() {
20-
log("connecting to %s", connectionString)
21-
pg.connect(connectionString, assert.calls(function(err, client) {
18+
log("connecting to %j", helper.config)
19+
pg.connect(helper.config, assert.calls(function(err, client) {
2220
assert.equal(err, null, "Failed to connect: " + helper.sys.inspect(err));
2321

2422
client.query('CREATE TEMP TABLE band(name varchar(100))');
@@ -60,7 +58,7 @@ test('api', function() {
6058
})
6159

6260
test('executing nested queries', function() {
63-
pg.connect(connectionString, assert.calls(function(err, client) {
61+
pg.connect(helper.config, assert.calls(function(err, client) {
6462
assert.isNull(err);
6563
log("connected for nested queriese")
6664
client.query('select now as now from NOW()', assert.calls(function(err, result) {
@@ -87,7 +85,7 @@ test('raises error if cannot connect', function() {
8785
})
8886

8987
test("query errors are handled and do not bubble if callback is provded", function() {
90-
pg.connect(connectionString, assert.calls(function(err, client) {
88+
pg.connect(helper.config, assert.calls(function(err, client) {
9189
assert.isNull(err)
9290
log("checking for query error")
9391
client.query("SELECT OISDJF FROM LEIWLISEJLSE", assert.calls(function(err, result) {
@@ -99,7 +97,7 @@ test("query errors are handled and do not bubble if callback is provded", functi
9997
})
10098

10199
test('callback is fired once and only once', function() {
102-
pg.connect(connectionString, assert.calls(function(err, client) {
100+
pg.connect(helper.config, assert.calls(function(err, client) {
103101
assert.isNull(err);
104102
client.query("CREATE TEMP TABLE boom(name varchar(10))");
105103
var callCount = 0;
@@ -115,7 +113,7 @@ test('callback is fired once and only once', function() {
115113
})
116114

117115
test('can provide callback and config object', function() {
118-
pg.connect(connectionString, assert.calls(function(err, client) {
116+
pg.connect(helper.config, assert.calls(function(err, client) {
119117
assert.isNull(err);
120118
client.query({
121119
name: 'boom',
@@ -128,7 +126,7 @@ test('can provide callback and config object', function() {
128126
})
129127

130128
test('can provide callback and config and parameters', function() {
131-
pg.connect(connectionString, assert.calls(function(err, client) {
129+
pg.connect(helper.config, assert.calls(function(err, client) {
132130
assert.isNull(err);
133131
var config = {
134132
text: 'select $1::text as val'
@@ -142,7 +140,7 @@ test('can provide callback and config and parameters', function() {
142140
})
143141

144142
test('null and undefined are both inserted as NULL', function() {
145-
pg.connect(connectionString, assert.calls(function(err, client) {
143+
pg.connect(helper.config, assert.calls(function(err, client) {
146144
assert.isNull(err);
147145
client.query("CREATE TEMP TABLE my_nulls(a varchar(1), b varchar(1), c integer, d integer, e date, f date)");
148146
client.query("INSERT INTO my_nulls(a,b,c,d,e,f) VALUES ($1,$2,$3,$4,$5,$6)", [ null, undefined, null, undefined, null, undefined ]);

test/integration/client/array-tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
var helper = require(__dirname + "/test-helper");
22
var pg = helper.pg;
3-
var conString = helper.connectionString();
43

54
test('parsing array results', function() {
6-
pg.connect(conString, assert.calls(function(err, client) {
5+
pg.connect(helper.config, assert.calls(function(err, client) {
76
assert.isNull(err);
87
client.query("CREATE TEMP TABLE why(names text[], numbors integer[])");
98
client.query('INSERT INTO why(names, numbors) VALUES(\'{"aaron", "brian","a b c" }\', \'{1, 2, 3}\')').on('error', console.log);

test/integration/client/cancel-query-tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ test("cancellation of a query", function() {
2828
rows4++;
2929
});
3030

31-
helper.pg.cancel(helper.connectionString, client, query1);
32-
helper.pg.cancel(helper.connectionString, client, query2);
33-
helper.pg.cancel(helper.connectionString, client, query4);
31+
helper.pg.cancel(helper.config, client, query1);
32+
helper.pg.cancel(helper.config, client, query2);
33+
helper.pg.cancel(helper.config, client, query4);
3434

3535
setTimeout(function() {
3636
assert.equal(rows1, 0);

test/integration/client/drain-tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if(helper.args.native) {
66
}
77

88
var testDrainOfClientWithPendingQueries = function() {
9-
pg.connect(helper.connectionString(), assert.success(function(client) {
9+
pg.connect(helper.config, assert.success(function(client) {
1010
test('when there are pending queries and client is resumed', function() {
1111
var drainCount = 0;
1212
client.on('drain', function() {
@@ -28,7 +28,7 @@ var testDrainOfClientWithPendingQueries = function() {
2828
}));
2929
};
3030

31-
pg.connect(helper.connectionString(), assert.success(function(client) {
31+
pg.connect(helper.config, assert.success(function(client) {
3232
var drainCount = 0;
3333
client.on('drain', function() {
3434
drainCount++;

test/integration/client/result-metadata-tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
var helper = require(__dirname + "/test-helper");
22
var pg = helper.pg;
3-
var conString = helper.connectionString();
43

54
test('should return insert metadata', function() {
65
return false;
7-
pg.connect(conString, assert.calls(function(err, client) {
6+
pg.connect(helper.config, assert.calls(function(err, client) {
87
assert.isNull(err);
98
client.query("CREATE TEMP TABLE zugzug(name varchar(10))", assert.calls(function(err, result) {
109
assert.isNull(err);
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
var helper = require(__dirname+'/../test-helper');
22

3-
module.exports = {
4-
//creates a client from cli parameters
5-
client: function() {
6-
var client = new Client({
7-
database: helper.args.database,
8-
user: helper.args.user,
9-
password: helper.args.password,
10-
host: helper.args.host,
11-
port: helper.args.port
12-
});
13-
14-
client.connect();
15-
return client;
16-
},
17-
connectionString: helper.connectionString,
18-
Sink: helper.Sink,
19-
pg: helper.pg,
20-
args: helper.args
3+
//creates a client from cli parameters
4+
helper.client = function() {
5+
var client = new Client(helper.config);
6+
client.connect();
7+
return client;
218
};
9+
10+
module.exports = helper;

test/integration/client/transaction-tests.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ var sink = new helper.Sink(2, function() {
55
});
66

77
test('a single connection transaction', function() {
8-
var connectionString = helper.connectionString();
9-
10-
helper.pg.connect(connectionString, assert.calls(function(err, client) {
8+
helper.pg.connect(helper.config, assert.calls(function(err, client) {
119
assert.isNull(err);
1210

1311
client.query('begin');
@@ -48,8 +46,7 @@ test('a single connection transaction', function() {
4846
})
4947

5048
test('gh#36', function() {
51-
var connectionString = helper.connectionString();
52-
helper.pg.connect(connectionString, function(err, client) {
49+
helper.pg.connect(helper.config, function(err, client) {
5350
if(err) throw err;
5451
client.query("BEGIN");
5552
client.query({

test/integration/client/type-coercion-tests.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var helper = require(__dirname + '/test-helper');
22
var sink;
3-
var connectionString = helper.connectionString();
3+
44
var testForTypeCoercion = function(type){
5-
helper.pg.connect(connectionString, function(err, client) {
6-
assert.isNull(err)
5+
helper.pg.connect(helper.config, function(err, client) {
6+
assert.isNull(err);
77
client.query("create temp table test_type(col " + type.name + ")", assert.calls(function(err, result) {
88
assert.isNull(err);
99
test("Coerces " + type.name, function() {
@@ -126,7 +126,7 @@ test("timestampz round trip", function() {
126126
client.on('drain', client.end.bind(client));
127127
});
128128

129-
helper.pg.connect(helper.connectionString(), assert.calls(function(err, client) {
129+
helper.pg.connect(helper.config, assert.calls(function(err, client) {
130130
assert.isNull(err);
131131
client.query('select null as res;', assert.calls(function(err, res) {
132132
assert.isNull(err);

test/integration/connection-pool/ending-pool-tests.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
var helper = require(__dirname + '/test-helper')
2-
var conString1 = helper.connectionString();
3-
var conString2 = helper.connectionString();
4-
var conString3 = helper.connectionString();
5-
var conString4 = helper.connectionString();
62

73
var called = false;
84
test('disconnects', function() {
@@ -11,8 +7,8 @@ test('disconnects', function() {
117
//this should exit the process, killing each connection pool
128
helper.pg.end();
139
});
14-
[conString1, conString2, conString3, conString4].forEach(function() {
15-
helper.pg.connect(conString1, function(err, client) {
10+
[helper.config, helper.config, helper.config, helper.config].forEach(function(config) {
11+
helper.pg.connect(config, function(err, client) {
1612
assert.isNull(err);
1713
client.query("SELECT * FROM NOW()", function(err, result) {
1814
process.nextTick(function() {

0 commit comments

Comments
 (0)