more linting

This commit is contained in:
Gareth Jones 2013-05-26 17:15:10 +10:00
parent 50b676dec5
commit 6a9441d261

View File

@ -1,3 +1,4 @@
"use strict";
var vows = require('vows') var vows = require('vows')
, assert = require('assert') , assert = require('assert')
, levels = require('../lib/levels'); , levels = require('../lib/levels');
@ -8,7 +9,7 @@ function MockLogger() {
this.messages = []; this.messages = [];
this.log = function(level, message, exception) { this.log = function(level, message, exception) {
that.messages.push({ level: level, message: message }); that.messages.push({ level: level, message: message });
}; };
this.isLevelEnabled = function(level) { this.isLevelEnabled = function(level) {
@ -20,7 +21,7 @@ function MockLogger() {
} }
function MockRequest(remoteAddr, method, originalUrl) { function MockRequest(remoteAddr, method, originalUrl) {
this.socket = { remoteAddress: remoteAddr }; this.socket = { remoteAddress: remoteAddr };
this.originalUrl = originalUrl; this.originalUrl = originalUrl;
this.method = method; this.method = method;
@ -34,226 +35,226 @@ function MockResponse(statusCode) {
this.statusCode = statusCode; this.statusCode = statusCode;
this.end = function(chunk, encoding) { this.end = function(chunk, encoding) {
}; };
} }
vows.describe('log4js connect logger').addBatch({ vows.describe('log4js connect logger').addBatch({
'getConnectLoggerModule': { 'getConnectLoggerModule': {
topic: function() { topic: function() {
var clm = require('../lib/connect-logger'); var clm = require('../lib/connect-logger');
return clm; 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};
},
'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.ok(levels.INFO.isEqualTo(messages[0].level));
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': {
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;
}
, 'check message': function(messages) {
assert.isArray(messages);
assert.equal(messages.length, 0);
}
}
}, },
'nolog Strings' : { 'should return a "connect logger" factory' : function(clm) {
topic: function(clm) { assert.isObject(clm);
var ml = new MockLogger(); },
var cl = clm.connectLogger(ml, {nolog: "\\.gif|\\.jpe?g"});
return {cl: cl, ml: ml};
},
'check unmatch url request (png)': { 'nolog String' : {
topic: function(d){ topic: function(clm) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif var ml = new MockLogger();
var res = new MockResponse(200); var cl = clm.connectLogger(ml, { nolog: "\\.gif" });
d.cl(req, res, function() { }); return {cl: cl, ml: ml};
res.end('chunk', 'encoding'); },
return d.ml.messages;
} 'check unmatch url request': {
, 'check message': function(messages){ topic: function(d){
assert.isArray(messages); var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
assert.equal(messages.length, 1); var res = new MockResponse(200);
assert.ok(levels.INFO.isEqualTo(messages[0].level)); d.cl(req, res, function() { });
assert.include(messages[0].message, 'GET'); res.end('chunk', 'encoding');
assert.include(messages[0].message, 'http://url'); return d.ml.messages;
assert.include(messages[0].message, 'my.remote.addr'); },
assert.include(messages[0].message, '200'); 'check message': function(messages){
messages.pop(); assert.isArray(messages);
} assert.equal(messages.length, 1);
}, assert.ok(levels.INFO.isEqualTo(messages[0].level));
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': {
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;
},
'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.ok(levels.INFO.isEqualTo(messages[0].level));
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)': { 'check match url request (gif)': {
topic: function(d) { topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
var res = new MockResponse(200); var res = new MockResponse(200);
d.cl(req, res, function() { }); d.cl(req, res, function() { });
res.end('chunk', 'encoding'); res.end('chunk', 'encoding');
return d.ml.messages; return d.ml.messages;
} },
, 'check message': function(messages) { 'check message': function(messages) {
assert.isArray(messages); assert.isArray(messages);
assert.equal(messages.length, 0); assert.equal(messages.length, 0);
} }
}, },
'check match url request (jpeg)': { 'check match url request (jpeg)': {
topic: function(d) { topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
var res = new MockResponse(200); var res = new MockResponse(200);
d.cl(req, res, function() { }); d.cl(req, res, function() { });
res.end('chunk', 'encoding'); res.end('chunk', 'encoding');
return d.ml.messages; return d.ml.messages;
} },
, 'check message': function(messages) { 'check message': function(messages) {
assert.isArray(messages); assert.isArray(messages);
assert.equal(messages.length, 0); assert.equal(messages.length, 0);
} }
} }
}, },
'nolog Array<String>' : { 'nolog Array<String>' : {
topic: function(clm) { topic: function(clm) {
var ml = new MockLogger(); var ml = new MockLogger();
var cl = clm.connectLogger(ml, {nolog: ["\\.gif", "\\.jpe?g"]}); 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.ok(levels.INFO.isEqualTo(messages[0].level));
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
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 match url request (jpeg)': {
topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // 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);
}
},
},
'nolog RegExp' : {
topic: function(clm) {
var ml = new MockLogger();
var cl = clm.connectLogger(ml, {nolog: /\.gif|\.jpe?g/});
return {cl: cl, ml: ml}; return {cl: cl, ml: ml};
}, },
'check unmatch url request (png)': { 'check unmatch url request (png)': {
topic: function(d){ topic: function(d){
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.png'); // not gif
var res = new MockResponse(200); var res = new MockResponse(200);
d.cl(req, res, function() { }); d.cl(req, res, function() { });
res.end('chunk', 'encoding'); res.end('chunk', 'encoding');
return d.ml.messages; return d.ml.messages;
} },
, 'check message': function(messages){ 'check message': function(messages){
assert.isArray(messages); assert.isArray(messages);
assert.equal(messages.length, 1); assert.equal(messages.length, 1);
assert.ok(levels.INFO.isEqualTo(messages[0].level)); assert.ok(levels.INFO.isEqualTo(messages[0].level));
assert.include(messages[0].message, 'GET'); assert.include(messages[0].message, 'GET');
assert.include(messages[0].message, 'http://url'); assert.include(messages[0].message, 'http://url');
assert.include(messages[0].message, 'my.remote.addr'); assert.include(messages[0].message, 'my.remote.addr');
assert.include(messages[0].message, '200'); assert.include(messages[0].message, '200');
messages.pop(); messages.pop();
} }
},
'check match url request (gif)': {
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;
}
, 'check message': function(messages) {
assert.isArray(messages);
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
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);
}
},
},
'nolog RegExp' : {
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.ok(levels.INFO.isEqualTo(messages[0].level));
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)': { 'check match url request (gif)': {
topic: function(d) { topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.gif'); // gif
var res = new MockResponse(200); var res = new MockResponse(200);
d.cl(req, res, function() { }); d.cl(req, res, function() { });
res.end('chunk', 'encoding'); res.end('chunk', 'encoding');
return d.ml.messages; return d.ml.messages;
} },
, 'check message': function(messages) { 'check message': function(messages) {
assert.isArray(messages); assert.isArray(messages);
assert.equal(messages.length, 0); assert.equal(messages.length, 0);
} }
}, },
'check match url request (jpeg)': { 'check match url request (jpeg)': {
topic: function(d) { topic: function(d) {
var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif var req = new MockRequest('my.remote.addr', 'GET', 'http://url/hoge.jpeg'); // gif
var res = new MockResponse(200); var res = new MockResponse(200);
d.cl(req, res, function() { }); d.cl(req, res, function() { });
res.end('chunk', 'encoding'); res.end('chunk', 'encoding');
return d.ml.messages; return d.ml.messages;
} },
, 'check message': function(messages) { 'check message': function(messages) {
assert.isArray(messages); assert.isArray(messages);
assert.equal(messages.length, 0); assert.equal(messages.length, 0);
} }
}, }
} }
} }