fixed the nolog tests

This commit is contained in:
Gareth Jones 2012-05-09 16:40:27 +10:00
parent 613a077a61
commit 61078e88ef
3 changed files with 85 additions and 86 deletions

View File

@ -45,8 +45,8 @@ function getLogger(logger4js, options) {
// mount safety
if (req._logging) return next();
// nologs
if(nolog && nolog.test(req.originalUrl)) return next();
// nologs
if (nolog && nolog.test(req.originalUrl)) return next();
if (thislogger.isLevelEnabled(level)) {
@ -80,7 +80,7 @@ function getLogger(logger4js, options) {
}
};
}
//ensure next gets always called
next();
};
@ -165,4 +165,4 @@ function createNoLogCondition(nolog, type) {
}
}
exports.connectLogger = getLogger;
exports.connectLogger = getLogger;

View File

@ -12,18 +12,17 @@ function Level(level, levelStr) {
*/
function toLevel(sArg, defaultLevel) {
if (sArg === null) {
return defaultLevel;
if (!sArg) {
return defaultLevel;
}
if (typeof sArg == "string") {
var s = sArg.toUpperCase();
if (module.exports[s]) {
return module.exports[s];
}
else {
return defaultLevel;
}
var s = sArg.toUpperCase();
if (module.exports[s]) {
return module.exports[s];
} else {
return defaultLevel;
}
}
return toLevel(sArg.toString());

View File

@ -40,84 +40,84 @@ function MockResponse(statusCode) {
vows.describe('log4js connect logger').addBatch({
'getConnectLoggerModule': {
topic: function() {
var clm = require('../lib/connect-logger');
return clm;
},
'should return a "connect logger" factory' : function(clm) {
assert.isObject(clm);
},
'nolog String' : {
topic: function(clm) {
var ml = new MockLogger();
var cl = clm.connectLogger(ml, {nolog: "\\.gif"});
return {cl: cl, ml: ml};
topic: function() {
var clm = require('../lib/connect-logger');
return clm;
},
'check unmatch url request': {
topic: function(d){
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
var res = new MockResponse(200);
d.cl(req, res, function() { });
res.end('chunk', 'encoding');
return d.ml.messages;
}
, 'check message': function(messages){
assert.isArray(messages);
assert.equal(messages.length, 1);
assert.equal(messages[0].level, levels.INFO);
assert.include(messages[0].message, 'GET');
assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200');
messages.pop();
'should return a "connect logger" factory' : function(clm) {
assert.isObject(clm);
},
'nolog String' : {
topic: function(clm) {
var ml = new MockLogger();
var cl = clm.connectLogger(ml, { nolog: "\\.gif" });
return {cl: cl, ml: ml};
},
'check unmatch url request': {
topic: function(d){
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
var res = new MockResponse(200);
d.cl(req, res, function() { });
res.end('chunk', 'encoding');
return d.ml.messages;
}
, 'check message': function(messages){
assert.isArray(messages);
assert.equal(messages.length, 1);
assert.equal(messages[0].level, levels.INFO);
assert.include(messages[0].message, 'GET');
assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200');
messages.pop();
}
},
'check match url request': {
},
'check match url request': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
var res = new MockResponse(200);
d.cl(req, res, function() { });
res.end('chunk', 'encoding');
return d.ml.messages;
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
var res = new MockResponse(200);
d.cl(req, res, function() { });
res.end('chunk', 'encoding');
return d.ml.messages;
}
, 'check message': function(messages) {
assert.isArray(messages);
assert.equal(messages.length, 0);
, 'check message': function(messages) {
assert.isArray(messages);
assert.equal(messages.length, 0);
}
}
}
},
'nolog Strings' : {
topic: function(clm) {
var ml = new MockLogger();
var cl = clm.connectLogger(ml, {nolog: "\\.gif|\\.jpe?g"});
return {cl: cl, ml: ml};
},
'check unmatch url request (png)': {
topic: function(d){
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
var res = new MockResponse(200);
d.cl(req, res, function() { });
res.end('chunk', 'encoding');
return d.ml.messages;
}
, 'check message': function(messages){
assert.isArray(messages);
assert.equal(messages.length, 1);
assert.equal(messages[0].level, levels.INFO);
assert.include(messages[0].message, 'GET');
assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200');
messages.pop();
'nolog Strings' : {
topic: function(clm) {
var ml = new MockLogger();
var cl = clm.connectLogger(ml, {nolog: "\\.gif|\\.jpe?g"});
return {cl: cl, ml: ml};
},
'check unmatch url request (png)': {
topic: function(d){
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
var res = new MockResponse(200);
d.cl(req, res, function() { });
res.end('chunk', 'encoding');
return d.ml.messages;
}
, 'check message': function(messages){
assert.isArray(messages);
assert.equal(messages.length, 1);
assert.equal(messages[0].level, levels.INFO);
assert.include(messages[0].message, 'GET');
assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200');
messages.pop();
}
},
},
'check match url request (gif)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
@ -171,7 +171,7 @@ vows.describe('log4js connect logger').addBatch({
messages.pop();
}
},
'check match url request (gif)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
@ -185,7 +185,7 @@ vows.describe('log4js connect logger').addBatch({
assert.equal(messages.length, 0);
}
},
'check match url request (jpeg)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
@ -226,7 +226,7 @@ vows.describe('log4js connect logger').addBatch({
messages.pop();
}
},
'check match url request (gif)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
@ -240,7 +240,7 @@ vows.describe('log4js connect logger').addBatch({
assert.equal(messages.length, 0);
}
},
'check match url request (jpeg)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif