Skip to content
Browse files

Misc Unit tests fixes & optimizations

  • Loading branch information...
1 parent 97c1f06 commit 84e9f2b837dca66778f79b1a2f63e1c759e99ee2 @DrBenton committed Sep 16, 2012
Showing with 37 additions and 46 deletions.
  1. +3 −31 test/adapters-simple-operations.js
  2. +2 −1 test/all.js
  3. +30 −1 test/config.js
  4. +2 −13 test/db-select.js
View
34 test/adapters-simple-operations.js
@@ -25,14 +25,6 @@ var vows = require('vows')
, nodeDBI = require('../index.js');
-var testedAdapterNames = [
- 'mysql-libmysqlclient',
- 'mysql',
- 'sqlite3',
- 'pg'
-];
-
-
var getTableCreationSql = function( adapterName, tableName )
{
@@ -91,33 +83,13 @@ var getTableCreationSql = function( adapterName, tableName )
};
-var getDbConfig = function( adapterName )
-{
- switch ( adapterName )
- {
-
- case 'mysql-libmysqlclient':
- case 'mysql':
- return config.mysql;
-
- case 'sqlite3':
- return config.sqlite;
-
- case 'pg':
- return config.pgsql;
-
- default:
- throw new Error('Unknown Adapter "'+adapterName+'" !');
-
- }
-};
-
var firstInsertedUser = {
first_name: 'FirstName 1',
last_name: 'LastName 1',
birth_date: new Date(),
enabled: 1
};
+
// We don't wanna deal with GMT shiftings, so let's force all the Date components in UTC... :-/
firstInsertedUser.birth_date.setYear(1951);
firstInsertedUser.birth_date.setUTCMonth(3);
@@ -154,7 +126,7 @@ var DBExpr = nodeDBI.DBExpr;
var adapterTestSuite = function( adapterName, callback )
{
- var dbWrapper = new DBWrapper( adapterName, getDbConfig(adapterName) );
+ var dbWrapper = new DBWrapper( adapterName, config.getDbConfig(adapterName) );
dbWrapper.connect();
var tableName = 'test_' + ( 100 + Math.round( Math.random() * 5000 ) );
@@ -460,7 +432,7 @@ var adapterTestSuite = function( adapterName, callback )
var runTest = function( callback )
{
- async.forEachSeries( testedAdapterNames, adapterTestSuite, function(err){
+ async.forEachSeries( config.testedAdapterNames, adapterTestSuite, function(err){
callback && callback( err );
});
View
3 test/all.js
@@ -21,5 +21,6 @@ var allTests = [
async.series( allTests, function(err) {
if( err )
throw err;
- setTimeout( function() { process.exit(0); }, 500 );
+ else
+ setTimeout( function() { process.exit(0); }, 500 );
});
View
31 test/config.js
@@ -1,6 +1,6 @@
// @see /.travis.yml
-module.exports = {
+var connectionParams = {
mysql: {
host: '127.0.0.1',
@@ -21,3 +21,32 @@ module.exports = {
}
};
+
+module.exports.getDbConfig = function( adapterName )
+{
+ switch ( adapterName )
+ {
+
+ case 'mysql-libmysqlclient':
+ case 'mysql':
+ return connectionParams.mysql;
+
+ case 'sqlite3':
+ return connectionParams.sqlite;
+
+ case 'pg':
+ return connectionParams.pgsql;
+
+ default:
+ throw new Error('Unknown Adapter "'+adapterName+'" !');
+
+ }
+};
+
+
+module.exports.testedAdapterNames = [
+ 'mysql-libmysqlclient',
+ 'mysql',
+ 'sqlite3',
+ 'pg'
+];
View
15 test/db-select.js
@@ -13,14 +13,6 @@ var vows = require('vows')
, nodeDBI = require('../index.js');
-var testedAdapterNames = [
- 'mysql-libmysqlclient',
- 'mysql',
- 'sqlite3',
- 'pg'
-];
-
-
var DBWrapper = nodeDBI.DBWrapper;
var DBExpr = nodeDBI.DBExpr;
@@ -30,7 +22,7 @@ var DBExpr = nodeDBI.DBExpr;
var adapterTestSuite = function( adapterName, callback )
{
- var dbWrapper = new DBWrapper( adapterName, config );
+ var dbWrapper = new DBWrapper( adapterName, config.getDbConfig(adapterName) );
var tableName = 'test_' + ( 100 + Math.round( Math.random() * 5000 ) );
@@ -415,11 +407,8 @@ var adapterTestSuite = function( adapterName, callback )
var runTest = function( callback )
{
- async.forEachSeries( testedAdapterNames, adapterTestSuite, function(err){
- if (err )
+ async.forEachSeries( config.testedAdapterNames, adapterTestSuite, function(err){
callback && callback( err );
- else
- callback && callback( null );
});
};

0 comments on commit 84e9f2b

Please sign in to comment.
Something went wrong with that request. Please try again.