a connection string without all settings no longer causes client

constructor to throw error
This commit is contained in:
brianc 2010-12-28 10:44:33 -06:00
parent 4aa4443505
commit 51d922f3e1
2 changed files with 25 additions and 2 deletions

View File

@ -12,7 +12,7 @@ var Connection = require(__dirname + '/connection');
var parseConnectionString = function(str) {
var result = url.parse(str);
result.host = result.hostname;
result.database = result.pathname.slice(1);
result.database = result.pathname ? result.pathname.slice(1) : null
var auth = (result.auth || ':').split(':');
result.user = auth[0];
result.password = auth[1];

View File

@ -19,7 +19,7 @@ test('client settings', function() {
port: 321,
password: password
});
assert.equal(client.user, user);
assert.equal(client.database, database);
assert.equal(client.port, 321);
@ -27,3 +27,26 @@ test('client settings', function() {
});
});
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")
assert.equal(client.user, "")
assert.equal(client.password, "")
assert.equal(client.host, "host1")
assert.equal(client.port, 5432)
assert.equal(client.database, "")
})
})