Port tests to mocha (closes #20)

This commit is contained in:
Sandro Santilli
2012-07-09 16:49:31 +02:00
parent e45d8339c4
commit 2b24e46f6c
5 changed files with 573 additions and 233 deletions
+58 -47
View File
@@ -1,54 +1,65 @@
var assert = require('assert')
var assert = require('../../support/assert')
, _ = require('underscore')
, RedisPool = require('../../../lib/cartodb/redis_pool')
, tests = module.exports = {};
// configure redis pool instance to use in tests
var test_opts = {
max: 10,
idleTimeoutMillis: 1,
reapIntervalMillis: 1
};
suite('redis_pool', function() {
var redis_pool = new RedisPool(test_opts);
// configure redis pool instance to use in tests
var test_opts = {
max: 10,
idleTimeoutMillis: 1,
reapIntervalMillis: 1
};
var redis_pool = new RedisPool(test_opts);
tests['truth'] = function(){
assert.ok(true, 'it is');
};
test('RedisPool object exists', function(done){
assert.ok(RedisPool);
done();
});
test('RedisPool can create new redis_pool objects with default settings', function(done){
var redis_pool = new RedisPool();
done();
});
test('RedisPool can create new redis_pool objects with specific settings', function(done){
var redis_pool = new RedisPool(_.extend({host:'127.0.0.1', port: '6379'}, test_opts));
done();
});
test('pool object has an acquire function', function(done){
var found=false;
var functions = _.functions(redis_pool);
for (var i=0; i<functions.length; ++i) {
if ( functions[i] == 'acquire' ) { found=true; break; }
}
assert.ok(found);
done();
});
test('calling aquire returns a redis client object that can get/set', function(done){
redis_pool.acquire(0, function(err, client){
client.set("key","value");
client.get("key", function(err,data){
assert.equal(data, "value");
redis_pool.release(0, client); // needed to exit tests
done();
})
});
});
test('calling aquire on another DB returns a redis client object that can get/set', function(done){
redis_pool.acquire(2, function(err, client){
client.set("key","value");
client.get("key", function(err,data){
assert.equal(data, "value");
redis_pool.release(2, client); // needed to exit tests
done();
})
});
});
tests['RedisPool object exists'] = function(){
assert.ok(RedisPool);
};
tests['RedisPool can create new redis_pool objects with default settings'] = function(){
var redis_pool = new RedisPool();
};
tests['RedisPool can create new redis_pool objects with specific settings'] = function(){
var redis_pool = new RedisPool(_.extend({host:'127.0.0.1', port: '6379'}, test_opts));
};
tests['pool object has an aquire function'] = function(){
assert.includes(_.functions(redis_pool), 'acquire');
};
tests['calling aquire returns a redis client object that can get/set'] = function(){
redis_pool.acquire(0, function(err, client){
client.set("key","value");
client.get("key", function(err,data){
assert.eql(data, "value");
redis_pool.release(0, client); // needed to exit tests
})
});
};
tests['calling aquire on another DB returns a redis client object that can get/set'] = function(){
redis_pool.acquire(2, function(err, client){
client.set("key","value");
client.get("key", function(err,data){
assert.eql(data, "value");
redis_pool.release(2, client); // needed to exit tests
})
});
};
});