2011-09-05 07:00:41 +08:00
|
|
|
/**
|
|
|
|
* User: simon
|
|
|
|
* Date: 30/08/2011
|
|
|
|
* Time: 13:52
|
|
|
|
* Desc: Loads test specific variables
|
|
|
|
*/
|
|
|
|
|
2014-03-04 17:46:15 +08:00
|
|
|
var assert = require('assert');
|
2014-08-15 01:54:45 +08:00
|
|
|
var LZMA = require('lzma').LZMA;
|
|
|
|
|
|
|
|
var lzmaWorker = new LZMA();
|
2011-09-05 07:00:41 +08:00
|
|
|
|
|
|
|
// set environment specific variables
|
2012-07-18 17:00:24 +08:00
|
|
|
global.environment = require(__dirname + '/../../config/environments/test');
|
2014-02-28 23:14:44 +08:00
|
|
|
process.env.NODE_ENV = 'test';
|
2011-09-05 07:00:41 +08:00
|
|
|
|
|
|
|
|
2013-04-24 21:10:58 +08:00
|
|
|
// Utility function to compress & encode LZMA
|
|
|
|
function lzma_compress_to_base64(payload, mode, callback) {
|
2014-08-15 01:54:45 +08:00
|
|
|
lzmaWorker.compress(payload, mode,
|
2013-04-24 21:10:58 +08:00
|
|
|
function(ints) {
|
2015-07-05 02:41:22 +08:00
|
|
|
ints = ints.map(function(c) { return String.fromCharCode(c + 128); }).join('');
|
2013-04-24 21:10:58 +08:00
|
|
|
var base64 = new Buffer(ints, 'binary').toString('base64');
|
|
|
|
callback(null, base64);
|
|
|
|
},
|
2015-07-05 02:41:22 +08:00
|
|
|
function(/*percent*/) {
|
2013-04-24 21:10:58 +08:00
|
|
|
//console.log("Compressing: " + percent + "%");
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-03-04 17:46:15 +08:00
|
|
|
// Check that the response headers do not request caching
|
|
|
|
// Throws on failure
|
|
|
|
function checkNoCache(res) {
|
|
|
|
assert.ok(!res.headers.hasOwnProperty('x-cache-channel'));
|
|
|
|
assert.ok(!res.headers.hasOwnProperty('cache-control')); // is this correct ?
|
|
|
|
assert.ok(!res.headers.hasOwnProperty('last-modified')); // is this correct ?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 19:13:00 +08:00
|
|
|
/**
|
|
|
|
* Check that the response headers do not request caching
|
|
|
|
* @see checkNoCache
|
|
|
|
* @param res
|
|
|
|
*/
|
|
|
|
function checkCache(res) {
|
|
|
|
assert.ok(res.headers.hasOwnProperty('x-cache-channel'));
|
|
|
|
assert.ok(res.headers.hasOwnProperty('cache-control'));
|
|
|
|
assert.ok(res.headers.hasOwnProperty('last-modified'));
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:02:13 +08:00
|
|
|
function checkSurrogateKey(res, expectedKey) {
|
|
|
|
assert.ok(res.headers.hasOwnProperty('surrogate-key'));
|
|
|
|
assert.equal(res.headers['surrogate-key'], expectedKey);
|
|
|
|
}
|
|
|
|
|
2015-07-05 02:41:22 +08:00
|
|
|
//var _ = require('underscore');
|
|
|
|
//var redis = require('redis');
|
|
|
|
// global afterEach to capture tests that leave keys in redis
|
|
|
|
//afterEach(function(done) {
|
|
|
|
// var redisClient = redis.createClient(global.environment.redis.port);
|
|
|
|
// // Check that we start with an empty redis db
|
|
|
|
// redisClient.keys("*", function(err, keys) {
|
|
|
|
// if ( err ) {
|
|
|
|
// return done(err);
|
|
|
|
// }
|
|
|
|
// assert.equal(keys.length, 0, "test left objects in redis:\n" + keys.join("\n"));
|
|
|
|
// redisClient.flushall(done);
|
|
|
|
// });
|
|
|
|
//});
|
|
|
|
|
2014-06-24 19:13:00 +08:00
|
|
|
|
2013-04-24 21:10:58 +08:00
|
|
|
module.exports = {
|
2014-03-04 17:46:15 +08:00
|
|
|
lzma_compress_to_base64: lzma_compress_to_base64,
|
2014-06-24 19:13:00 +08:00
|
|
|
checkNoCache: checkNoCache,
|
2015-01-24 00:02:13 +08:00
|
|
|
checkSurrogateKey: checkSurrogateKey,
|
2014-06-24 19:13:00 +08:00
|
|
|
checkCache: checkCache
|
|
|
|
};
|
2011-09-05 07:00:41 +08:00
|
|
|
|