remove node-tap

This commit is contained in:
bmc 2013-01-17 18:27:48 -06:00
parent 92e75f0577
commit 868a9d0e8d
4 changed files with 57 additions and 65 deletions

View File

@ -4,18 +4,7 @@ var val = function(key, config) {
return config[key] || return config[key] ||
process.env['PG' + key.toUpperCase()] || process.env['PG' + key.toUpperCase()] ||
defaults[key]; defaults[key];
} };
var ConnectionParameters = function(config) {
config = typeof config == 'string' ? parse(config) : (config || {});
this.user = val('user', config);
this.database = val('database', config);
this.port = parseInt(val('port', config));
this.host = val('host', config);
this.password = val('password', config);
this.binary = val('binary', config);
this.ssl = config.ssl || defaults.ssl;
}
var url = require('url'); var url = require('url');
//parses a connection string //parses a connection string
@ -33,6 +22,17 @@ var parse = function(str) {
config.password = auth[1]; config.password = auth[1];
config.port = result.port; config.port = result.port;
return config; return config;
} };
var ConnectionParameters = function(config) {
config = typeof config == 'string' ? parse(config) : (config || {});
this.user = val('user', config);
this.database = val('database', config);
this.port = parseInt(val('port', config));
this.host = val('host', config);
this.password = val('password', config);
this.binary = val('binary', config);
this.ssl = config.ssl || defaults.ssl;
};
module.exports = ConnectionParameters; module.exports = ConnectionParameters;

View File

