2010-10-03 13:27:16 +08:00
|
|
|
require(__dirname+'/test-helper');
|
2010-10-11 11:42:13 +08:00
|
|
|
|
2010-10-03 13:27:16 +08:00
|
|
|
test('client settings', function() {
|
2010-10-11 11:42:13 +08:00
|
|
|
|
2010-10-03 13:27:16 +08:00
|
|
|
test('defaults', function() {
|
|
|
|
var client = new Client();
|
2011-03-02 04:13:04 +08:00
|
|
|
assert.equal(client.user, process.env.USER);
|
|
|
|
assert.equal(client.database, process.env.USER);
|
2010-10-03 13:27:16 +08:00
|
|
|
assert.equal(client.port, 5432);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('custom', function() {
|
|
|
|
var user = 'brian';
|
|
|
|
var database = 'pgjstest';
|
2010-10-20 12:26:25 +08:00
|
|
|
var password = 'boom';
|
2010-10-03 13:27:16 +08:00
|
|
|
var client = new Client({
|
|
|
|
user: user,
|
|
|
|
database: database,
|
2010-10-20 12:26:25 +08:00
|
|
|
port: 321,
|
|
|
|
password: password
|
2010-10-03 13:27:16 +08:00
|
|
|
});
|
2010-12-29 00:44:33 +08:00
|
|
|
|
2010-10-03 13:27:16 +08:00
|
|
|
assert.equal(client.user, user);
|
|
|
|
assert.equal(client.database, database);
|
|
|
|
assert.equal(client.port, 321);
|
2010-10-20 12:26:25 +08:00
|
|
|
assert.equal(client.password, password);
|
2010-10-03 13:27:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2010-12-29 00:44:33 +08:00
|
|
|
|
|
|
|
test('initializing from a config string', function() {
|
|
|
|
|
|
|
|
test('uses the correct values from the config string', function() {
|
|
|
|
var client = new Client("pg://brian:pass@host1:333/databasename")
|
|
|
|
assert.equal(client.user, 'brian')
|
|
|
|
assert.equal(client.password, "pass")
|
|
|
|
assert.equal(client.host, "host1")
|
|
|
|
assert.equal(client.port, 333)
|
|
|
|
assert.equal(client.database, "databasename")
|
|
|
|
})
|
|
|
|
|
|
|
|
test('when not including all values the defaults are used', function() {
|
|
|
|
var client = new Client("pg://host1")
|
2011-03-02 04:13:04 +08:00
|
|
|
assert.equal(client.user, process.env.USER)
|
|
|
|
assert.equal(client.password, null)
|
2010-12-29 00:44:33 +08:00
|
|
|
assert.equal(client.host, "host1")
|
|
|
|
assert.equal(client.port, 5432)
|
2011-03-02 04:13:04 +08:00
|
|
|
assert.equal(client.database, process.env.USER)
|
2010-12-29 00:44:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
})
|
2011-03-02 04:35:14 +08:00
|
|
|
|
|
|
|
test('calls connect correctly on connection', function() {
|
|
|
|
var client = new Client("/tmp");
|
|
|
|
var usedPort = "";
|
|
|
|
var usedHost = "";
|
|
|
|
client.connection.connect = function(port, host) {
|
|
|
|
usedPort = port;
|
|
|
|
usedHost = host;
|
|
|
|
};
|
|
|
|
client.connect();
|
|
|
|
assert.equal(usedPort, "/tmp/.s.PGSQL.5432");
|
|
|
|
assert.strictEqual(usedHost, undefined)
|
|
|
|
})
|
|
|
|
|