From 5a2771cfed9b946faf5879f6f411d8da8b074680 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 24 Aug 2013 20:51:25 +1000 Subject: [PATCH] moved nolog test to log4js-connect --- test/nolog-test.js | 261 --------------------------------------------- 1 file changed, 261 deletions(-) delete mode 100644 test/nolog-test.js diff --git a/test/nolog-test.js b/test/nolog-test.js deleted file mode 100644 index 3c1a8e7..0000000 --- a/test/nolog-test.js +++ /dev/null @@ -1,261 +0,0 @@ -"use strict"; -var vows = require('vows') -, assert = require('assert') -, levels = require('../lib/levels'); - -function MockLogger() { - - var that = this; - this.messages = []; - - this.log = function(level, message, exception) { - that.messages.push({ level: level, message: message }); - }; - - this.isLevelEnabled = function(level) { - return level.isGreaterThanOrEqualTo(that.level); - }; - - this.level = levels.TRACE; - -} - -function MockRequest(remoteAddr, method, originalUrl) { - - this.socket = { remoteAddress: remoteAddr }; - this.originalUrl = originalUrl; - this.method = method; - this.httpVersionMajor = '5'; - this.httpVersionMinor = '0'; - this.headers = {}; -} - -function MockResponse(statusCode) { - - this.statusCode = statusCode; - - this.end = function(chunk, encoding) { - - }; -} - -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}; - }, - - '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' : { - 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)': { - 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 Array' : { - 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)': { - 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)': { - 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); - } - } - } - } - -}).export(module);