Skip to content

Instantly share code, notes, and snippets.

@sreeix
Created February 23, 2012 11:47
Show Gist options
  • Save sreeix/1892518 to your computer and use it in GitHub Desktop.
Save sreeix/1892518 to your computer and use it in GitHub Desktop.
Fake Redis in test
var testy = require('../testy')
var RedisProxy = require('../../lib/redis_proxy')
describe('RedisProxy', function() {
it('raises exception when no rediss available', function() {
(function(){
new RedisProxy({})
}).should.throw();
});
it('should proxy existing redis', function() {
var fake = testy.createRedis(6389);
(function() {
new RedisProxy({"servers": [{"host": "localhost","port": 6389}]})
}).should.not.throw();
fake.close();
});
});
var net = require('net');
exports.createRedis = function(port){
var server = net.createServer(function (socket) {
socket.on('end', function() {
console.log('disconnect');
});
socket.on('data', function(data) {
console.log("DATA: "+data);
});
});
server.listen(port);
return server;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment