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-08-12 10:52:29 +08:00
|
|
|
helper.pg.defaults.poolIdleTimeout = 100;
|
2011-05-02 13:16:07 +08:00
|
|
|
var args = {
|
|
|
|
user: helper.args.user,
|
|
|
|
password: helper.args.password,
|
|
|
|
database: helper.args.database,
|
|
|
|
port: helper.args.port,
|
|
|
|
host: helper.args.host
|
|
|
|
}
|
|
|
|
|
|
|
|
var moreArgs = {
|
2011-08-12 08:32:57 +08:00
|
|
|
database: helper.args.database,
|
2011-05-02 13:16:07 +08:00
|
|
|
password: helper.args.password,
|
2011-08-12 08:32:57 +08:00
|
|
|
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',
|
2011-05-02 13:16:07 +08:00
|
|
|
database: helper.args.database,
|
|
|
|
port: helper.args.port,
|
|
|
|
zomg: true
|
|
|
|
}
|
|
|
|
|
2011-08-12 08:32:57 +08:00
|
|
|
test('connecting with complete config', function() {
|
|
|
|
|
|
|
|
helper.pg.connect(args, assert.calls(function(err, client) {
|
|
|
|
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");
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|