2011-05-02 13:16:07 +08:00
|
|
|
var helper = require(__dirname + '/test-helper');
|
|
|
|
|
|
|
|
helper.pg.defaults.poolSize = 1;
|
2011-08-12 08:32:57 +08:00
|
|
|
helper.pg.defaults.user = helper.args.user;
|
|
|
|
helper.pg.defaults.password = helper.args.password;
|
|
|
|
helper.pg.defaults.database = helper.args.database;
|
|
|
|
helper.pg.defaults.port = helper.args.port;
|
|
|
|
helper.pg.defaults.host = helper.args.host;
|
2011-11-22 11:59:54 +08:00
|
|
|
helper.pg.defaults.binary = helper.args.binary;
|
2011-08-12 10:52:29 +08:00
|
|
|
helper.pg.defaults.poolIdleTimeout = 100;
|
2011-05-02 13:16:07 +08:00
|
|
|
|
2011-11-22 11:42:43 +08:00
|
|
|
var moreArgs = {};
|
|
|
|
for (c in helper.config) {
|
|
|
|
moreArgs[c] = helper.config[c];
|
2011-08-12 08:32:57 +08:00
|
|
|
}
|
2011-11-22 11:42:43 +08:00
|
|
|
moreArgs.zomg = true;
|
2011-08-12 08:32:57 +08:00
|
|
|
|
2011-11-22 11:42:43 +08:00
|
|
|
var badArgs = {};
|
|
|
|
for (c in helper.config) {
|
|
|
|
badArgs[c] = helper.config[c];
|
2011-05-02 13:16:07 +08:00
|
|
|
}
|
|
|
|
|
2011-11-22 11:42:43 +08:00
|
|
|
badArgs.user = badArgs.user + 'laksdjfl';
|
|
|
|
badArgs.password = badArgs.password + 'asldkfjlas';
|
|
|
|
badArgs.zomg = true;
|
|
|
|
|
2011-08-12 08:32:57 +08:00
|
|
|
test('connecting with complete config', function() {
|
|
|
|
|
2011-11-22 11:42:43 +08:00
|
|
|
helper.pg.connect(helper.config, assert.calls(function(err, client) {
|
2011-08-12 08:32:57 +08:00
|
|
|
assert.isNull(err);
|
|
|
|
client.iGotAccessed = true;
|
|
|
|
client.query("SELECT NOW()")
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('connecting with different config object', function() {
|
|
|
|
|
|
|
|
helper.pg.connect(moreArgs, assert.calls(function(err, client) {
|
|
|
|
assert.isNull(err);
|
|
|
|
assert.ok(client.iGotAccessed === true)
|
|
|
|
client.query("SELECT NOW()");
|
|
|
|
}))
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('connecting with all defaults', function() {
|
|
|
|
|
|
|
|
helper.pg.connect(assert.calls(function(err, client) {
|
|
|
|
assert.isNull(err);
|
|
|
|
assert.ok(client.iGotAccessed === true);
|
|
|
|
client.end();
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
test('connecting with invalid config', function() {
|
|
|
|
|
|
|
|
helper.pg.connect(badArgs, assert.calls(function(err, client) {
|
|
|
|
assert.ok(err != null, "Expected connection error using invalid connection credentials");
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|