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
This commit is contained in:
parent
239d8bd0c2
commit
f698ed4459
@ -1,9 +1,9 @@
|
||||
var helper = require(__dirname + '/../test/test-helper');
|
||||
var connectionString = helper.connectionString();
|
||||
|
||||
console.log();
|
||||
console.log("testing ability to connect to '%s'", connectionString);
|
||||
console.log("testing ability to connect to '%j'", helper.config);
|
||||
var pg = require(__dirname + '/../lib');
|
||||
pg.connect(connectionString, function(err, client) {
|
||||
pg.connect(helper.config, function(err, client) {
|
||||
if(err !== null) {
|
||||
console.error("Recieved connection error when attempting to contact PostgreSQL:");
|
||||
console.error(err);
|
||||
|
@ -5,20 +5,18 @@ if(helper.args.native) {
|
||||
pg = require(__dirname + '/../../../lib').native;
|
||||
}
|
||||
|
||||
var connectionString = helper.connectionString(__filename);
|
||||
|
||||
var log = function() {
|
||||
//console.log.apply(console, arguments);
|
||||
}
|
||||
|
||||
var sink = new helper.Sink(5, 10000, function() {
|
||||
log("ending connection pool: %s", connectionString);
|
||||
pg.end(connectionString);
|
||||
log("ending connection pool: %j", helper.config);
|
||||
pg.end(helper.config);
|
||||
});
|
||||
|
||||
test('api', function() {
|
||||
log("connecting to %s", connectionString)
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
log("connecting to %j", helper.config)
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.equal(err, null, "Failed to connect: " + helper.sys.inspect(err));
|
||||
|
||||
client.query('CREATE TEMP TABLE band(name varchar(100))');
|
||||
@ -60,7 +58,7 @@ test('api', function() {
|
||||
})
|
||||
|
||||
test('executing nested queries', function() {
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
log("connected for nested queriese")
|
||||
client.query('select now as now from NOW()', assert.calls(function(err, result) {
|
||||
@ -87,7 +85,7 @@ test('raises error if cannot connect', function() {
|
||||
})
|
||||
|
||||
test("query errors are handled and do not bubble if callback is provded", function() {
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err)
|
||||
log("checking for query error")
|
||||
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
|
||||
})
|
||||
|
||||
test('callback is fired once and only once', function() {
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE boom(name varchar(10))");
|
||||
var callCount = 0;
|
||||
@ -115,7 +113,7 @@ test('callback is fired once and only once', function() {
|
||||
})
|
||||
|
||||
test('can provide callback and config object', function() {
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query({
|
||||
name: 'boom',
|
||||
@ -128,7 +126,7 @@ test('can provide callback and config object', function() {
|
||||
})
|
||||
|
||||
test('can provide callback and config and parameters', function() {
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
var config = {
|
||||
text: 'select $1::text as val'
|
||||
@ -142,7 +140,7 @@ test('can provide callback and config and parameters', function() {
|
||||
})
|
||||
|
||||
test('null and undefined are both inserted as NULL', function() {
|
||||
pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE my_nulls(a varchar(1), b varchar(1), c integer, d integer, e date, f date)");
|
||||
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 ]);
|
||||
|
@ -1,9 +1,8 @@
|
||||
var helper = require(__dirname + "/test-helper");
|
||||
var pg = helper.pg;
|
||||
var conString = helper.connectionString();
|
||||
|
||||
test('parsing array results', function() {
|
||||
pg.connect(conString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
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);
|
||||
|
@ -28,9 +28,9 @@ test("cancellation of a query", function() {
|
||||
rows4++;
|
||||
});
|
||||
|
||||
helper.pg.cancel(helper.connectionString, client, query1);
|
||||
helper.pg.cancel(helper.connectionString, client, query2);
|
||||
helper.pg.cancel(helper.connectionString, client, query4);
|
||||
helper.pg.cancel(helper.config, client, query1);
|
||||
helper.pg.cancel(helper.config, client, query2);
|
||||
helper.pg.cancel(helper.config, client, query4);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(rows1, 0);
|
||||
|
@ -6,7 +6,7 @@ if(helper.args.native) {
|
||||
}
|
||||
|
||||
var testDrainOfClientWithPendingQueries = function() {
|
||||
pg.connect(helper.connectionString(), assert.success(function(client) {
|
||||
pg.connect(helper.config, assert.success(function(client) {
|
||||
test('when there are pending queries and client is resumed', function() {
|
||||
var drainCount = 0;
|
||||
client.on('drain', function() {
|
||||
@ -28,7 +28,7 @@ var testDrainOfClientWithPendingQueries = function() {
|
||||
}));
|
||||
};
|
||||
|
||||
pg.connect(helper.connectionString(), assert.success(function(client) {
|
||||
pg.connect(helper.config, assert.success(function(client) {
|
||||
var drainCount = 0;
|
||||
client.on('drain', function() {
|
||||
drainCount++;
|
||||
|
@ -1,10 +1,9 @@
|
||||
var helper = require(__dirname + "/test-helper");
|
||||
var pg = helper.pg;
|
||||
var conString = helper.connectionString();
|
||||
|
||||
test('should return insert metadata', function() {
|
||||
return false;
|
||||
pg.connect(conString, assert.calls(function(err, client) {
|
||||
pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("CREATE TEMP TABLE zugzug(name varchar(10))", assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
|
@ -1,21 +1,10 @@
|
||||
var helper = require(__dirname+'/../test-helper');
|
||||
|
||||
module.exports = {
|
||||
//creates a client from cli parameters
|
||||
client: function() {
|
||||
var client = new Client({
|
||||
database: helper.args.database,
|
||||
user: helper.args.user,
|
||||
password: helper.args.password,
|
||||
host: helper.args.host,
|
||||
port: helper.args.port
|
||||
});
|
||||
|
||||
client.connect();
|
||||
return client;
|
||||
},
|
||||
connectionString: helper.connectionString,
|
||||
Sink: helper.Sink,
|
||||
pg: helper.pg,
|
||||
args: helper.args
|
||||
//creates a client from cli parameters
|
||||
helper.client = function() {
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
return client;
|
||||
};
|
||||
|
||||
module.exports = helper;
|
||||
|
@ -5,9 +5,7 @@ var sink = new helper.Sink(2, function() {
|
||||
});
|
||||
|
||||
test('a single connection transaction', function() {
|
||||
var connectionString = helper.connectionString();
|
||||
|
||||
helper.pg.connect(connectionString, assert.calls(function(err, client) {
|
||||
helper.pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
|
||||
client.query('begin');
|
||||
@ -48,8 +46,7 @@ test('a single connection transaction', function() {
|
||||
})
|
||||
|
||||
test('gh#36', function() {
|
||||
var connectionString = helper.connectionString();
|
||||
helper.pg.connect(connectionString, function(err, client) {
|
||||
helper.pg.connect(helper.config, function(err, client) {
|
||||
if(err) throw err;
|
||||
client.query("BEGIN");
|
||||
client.query({
|
||||
|
@ -1,9 +1,9 @@
|
||||
var helper = require(__dirname + '/test-helper');
|
||||
var sink;
|
||||
var connectionString = helper.connectionString();
|
||||
|
||||
var testForTypeCoercion = function(type){
|
||||
helper.pg.connect(connectionString, function(err, client) {
|
||||
assert.isNull(err)
|
||||
helper.pg.connect(helper.config, function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("create temp table test_type(col " + type.name + ")", assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
test("Coerces " + type.name, function() {
|
||||
@ -126,7 +126,7 @@ test("timestampz round trip", function() {
|
||||
client.on('drain', client.end.bind(client));
|
||||
});
|
||||
|
||||
helper.pg.connect(helper.connectionString(), assert.calls(function(err, client) {
|
||||
helper.pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query('select null as res;', assert.calls(function(err, res) {
|
||||
assert.isNull(err);
|
||||
|
@ -1,8 +1,4 @@
|
||||
var helper = require(__dirname + '/test-helper')
|
||||
var conString1 = helper.connectionString();
|
||||
var conString2 = helper.connectionString();
|
||||
var conString3 = helper.connectionString();
|
||||
var conString4 = helper.connectionString();
|
||||
|
||||
var called = false;
|
||||
test('disconnects', function() {
|
||||
@ -11,8 +7,8 @@ test('disconnects', function() {
|
||||
//this should exit the process, killing each connection pool
|
||||
helper.pg.end();
|
||||
});
|
||||
[conString1, conString2, conString3, conString4].forEach(function() {
|
||||
helper.pg.connect(conString1, function(err, client) {
|
||||
[helper.config, helper.config, helper.config, helper.config].forEach(function(config) {
|
||||
helper.pg.connect(config, function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("SELECT * FROM NOW()", function(err, result) {
|
||||
process.nextTick(function() {
|
||||
|
@ -2,24 +2,22 @@ var helper = require(__dirname + "/../test-helper");
|
||||
var pg = require(__dirname + "/../../../lib");
|
||||
helper.pg = pg;
|
||||
|
||||
var conString = helper.connectionString();
|
||||
|
||||
//first make pool hold 2 clients
|
||||
pg.defaults.poolSize = 2;
|
||||
helper.pg.defaults.poolSize = 2;
|
||||
|
||||
var killIdleQuery = 'SELECT procpid, (SELECT pg_terminate_backend(procpid)) AS killed FROM pg_stat_activity WHERE current_query LIKE \'<IDLE>\'';
|
||||
|
||||
//get first client
|
||||
pg.connect(conString, assert.success(function(client) {
|
||||
helper.pg.connect(helper.config, assert.success(function(client) {
|
||||
client.id = 1;
|
||||
pg.connect(conString, assert.success(function(client2) {
|
||||
helper.pg.connect(helper.config, assert.success(function(client2) {
|
||||
client2.id = 2;
|
||||
//subscribe to the pg error event
|
||||
assert.emits(pg, 'error', function(error, brokenClient) {
|
||||
assert.emits(helper.pg, 'error', function(error, brokenClient) {
|
||||
assert.ok(error);
|
||||
assert.ok(brokenClient);
|
||||
assert.equal(client.id, brokenClient.id);
|
||||
pg.end();
|
||||
helper.pg.end();
|
||||
});
|
||||
//kill the connection from client
|
||||
client2.query(killIdleQuery, assert.success(function(res) {
|
||||
|
@ -3,7 +3,7 @@ var helper = require(__dirname + '/test-helper');
|
||||
helper.pg.defaults.poolIdleTimeout = 200;
|
||||
|
||||
test('idle timeout', function() {
|
||||
helper.pg.connect(helper.connectionString(), assert.calls(function(err, client) {
|
||||
helper.pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query('SELECT NOW()');
|
||||
//just let this one time out
|
||||
|
@ -1,18 +1,15 @@
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var pg = require(__dirname + "/../../../lib");
|
||||
helper.pg = pg;
|
||||
|
||||
var testPoolSize = function(max) {
|
||||
var conString = helper.connectionString();
|
||||
helper.testPoolSize = function(max) {
|
||||
var sink = new helper.Sink(max, function() {
|
||||
helper.pg.end(conString);
|
||||
helper.pg.end();
|
||||
});
|
||||
|
||||
test("can pool " + max + " times", function() {
|
||||
for(var i = 0; i < max; i++) {
|
||||
helper.pg.poolSize = 10;
|
||||
test("connection #" + i + " executes", function() {
|
||||
helper.pg.connect(conString, function(err, client) {
|
||||
helper.pg.connect(helper.config, function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("select * from person", function(err, result) {
|
||||
assert.lengthIs(result.rows, 26)
|
||||
@ -30,11 +27,5 @@ var testPoolSize = function(max) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
args: helper.args,
|
||||
pg: helper.pg,
|
||||
connectionString: helper.connectionString,
|
||||
Sink: helper.Sink,
|
||||
testPoolSize: testPoolSize
|
||||
}
|
||||
module.exports = helper;
|
||||
|
||||
|
@ -7,35 +7,25 @@ helper.pg.defaults.database = helper.args.database;
|
||||
helper.pg.defaults.port = helper.args.port;
|
||||
helper.pg.defaults.host = helper.args.host;
|
||||
helper.pg.defaults.poolIdleTimeout = 100;
|
||||
var args = {
|
||||
user: helper.args.user,
|
||||
password: helper.args.password,
|
||||
database: helper.args.database,
|
||||
port: helper.args.port,
|
||||
host: helper.args.host
|
||||
|
||||
var moreArgs = {};
|
||||
for (c in helper.config) {
|
||||
moreArgs[c] = helper.config[c];
|
||||
}
|
||||
moreArgs.zomg = true;
|
||||
|
||||
var badArgs = {};
|
||||
for (c in helper.config) {
|
||||
badArgs[c] = helper.config[c];
|
||||
}
|
||||
|
||||
var moreArgs = {
|
||||
database: helper.args.database,
|
||||
password: helper.args.password,
|
||||
port: helper.args.port,
|
||||
user: helper.args.user,
|
||||
host: helper.args.host,
|
||||
zomg: true
|
||||
}
|
||||
|
||||
var badArgs = {
|
||||
user: helper.args.user + 'laksdjfl',
|
||||
host: helper.args.host,
|
||||
password: helper.args.password + 'asldkfjlas',
|
||||
database: helper.args.database,
|
||||
port: helper.args.port,
|
||||
zomg: true
|
||||
}
|
||||
badArgs.user = badArgs.user + 'laksdjfl';
|
||||
badArgs.password = badArgs.password + 'asldkfjlas';
|
||||
badArgs.zomg = true;
|
||||
|
||||
test('connecting with complete config', function() {
|
||||
|
||||
helper.pg.connect(args, assert.calls(function(err, client) {
|
||||
helper.pg.connect(helper.config, assert.calls(function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.iGotAccessed = true;
|
||||
client.query("SELECT NOW()")
|
||||
|
@ -1,9 +1,8 @@
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var Client = require(__dirname + "/../../lib/native");
|
||||
var conString = helper.connectionString();
|
||||
|
||||
test('fires callback with results', function() {
|
||||
var client = new Client(conString);
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
client.query('SELECT 1 as num', assert.calls(function(err, result) {
|
||||
assert.isNull(err);
|
||||
|
@ -12,7 +12,7 @@ test('connecting with wrong parameters', function() {
|
||||
});
|
||||
|
||||
test('connects', function() {
|
||||
var con = new Client(helper.connectionString());
|
||||
var con = new Client(helper.config);
|
||||
con.connect();
|
||||
assert.emits(con, 'connect', function() {
|
||||
test('disconnects', function() {
|
||||
|
@ -1,9 +1,8 @@
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var Client = require(__dirname + "/../../lib/native");
|
||||
var conString = helper.connectionString();
|
||||
|
||||
test('query with non-text as first parameter throws error', function() {
|
||||
var client = new Client(conString);
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
assert.emits(client, 'connect', function() {
|
||||
assert.throws(function() {
|
||||
@ -14,7 +13,7 @@ test('query with non-text as first parameter throws error', function() {
|
||||
})
|
||||
|
||||
test('parameterized query with non-text as first parameter throws error', function() {
|
||||
var client = new Client(conString);
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
assert.emits(client, 'connect', function() {
|
||||
assert.throws(function() {
|
||||
@ -28,7 +27,7 @@ test('parameterized query with non-text as first parameter throws error', functi
|
||||
})
|
||||
|
||||
var connect = function(callback) {
|
||||
var client = new Client(conString);
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
assert.emits(client, 'connect', function() {
|
||||
callback(client);
|
||||
|
@ -1,9 +1,8 @@
|
||||
var helper = require(__dirname + "/../test-helper");
|
||||
var Client = require(__dirname + "/../../lib/native");
|
||||
var conString = helper.connectionString();
|
||||
|
||||
var setupClient = function() {
|
||||
var client = new Client(conString);
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
client.query("CREATE TEMP TABLE boom(name varchar(10), age integer)");
|
||||
client.query("INSERT INTO boom(name, age) VALUES('Aaron', 26)");
|
||||
@ -12,7 +11,7 @@ var setupClient = function() {
|
||||
}
|
||||
|
||||
test('connects', function() {
|
||||
var client = new Client(conString);
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
test('good query', function() {
|
||||
var query = client.query("SELECT 1 as num, 'HELLO' as str");
|
||||
|
@ -2,7 +2,7 @@ var helper = require(__dirname + "/../test-helper");
|
||||
var Client = require(__dirname + "/../../lib/native");
|
||||
|
||||
test('many rows', function() {
|
||||
var client = new Client(helper.connectionString());
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
var q = client.query("SELECT * FROM person");
|
||||
var rows = [];
|
||||
@ -16,7 +16,7 @@ test('many rows', function() {
|
||||
});
|
||||
|
||||
test('many queries', function() {
|
||||
var client = new Client(helper.connectionString());
|
||||
var client = new Client(helper.config);
|
||||
client.connect();
|
||||
var count = 0;
|
||||
var expected = 100;
|
||||
@ -35,7 +35,7 @@ test('many queries', function() {
|
||||
test('many clients', function() {
|
||||
var clients = [];
|
||||
for(var i = 0; i < 10; i++) {
|
||||
clients.push(new Client(helper.connectionString()));
|
||||
clients.push(new Client(helper.config));
|
||||
}
|
||||
clients.forEach(function(client) {
|
||||
client.connect();
|
||||
|
@ -225,9 +225,7 @@ module.exports = {
|
||||
args: args,
|
||||
Sink: Sink,
|
||||
pg: require(__dirname + '/../lib/'),
|
||||
connectionString: function() {
|
||||
return "pg"+(count++)+"://"+args.user+":"+args.password+"@"+args.host+":"+args.port+"/"+args.database;
|
||||
},
|
||||
config: args,
|
||||
sys: sys,
|
||||
Client: Client
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user