@ -1,5 +1,5 @@
var test = require('tap').test; var helper = require(__dirname + '/../test-helper');
var assert = require('assert');
var ConnectionParameters = require(__dirname + '/../../../lib/connection-parameters'); var ConnectionParameters = require(__dirname + '/../../../lib/connection-parameters');
var defaults = require(__dirname + '/../../../lib').defaults; var defaults = require(__dirname + '/../../../lib').defaults;
@ -8,29 +8,27 @@ for(var key in process.env) {
delete process.env[key]; delete process.env[key];
} }
test('ConnectionParameters construction', function(t) { test('ConnectionParameters construction', function() {
t.ok(new ConnectionParameters(), 'with null config'); assert.ok(new ConnectionParameters(), 'with null config');
t.ok(new ConnectionParameters({user: 'asdf'}), 'with config object'); assert.ok(new ConnectionParameters({user: 'asdf'}), 'with config object');
t.ok(new ConnectionParameters('pg://localhost/postgres'), 'with connection string'); assert.ok(new ConnectionParameters('pg://localhost/postgres'), 'with connection string');
t.end(); });
})
var compare = function(t, actual, expected, type) { var compare = function(actual, expected, type) {
t.equal(actual.user, expected.user, type + ' user'); assert.equal(actual.user, expected.user, type + ' user');
t.equal(actual.database, expected.database, type + ' database'); assert.equal(actual.database, expected.database, type + ' database');
t.equal(actual.port, expected.port, type + ' port'); assert.equal(actual.port, expected.port, type + ' port');
t.equal(actual.host, expected.host, type + ' host'); assert.equal(actual.host, expected.host, type + ' host');
t.equal(actual.password, expected.password, type + ' password'); assert.equal(actual.password, expected.password, type + ' password');
t.equal(actual.binary, expected.binary, type + ' binary'); assert.equal(actual.binary, expected.binary, type + ' binary');
} };
test('ConnectionParameters initializing from defaults', function(t) { test('ConnectionParameters initializing from defaults', function() {
var subject = new ConnectionParameters(); var subject = new ConnectionParameters();
compare(t, subject, defaults, 'defaults'); compare(subject, defaults, 'defaults');
t.end(); });
})
test('ConnectionParameters initializing from config', function(t) { test('ConnectionParameters initializing from config', function() {
var config = { var config = {
user: 'brian', user: 'brian',
database: 'home', database: 'home',
@ -42,8 +40,7 @@ test('ConnectionParameters initializing from config', function(t) {
ssl: { ssl: {
asdf: 'blah' asdf: 'blah'
} }
} };
var subject = new ConnectionParameters(config); var subject = new ConnectionParameters(config);
compare(t, subject, config, 'config'); compare(subject, config, 'config');
t.end(); });
})

View File

@ -1,9 +1,8 @@
var test = require('tap').test; var helper = require(__dirname + '/../test-helper');
var assert = require('assert');
var ConnectionParameters = require(__dirname + '/../../../lib/connection-parameters'); var ConnectionParameters = require(__dirname + '/../../../lib/connection-parameters');
var defaults = require(__dirname + '/../../../lib').defaults; var defaults = require(__dirname + '/../../../lib').defaults;
//clear process.env //clear process.env
var realEnv = {}; var realEnv = {};
for(var key in process.env) { for(var key in process.env) {
@ -11,7 +10,6 @@ for(var key in process.env) {
delete process.env[key]; delete process.env[key];
} }
test('ConnectionParameters initialized from environment variables', function(t) { test('ConnectionParameters initialized from environment variables', function(t) {
process.env['PGHOST'] = 'local'; process.env['PGHOST'] = 'local';
process.env['PGUSER'] = 'bmc2'; process.env['PGUSER'] = 'bmc2';
@ -20,13 +18,12 @@ test('ConnectionParameters initialized from environment variables', function(t)
process.env['PGPASSWORD'] = 'open'; process.env['PGPASSWORD'] = 'open';
var subject = new ConnectionParameters(); var subject = new ConnectionParameters();
t.equal(subject.host, 'local', 'env host'); assert.equal(subject.host, 'local', 'env host');
t.equal(subject.user, 'bmc2', 'env user'); assert.equal(subject.user, 'bmc2', 'env user');
t.equal(subject.port, 7890, 'env port'); assert.equal(subject.port, 7890, 'env port');
t.equal(subject.database, 'allyerbase', 'env database'); assert.equal(subject.database, 'allyerbase', 'env database');
t.equal(subject.password, 'open', 'env password'); assert.equal(subject.password, 'open', 'env password');
t.end(); });
})
test('ConnectionParameters initialized from mix', function(t) { test('ConnectionParameters initialized from mix', function(t) {
delete process.env['PGPASSWORD']; delete process.env['PGPASSWORD'];
@ -34,14 +31,13 @@ test('ConnectionParameters initialized from mix', function(t) {
var subject = new ConnectionParameters({ var subject = new ConnectionParameters({
user: 'testing', user: 'testing',
database: 'zugzug' database: 'zugzug'
}) });
t.equal(subject.host, 'local', 'env host'); assert.equal(subject.host, 'local', 'env host');
t.equal(subject.user, 'testing', 'config user'); assert.equal(subject.user, 'testing', 'config user');
t.equal(subject.port, 7890, 'env port'); assert.equal(subject.port, 7890, 'env port');
t.equal(subject.database, 'zugzug', 'config database'); assert.equal(subject.database, 'zugzug', 'config database');
t.equal(subject.password, defaults.password, 'defaults password'); assert.equal(subject.password, defaults.password, 'defaults password');
t.end(); });
})
//clear process.env //clear process.env
for(var key in process.env) { for(var key in process.env) {
@ -51,13 +47,12 @@ for(var key in process.env) {
test('connection string parsing', function(t) { test('connection string parsing', function(t) {
var string = 'postgres://brian:pw@boom:381/lala'; var string = 'postgres://brian:pw@boom:381/lala';
var subject = new ConnectionParameters(string); var subject = new ConnectionParameters(string);
t.equal(subject.host, 'boom', 'string host'); assert.equal(subject.host, 'boom', 'string host');
t.equal(subject.user, 'brian', 'string user'); assert.equal(subject.user, 'brian', 'string user');
t.equal(subject.password, 'pw', 'string password'); assert.equal(subject.password, 'pw', 'string password');
t.equal(subject.port, 381, 'string port'); assert.equal(subject.port, 381, 'string port');
t.equal(subject.database, 'lala', 'string database'); assert.equal(subject.database, 'lala', 'string database');
t.end(); });
})
//restore process.env //restore process.env
for(var key in realEnv) { for(var key in realEnv) {

View File

@ -5,7 +5,7 @@ var defaults = require(__dirname + "/../../lib").defaults;
//this tests the monkey patching //this tests the monkey patching
//to ensure comptability with older //to ensure comptability with older
//versions of node //versions of node
test("EventEmitter.once", function() { test("EventEmitter.once", function(t) {
//an event emitter //an event emitter
var stream = new MemoryStream(); var stream = new MemoryStream();