mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
121 lines
3.4 KiB
JavaScript
121 lines
3.4 KiB
JavaScript
// Generated by CoffeeScript 1.6.3
|
|
(function() {
|
|
var fs, getLog, path,
|
|
_this = this;
|
|
|
|
path = require('path');
|
|
|
|
fs = require('fs');
|
|
|
|
getLog = function(strPath, cb) {
|
|
var fWait,
|
|
_this = this;
|
|
fWait = function() {
|
|
var arrStr, fConvertRow, i, row, str, _i, _len;
|
|
str = fs.readFileSync(path.resolve(strPath), 'utf-8');
|
|
arrStr = str.split("\n");
|
|
fConvertRow = function(row) {
|
|
try {
|
|
return JSON.parse(row);
|
|
} catch (_error) {}
|
|
};
|
|
for (i = _i = 0, _len = arrStr.length; _i < _len; i = ++_i) {
|
|
row = arrStr[i];
|
|
arrStr[i] = fConvertRow(row);
|
|
}
|
|
return cb(arrStr.slice(0, arrStr.length - 1));
|
|
};
|
|
return setTimeout(fWait, 100);
|
|
};
|
|
|
|
exports.setUp = function(cb) {
|
|
_this.stdPath = path.resolve(__dirname, '..', 'logs', 'server.log');
|
|
try {
|
|
fs.unlinkSync(_this.stdPath);
|
|
} catch (_error) {}
|
|
_this.logger = require(path.join('..', 'js-coffee', 'logging'));
|
|
return cb();
|
|
};
|
|
|
|
exports.testCreate = function(test) {
|
|
var args, arrLogs, log;
|
|
test.expect(2);
|
|
arrLogs = ['TL | testInitIO - info', 'TL | testInitIO - warn', 'TL | testInitIO - error'];
|
|
args = {};
|
|
args['io-level'] = 'error';
|
|
log = _this.logger.getLogger(args);
|
|
log.info(arrLogs[0]);
|
|
log.warn(arrLogs[1]);
|
|
log.error(arrLogs[2]);
|
|
test.ok(fs.existsSync(_this.stdPath), 'Log file does not exist!');
|
|
return getLog(_this.stdPath, function(arr) {
|
|
var allCorrect, i, o, _i, _len;
|
|
allCorrect = true;
|
|
for (i = _i = 0, _len = arr.length; _i < _len; i = ++_i) {
|
|
o = arr[i];
|
|
if (o.msg === !arrLogs[i]) {
|
|
allCorrect = false;
|
|
}
|
|
}
|
|
test.ok(allCorrect, 'Log file does not contain the correct entries!');
|
|
return test.done();
|
|
});
|
|
};
|
|
|
|
exports.testNoLog = function(test) {
|
|
var fWait, log;
|
|
test.expect(1);
|
|
log = _this.logger.getLogger({
|
|
nolog: true
|
|
});
|
|
log.info('TL | test 1');
|
|
fWait = function() {
|
|
test.ok(!fs.existsSync(_this.stdPath), 'Log file does still exist!');
|
|
return test.done();
|
|
};
|
|
return setTimeout(fWait, 100);
|
|
};
|
|
|
|
exports.testCustomPath = function(test) {
|
|
var args, fWait, log, strInfo, strPath;
|
|
test.expect(2);
|
|
strInfo = 'TL | custom path test 1';
|
|
strPath = 'testing/test.log';
|
|
args = {};
|
|
args['file-path'] = strPath;
|
|
args['io-level'] = 'error';
|
|
log = _this.logger.getLogger(args);
|
|
log.info(strInfo);
|
|
fWait = function() {
|
|
test.ok(fs.existsSync(strPath), 'Custom log file does not exist!');
|
|
return getLog(strPath, function(arr) {
|
|
test.ok(arr[0].msg === strInfo, 'Custom log file not correct!');
|
|
return test.done();
|
|
});
|
|
};
|
|
return setTimeout(fWait, 100);
|
|
};
|
|
|
|
exports.testWrongPath = function(test) {
|
|
var args, fWait, log, strInfo, strPath;
|
|
test.expect(1);
|
|
strInfo = 'TL | custom path test 1';
|
|
strPath = 'strange/path/to/test.log';
|
|
args = {};
|
|
args['file-path'] = strPath;
|
|
args['io-level'] = 'error';
|
|
console.log('getting logger');
|
|
log = _this.logger.getLogger(args);
|
|
console.log('logging');
|
|
log.info(strInfo);
|
|
console.log('logged');
|
|
fWait = function() {
|
|
console.log('waited');
|
|
test.ok(true, 'Custom log file does not exist!');
|
|
return test.done();
|
|
};
|
|
console.log('timing');
|
|
return setTimeout(fWait, 100);
|
|
};
|
|
|
|
}).call(this);
|