From 868a9d0e8ddcd6f4e464bf4f47ce4c8db44ddcd5 Mon Sep 17 00:00:00 2001 From: bmc Date: Thu, 17 Jan 2013 18:27:48 -0600 Subject: [PATCH] remove node-tap --- lib/connection-parameters.js | 26 +++++----- .../connection-parameters/creation-tests.js | 47 +++++++++---------- .../environment-variable-tests.js | 47 +++++++++---------- test/unit/utils-tests.js | 2 +- 4 files changed, 57 insertions(+), 65 deletions(-) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index bbbbf1d..e006e58 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -4,18 +4,7 @@ var val = function(key, config) { return config[key] || process.env['PG' + key.toUpperCase()] || 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'); //parses a connection string @@ -33,6 +22,17 @@ var parse = function(str) { config.password = auth[1]; config.port = result.port; 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; diff --git a/test/unit/connection-parameters/creation-tests.js b/test/unit/connection-parameters/creation-tests.js index de22c6d..e8306b6 100644 --- a/test/unit/connection-parameters/creation-tests.js +++ b/test/unit/connection-parameters/creation-tests.js @@ -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 defaults = require(__dirname + '/../../../lib').defaults; @@ -8,29 +8,27 @@ for(var key in process.env) { delete process.env[key]; } -test('ConnectionParameters construction', function(t) { - t.ok(new ConnectionParameters(), 'with null config'); - t.ok(new ConnectionParameters({user: 'asdf'}), 'with config object'); - t.ok(new ConnectionParameters('pg://localhost/postgres'), 'with connection string'); - t.end(); -}) +test('ConnectionParameters construction', function() { + assert.ok(new ConnectionParameters(), 'with null config'); + assert.ok(new ConnectionParameters({user: 'asdf'}), 'with config object'); + assert.ok(new ConnectionParameters('pg://localhost/postgres'), 'with connection string'); +}); -var compare = function(t, actual, expected, type) { - t.equal(actual.user, expected.user, type + ' user'); - t.equal(actual.database, expected.database, type + ' database'); - t.equal(actual.port, expected.port, type + ' port'); - t.equal(actual.host, expected.host, type + ' host'); - t.equal(actual.password, expected.password, type + ' password'); - t.equal(actual.binary, expected.binary, type + ' binary'); -} +var compare = function(actual, expected, type) { + assert.equal(actual.user, expected.user, type + ' user'); + assert.equal(actual.database, expected.database, type + ' database'); + assert.equal(actual.port, expected.port, type + ' port'); + assert.equal(actual.host, expected.host, type + ' host'); + assert.equal(actual.password, expected.password, type + ' password'); + 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(); - compare(t, subject, defaults, 'defaults'); - t.end(); -}) + compare(subject, defaults, 'defaults'); +}); -test('ConnectionParameters initializing from config', function(t) { +test('ConnectionParameters initializing from config', function() { var config = { user: 'brian', database: 'home', @@ -42,8 +40,7 @@ test('ConnectionParameters initializing from config', function(t) { ssl: { asdf: 'blah' } - } + }; var subject = new ConnectionParameters(config); - compare(t, subject, config, 'config'); - t.end(); -}) + compare(subject, config, 'config'); +}); diff --git a/test/unit/connection-parameters/environment-variable-tests.js b/test/unit/connection-parameters/environment-variable-tests.js index 2edc25a..61a0095 100644 --- a/test/unit/connection-parameters/environment-variable-tests.js +++ b/test/unit/connection-parameters/environment-variable-tests.js @@ -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 defaults = require(__dirname + '/../../../lib').defaults; - //clear process.env var realEnv = {}; for(var key in process.env) { @@ -11,7 +10,6 @@ for(var key in process.env) { delete process.env[key]; } - test('ConnectionParameters initialized from environment variables', function(t) { process.env['PGHOST'] = 'local'; process.env['PGUSER'] = 'bmc2'; @@ -20,13 +18,12 @@ test('ConnectionParameters initialized from environment variables', function(t) process.env['PGPASSWORD'] = 'open'; var subject = new ConnectionParameters(); - t.equal(subject.host, 'local', 'env host'); - t.equal(subject.user, 'bmc2', 'env user'); - t.equal(subject.port, 7890, 'env port'); - t.equal(subject.database, 'allyerbase', 'env database'); - t.equal(subject.password, 'open', 'env password'); - t.end(); -}) + assert.equal(subject.host, 'local', 'env host'); + assert.equal(subject.user, 'bmc2', 'env user'); + assert.equal(subject.port, 7890, 'env port'); + assert.equal(subject.database, 'allyerbase', 'env database'); + assert.equal(subject.password, 'open', 'env password'); +}); test('ConnectionParameters initialized from mix', function(t) { delete process.env['PGPASSWORD']; @@ -34,14 +31,13 @@ test('ConnectionParameters initialized from mix', function(t) { var subject = new ConnectionParameters({ user: 'testing', database: 'zugzug' - }) - t.equal(subject.host, 'local', 'env host'); - t.equal(subject.user, 'testing', 'config user'); - t.equal(subject.port, 7890, 'env port'); - t.equal(subject.database, 'zugzug', 'config database'); - t.equal(subject.password, defaults.password, 'defaults password'); - t.end(); -}) + }); + assert.equal(subject.host, 'local', 'env host'); + assert.equal(subject.user, 'testing', 'config user'); + assert.equal(subject.port, 7890, 'env port'); + assert.equal(subject.database, 'zugzug', 'config database'); + assert.equal(subject.password, defaults.password, 'defaults password'); +}); //clear process.env for(var key in process.env) { @@ -51,13 +47,12 @@ for(var key in process.env) { test('connection string parsing', function(t) { var string = 'postgres://brian:pw@boom:381/lala'; var subject = new ConnectionParameters(string); - t.equal(subject.host, 'boom', 'string host'); - t.equal(subject.user, 'brian', 'string user'); - t.equal(subject.password, 'pw', 'string password'); - t.equal(subject.port, 381, 'string port'); - t.equal(subject.database, 'lala', 'string database'); - t.end(); -}) + assert.equal(subject.host, 'boom', 'string host'); + assert.equal(subject.user, 'brian', 'string user'); + assert.equal(subject.password, 'pw', 'string password'); + assert.equal(subject.port, 381, 'string port'); + assert.equal(subject.database, 'lala', 'string database'); +}); //restore process.env for(var key in realEnv) { diff --git a/test/unit/utils-tests.js b/test/unit/utils-tests.js index 53b78b3..03a3d38 100644 --- a/test/unit/utils-tests.js +++ b/test/unit/utils-tests.js @@ -5,7 +5,7 @@ var defaults = require(__dirname + "/../../lib").defaults; //this tests the monkey patching //to ensure comptability with older //versions of node -test("EventEmitter.once", function() { +test("EventEmitter.once", function(t) { //an event emitter var stream = new MemoryStream();