2012-07-09 22:49:31 +08:00
|
|
|
var assert = require('../support/assert');
|
2011-12-01 17:32:27 +08:00
|
|
|
var net = require('net');
|
2012-07-18 17:00:24 +08:00
|
|
|
require(__dirname + '/../support/test_helper');
|
2011-12-01 17:32:27 +08:00
|
|
|
var CacheValidator = require(__dirname + '/../../lib/cartodb/cache_validator');
|
|
|
|
var tests = module.exports = {};
|
|
|
|
|
2012-07-09 22:12:03 +08:00
|
|
|
function VarnishEmu(on_cmd_recieved, test_callback) {
|
2011-12-01 17:32:27 +08:00
|
|
|
var self = this;
|
|
|
|
var welcome_msg = 'hi, im a varnish emu, right?';
|
|
|
|
|
|
|
|
self.commands_recieved = [];
|
|
|
|
|
|
|
|
var server = net.createServer(function (socket) {
|
|
|
|
var command = '';
|
|
|
|
socket.write("200 " + welcome_msg.length + "\n");
|
|
|
|
socket.write(welcome_msg);
|
2012-07-09 21:56:47 +08:00
|
|
|
socket.on('data', function(data) {
|
2011-12-01 17:32:27 +08:00
|
|
|
self.commands_recieved.push(data);
|
|
|
|
on_cmd_recieved && on_cmd_recieved(self.commands_recieved);
|
|
|
|
socket.write('200 0\n');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
server.listen(1337, "127.0.0.1");
|
2012-07-09 22:12:03 +08:00
|
|
|
|
|
|
|
server.on('listening', function(){
|
|
|
|
test_callback();
|
|
|
|
});
|
2011-12-01 17:32:27 +08:00
|
|
|
}
|
|
|
|
|
2012-07-09 22:49:31 +08:00
|
|
|
suite('cache_validator', function() {
|
|
|
|
|
|
|
|
test('should call purge on varnish when invalidate database', function(done) {
|
|
|
|
var varnish = new VarnishEmu(function(cmds) {
|
|
|
|
assert.ok(cmds.length == 1);
|
|
|
|
assert.equal('purge obj.http.X-Cache-Channel ~ \"^test_db:(.*test_cache.*)|(table)$\"\n', cmds[0].toString('utf8'));
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
CacheValidator.init('localhost', 1337);
|
|
|
|
CacheValidator.invalidate_db('test_db', 'test_cache');
|
|
|
|
});
|
2011-12-01 17:32:27 +08:00
|
|
|
});
|
2012-07-09 22:49:31 +08:00
|
|
|
|
|
|
|
});
|