2011-09-05 07:00:41 +08:00
|
|
|
/**
|
|
|
|
* User: simon
|
|
|
|
* Date: 30/08/2011
|
|
|
|
* Time: 13:52
|
|
|
|
* Desc: Loads test specific variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
var _ = require('underscore');
|
2014-03-04 17:46:15 +08:00
|
|
|
var assert = require('assert');
|
2013-04-24 21:10:58 +08:00
|
|
|
var LZMA = require('lzma/lzma_worker.js').LZMA;
|
2011-09-05 07:00:41 +08:00
|
|
|
|
|
|
|
// set environment specific variables
|
2012-07-18 17:00:24 +08:00
|
|
|
global.settings = require(__dirname + '/../../config/settings');
|
|
|
|
global.environment = require(__dirname + '/../../config/environments/test');
|
2011-09-05 07:00:41 +08:00
|
|
|
_.extend(global.settings, global.environment);
|
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) {
|
|
|
|
LZMA.compress(payload, mode,
|
|
|
|
function(ints) {
|
|
|
|
ints = ints.map(function(c) { return String.fromCharCode(c + 128) }).join('')
|
|
|
|
var base64 = new Buffer(ints, 'binary').toString('base64');
|
|
|
|
callback(null, base64);
|
|
|
|
},
|
|
|
|
function(percent) {
|
|
|
|
//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 ?
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
checkNoCache: checkNoCache
|
2013-04-24 21:10:58 +08:00
|
|
|
}
|
2011-09-05 07:00:41 +08:00
|
|
|
|