Skip to content

Commit

Permalink
Moved more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Mar 11, 2013
1 parent 6599d59 commit 3611c2c
Show file tree
Hide file tree
Showing 8 changed files with 1,001 additions and 2 deletions.
159 changes: 159 additions & 0 deletions new_tests/functional/connection_tests.js
Expand Up @@ -59,3 +59,162 @@ exports['Should fail to connect using non-domain socket with undefined port'] =
test.ok(/port must be specified/.test(error));
test.done();
}

/**
* @ignore
*/
function connectionTester(test, testName, callback) {
return function(err, db) {
test.equal(err, null);
db.collection(testName, function(err, collection) {
test.equal(err, null);
var doc = {foo:123};
collection.insert({foo:123}, {w:1}, function(err, docs) {
test.equal(err, null);
db.dropDatabase(function(err, done) {
db.close();
test.equal(err, null);
test.ok(done);
if(callback) return callback(db);
test.done();
});
});
});
};
};

/**
* @ignore
*/
exports.testConnectNoOptions = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;

connect(configuration.url(), connectionTester(test, 'testConnectNoOptions', function(db) {
test.done();
}));
};

/**
* @ignore
*/
exports.testConnectDbOptions = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;

connect(configuration.url(),
{ db: {native_parser: (process.env['TEST_NATIVE'] != null)} },
connectionTester(test, 'testConnectDbOptions', function(db) {
test.equal(process.env['TEST_NATIVE'] != null, db.native_parser);
test.done();
}));
};

/**
* @ignore
*/
exports.testConnectServerOptions = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;

connect(configuration.url(),
{ server: {auto_reconnect: true, poolSize: 4} },
connectionTester(test, 'testConnectServerOptions', function(db) {
test.equal(4, db.serverConfig.poolSize);
test.equal(true, db.serverConfig.autoReconnect);
test.done();
}));
};

/**
* @ignore
*/
exports.testConnectAllOptions = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;

connect(configuration.url(),
{ server: {auto_reconnect: true, poolSize: 4},
db: {native_parser: (process.env['TEST_NATIVE'] != null)} },
connectionTester(test, 'testConnectAllOptions', function(db) {
test.equal(process.env['TEST_NATIVE'] != null, db.native_parser);
test.equal(4, db.serverConfig.poolSize);
test.equal(true, db.serverConfig.autoReconnect);
test.done();
}));
};

/**
* @ignore
*/
exports.testConnectGoodAuth = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;
var user = 'testConnectGoodAuth', password = 'password';
// First add a user.
connect(configuration.url(), function(err, db) {
test.equal(err, null);
db.addUser(user, password, function(err, result) {
test.equal(err, null);
db.close();
restOfTest();
});
});

function restOfTest() {
connect(configuration.url(user, password), connectionTester(test, 'testConnectGoodAuth', function(db) {
test.equal(false, db.safe);
test.done();
}));
}
};

/**
* @ignore
*/
exports.testConnectBadAuth = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;

connect(configuration.url('slithy', 'toves'), function(err, db) {
test.ok(err);
test.equal(null, db);
test.done();
});
};

/**
* @ignore
*/
exports.testConnectThrowsNoCallbackProvided = function(configuration, test) {
var connect = configuration.getMongoPackage().connect;

test.throws(function() {
var db = connect(configuration.url());
});
test.done();
};

/**
* @ignore
*/
exports.testConnectBadUrl = function(configuration, test) {
test.throws(function() {
connect('mangodb://localhost:27017/test?safe=false', function(err, db) {
test.ok(false, 'Bad URL!');
});
});
test.done();
};

/**
* Example of a simple url connection string, with no acknowledgement of writes.
*
* @_class db
* @_function Db.connect
*/
exports.shouldCorrectlyDoSimpleCountExamples = function(configuration, test) {
var Db = configuration.getMongoPackage().Db;

// Connect to the server
Db.connect(configuration.url(), function(err, db) {
test.equal(null, err);

db.close();
test.done();
});
}
12 changes: 12 additions & 0 deletions new_tests/functional/contexts/index.js
@@ -0,0 +1,12 @@

var vm = require('vm')
var fs = require('fs')
var path = require('path')

var shared = require('./shared');
var ind = fs.readFileSync(__dirname + '/other.js', 'utf8');
var filename = path.resolve(__dirname + '/other.js');
var script = vm.createScript(ind, filename);
script.runInNewContext({ require: require, __filename: filename });

module.exports = exports = shared;
11 changes: 11 additions & 0 deletions new_tests/functional/contexts/other.js
@@ -0,0 +1,11 @@

var shared = require('./shared');
shared.object = { name: 1, age: -1 };
shared.array = ['name']
shared.string = 'woot'
shared.string2 = String('woot')
shared.number = 3
shared.number2 = Number(3)
shared.bool = true
shared.bool2 = Boolean(true)
shared.date = new Date;
2 changes: 2 additions & 0 deletions new_tests/functional/contexts/shared.js
@@ -0,0 +1,2 @@

module.exports = exports = {};

0 comments on commit 3611c2c

Please sign in to comment.