add cli parsing to all tests

This commit is contained in:
brianc 2010-10-25 01:30:14 -05:00
parent 32c49343d2
commit ccc04cdd0b
5 changed files with 59 additions and 42 deletions

View File

@ -1,42 +1,5 @@
var config = {};
var sys = require('sys'); var sys = require('sys');
var args = process.argv; var config = require(__dirname + '/../test/cli');
for(var i = 0; i < args.length; i++) {
switch(args[i].toLowerCase()) {
case '-u':
case '--user':
config.user = args[++i];
break;
case '--password':
config.password = args[++i];
throw new Error("Passwords not supported yet");
break;
case '-d':
case '--database':
config.database = args[++i];
break;
case '-p':
case '--port':
config.port = args[++i];
break;
case '-h':
case '--host':
config.host = args[++i];
break;
case '--down':
config.down = true;
break;
default:
break;
}
}
var log = function(keys) {
keys.forEach(function(key) {
console.log(key + ": '" + config[key] + "'");
});
}
log(['user','password','database','port','host'])
var pg = require(__dirname + '/../lib'); var pg = require(__dirname + '/../lib');
var con = new pg.Connection(); var con = new pg.Connection();
var people var people

46
test/cli.js Normal file
View File

@ -0,0 +1,46 @@
var config = {
port: 5432,
host: 'localhost',
user: 'postgres',
database: 'postgres',
password: ''
};
var args = process.argv;
for(var i = 0; i < args.length; i++) {
switch(args[i].toLowerCase()) {
case '-u':
case '--user':
config.user = args[++i];
break;
case '--password':
config.password = args[++i];
throw new Error("Passwords not supported yet");
break;
case '-d':
case '--database':
config.database = args[++i];
break;
case '-p':
case '--port':
config.port = args[++i];
break;
case '-h':
case '--host':
config.host = args[++i];
break;
case '--down':
config.down = true;
break;
default:
break;
}
}
var log = function(keys) {
keys.forEach(function(key) {
console.log(key + ": '" + config[key] + "'");
});
}
log(['user','password','database','port','host'])
module.exports = config;

View File

@ -1,11 +1,11 @@
var net = require('net'); var net = require('net');
require(__dirname+'/../test-helper'); var helper = require(__dirname+'/../test-helper');
var authConnect = function(username, database, callback) { var authConnect = function(username, database, callback) {
if(typeof username === 'function') { if(typeof username === 'function') {
callback = username; callback = username;
username = 'brian'; username = helper.args.user;
database = 'postgres'; database = helper.args.database;
} }
var connection = new Connection({stream: new net.Stream()}); var connection = new Connection({stream: new net.Stream()});
connection.connect('5432','localhost'); connection.connect('5432','localhost');

View File

@ -1 +1,3 @@
require(__dirname + '/../test-helper'); var helper = require(__dirname + '/../test-helper');
//export parent helper stuffs
module.exports = { args: helper.args };

View File

@ -8,6 +8,7 @@ EventEmitter = require('events').EventEmitter;
BufferList = require('buffer-list') BufferList = require('buffer-list')
buffers = require(__dirname + '/test-buffers'); buffers = require(__dirname + '/test-buffers');
Connection = require('connection'); Connection = require('connection');
var args = require(__dirname + '/cli');
assert.same = function(actual, expected) { assert.same = function(actual, expected) {
for(var key in expected) { for(var key in expected) {
@ -84,6 +85,7 @@ test = function(name, action) {
test.errors.push({name: name, e: e}); test.errors.push({name: name, e: e});
} }
}; };
test.assertCount = test.assertCount || 0; test.assertCount = test.assertCount || 0;
test.testCount = test.testCount || 0; test.testCount = test.testCount || 0;
test.ignored = test.ignored || []; test.ignored = test.ignored || [];
@ -104,3 +106,7 @@ process.on('exit', function() {
throw error.e; throw error.e;
}); });
}); });
module.exports = {
args: args
};