mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 18:52:50 +00:00
updated package.json
This commit is contained in:
39
node_modules/winston/test/transports/console-test.js
generated
vendored
Normal file
39
node_modules/winston/test/transports/console-test.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* console-test.js: Tests for instances of the Console transport
|
||||
*
|
||||
* (C) 2010 Charlie Robbins
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var npmTransport = new (winston.transports.Console)(),
|
||||
syslogTransport = new (winston.transports.Console)({ levels: winston.config.syslog.levels });
|
||||
|
||||
vows.describe('winston/transports/console').addBatch({
|
||||
"An instance of the Console Transport": {
|
||||
"with npm levels": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertConsole(npmTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(npmTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
},
|
||||
"with syslog levels": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertConsole(syslogTransport);
|
||||
},
|
||||
"the log() method": helpers.testSyslogLevels(syslogTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
62
node_modules/winston/test/transports/daily-rotate-file-test.js
generated
vendored
Normal file
62
node_modules/winston/test/transports/daily-rotate-file-test.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* file-test.js: Tests for instances of the Daily Rotate File transport
|
||||
*
|
||||
* (C) 2010 Charlie Robbins
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
vows = require('vows'),
|
||||
fs = require('fs'),
|
||||
assert = require('assert'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var transport = require('./transport');
|
||||
|
||||
var stream = fs.createWriteStream(
|
||||
path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log.2012-12-18')
|
||||
),
|
||||
dailyRotateFileTransport = new (winston.transports.DailyRotateFile)({
|
||||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfilename.log'),
|
||||
datePattern: '.yyyy-MM-dd'
|
||||
}),
|
||||
streamTransport = new (winston.transports.DailyRotateFile)({ stream: stream });
|
||||
|
||||
vows.describe('winston/transports/daily-rotate-file').addBatch({
|
||||
"An instance of the Daily Rotate File Transport": {
|
||||
"when passed a valid filename": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertDailyRotateFile(dailyRotateFileTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(dailyRotateFileTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
},
|
||||
"when passed a valid file stream": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertDailyRotateFile(streamTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(streamTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"These tests have a non-deterministic end": {
|
||||
topic: function () {
|
||||
setTimeout(this.callback, 200);
|
||||
},
|
||||
"and this should be fixed before releasing": function () {
|
||||
assert.isTrue(true);
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"An instance of the Daily Rotate File Transport": transport(winston.transports.DailyRotateFile, {
|
||||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log'),
|
||||
datePattern: '.2012-12-18'
|
||||
})
|
||||
}).export(module);
|
||||
102
node_modules/winston/test/transports/file-maxfiles-test.js
generated
vendored
Normal file
102
node_modules/winston/test/transports/file-maxfiles-test.js
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* file-maxfiles-test.js: Tests for instances of the File transport setting the max file size,
|
||||
* and setting a number for max files created.
|
||||
* maxSize * maxFiles = total storage used by winston.
|
||||
*
|
||||
* (C) 2011 Daniel Aristizabal
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
vows = require('vows'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var maxfilesTransport = new winston.transports.File({
|
||||
timestamp: false,
|
||||
json: false,
|
||||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxfiles.log'),
|
||||
maxsize: 4096,
|
||||
maxFiles: 3
|
||||
});
|
||||
|
||||
vows.describe('winston/transports/file/maxfiles').addBatch({
|
||||
"An instance of the File Transport": {
|
||||
"when passed a valid filename": {
|
||||
topic: maxfilesTransport,
|
||||
"should be a valid transporter": function (transportTest) {
|
||||
helpers.assertFile(transportTest);
|
||||
},
|
||||
"should set the maxFiles option correctly": function (transportTest) {
|
||||
assert.isNumber(transportTest.maxFiles);
|
||||
}
|
||||
},
|
||||
"when delete old test files": {
|
||||
topic: function () {
|
||||
exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxfiles*'), this.callback);
|
||||
},
|
||||
"and when passed more files than the maxFiles": {
|
||||
topic: function () {
|
||||
var that = this,
|
||||
created = 0;
|
||||
|
||||
function data(ch) {
|
||||
return new Array(1018).join(String.fromCharCode(65 + ch));
|
||||
};
|
||||
|
||||
function logKbytes(kbytes, txt) {
|
||||
//
|
||||
// With no timestamp and at the info level,
|
||||
// winston adds exactly 7 characters:
|
||||
// [info](4)[ :](2)[\n](1)
|
||||
//
|
||||
for (var i = 0; i < kbytes; i++) {
|
||||
maxfilesTransport.log('info', data(txt), null, function () { });
|
||||
}
|
||||
}
|
||||
|
||||
maxfilesTransport.on('logged', function () {
|
||||
if (++created === 6) {
|
||||
return that.callback();
|
||||
}
|
||||
|
||||
logKbytes(4, created);
|
||||
});
|
||||
|
||||
logKbytes(4, created);
|
||||
},
|
||||
"should be only 3 files called 5.log, 4.log and 3.log": function () {
|
||||
for (var num = 0; num < 6; num++) {
|
||||
var file = !num ? 'testmaxfiles.log' : 'testmaxfiles' + num + '.log',
|
||||
fullpath = path.join(__dirname, '..', 'fixtures', 'logs', file);
|
||||
|
||||
// There should be no files with that name
|
||||
if (num >= 0 && num < 3) {
|
||||
return assert.throws(function () {
|
||||
fs.statSync(file);
|
||||
}, Error);
|
||||
}
|
||||
|
||||
// The other files should be exist
|
||||
assert.doesNotThrow(function () {
|
||||
fs.statSync(file);
|
||||
}, Error);
|
||||
}
|
||||
},
|
||||
"should have the correct content": function () {
|
||||
['D', 'E', 'F'].forEach(function (name, inx) {
|
||||
var counter = inx + 3,
|
||||
logsDir = path.join(__dirname, '..', 'fixtures', 'logs'),
|
||||
content = fs.readFileSync(path.join(logsDir, 'testmaxfiles' + counter + '.log'), 'utf-8');
|
||||
// The content minus the 7 characters added by winston
|
||||
assert.lengthOf(content.match(new RegExp(name, 'g')), 4068);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
82
node_modules/winston/test/transports/file-maxsize-test.js
generated
vendored
Normal file
82
node_modules/winston/test/transports/file-maxsize-test.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* file-test.js: Tests for instances of the File transport
|
||||
*
|
||||
* (C) 2010 Charlie Robbins
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
vows = require('vows'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var maxsizeTransport = new winston.transports.File({
|
||||
timestamp: false,
|
||||
json: false,
|
||||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize.log'),
|
||||
maxsize: 4096
|
||||
});
|
||||
|
||||
vows.describe('winston/transports/file/maxsize').addBatch({
|
||||
"An instance of the File Transport": {
|
||||
"when passed a valid filename": {
|
||||
"the log() method": {
|
||||
topic: function () {
|
||||
exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize*'), this.callback);
|
||||
},
|
||||
"when passed more than the maxsize": {
|
||||
topic: function () {
|
||||
var that = this,
|
||||
data = new Array(1018).join('-');
|
||||
|
||||
//
|
||||
// Setup a list of files which we will later stat.
|
||||
//
|
||||
that.files = [];
|
||||
|
||||
function logKbytes (kbytes) {
|
||||
//
|
||||
// With no timestamp and at the info level,
|
||||
// winston adds exactly 7 characters:
|
||||
// [info](4)[ :](2)[\n](1)
|
||||
//
|
||||
for (var i = 0; i < kbytes; i++) {
|
||||
maxsizeTransport.log('info', data, null, function () { });
|
||||
}
|
||||
}
|
||||
|
||||
maxsizeTransport.on('open', function (file) {
|
||||
var match = file.match(/(\d+)\.log$/),
|
||||
count = match ? match[1] : 0;
|
||||
|
||||
that.files.push(file);
|
||||
|
||||
if (that.files.length === 5) {
|
||||
return that.callback();
|
||||
}
|
||||
|
||||
logKbytes(4);
|
||||
});
|
||||
|
||||
logKbytes(4);
|
||||
},
|
||||
"should create multiple files correctly": function () {
|
||||
this.files.forEach(function (file) {
|
||||
try {
|
||||
var stats = fs.statSync(file);
|
||||
assert.equal(stats.size, 4096);
|
||||
}
|
||||
catch (ex) {
|
||||
assert.isNull(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
61
node_modules/winston/test/transports/file-open-test.js
generated
vendored
Normal file
61
node_modules/winston/test/transports/file-open-test.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* file-open-test.js: Tests for File transport "open" event
|
||||
*
|
||||
* (C) 2014 William Wong
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
!function (assert, fs, os, path, vows, winston) {
|
||||
'use strict';
|
||||
|
||||
vows.describe('winston/transports/file').addBatch({
|
||||
'An instance of the File Transport': {
|
||||
topic: function () {
|
||||
var callback = this.callback.bind(this),
|
||||
logPath = path.resolve(__dirname, '../fixtures/logs/file-open-test.log');
|
||||
|
||||
try {
|
||||
fs.unlinkSync(logPath);
|
||||
} catch (ex) {
|
||||
if (ex && ex.code !== 'ENOENT') { return callback(ex); }
|
||||
}
|
||||
|
||||
var fileTransport = new (winston.transports.File)({
|
||||
filename: logPath
|
||||
}),
|
||||
logger = new (winston.Logger)({
|
||||
transports: [fileTransport]
|
||||
}),
|
||||
timeline = {};
|
||||
|
||||
fileTransport.open(function () {
|
||||
timeline.open = Date.now();
|
||||
|
||||
setTimeout(function () {
|
||||
logger.info('Hello, World!', function () {
|
||||
timeline.logged = Date.now();
|
||||
});
|
||||
}, 100);
|
||||
|
||||
setTimeout(function () {
|
||||
callback(null, timeline);
|
||||
}, 1000);
|
||||
});
|
||||
},
|
||||
'should fire "open" event': function (results) {
|
||||
assert.isTrue(!!results.open);
|
||||
},
|
||||
'should fire "logged" event': function (results) {
|
||||
assert.isTrue(!!results.logged);
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
}(
|
||||
require('assert'),
|
||||
require('fs'),
|
||||
require('os'),
|
||||
require('path'),
|
||||
require('vows'),
|
||||
require('../../lib/winston')
|
||||
);
|
||||
76
node_modules/winston/test/transports/file-stress-test.js
generated
vendored
Normal file
76
node_modules/winston/test/transports/file-stress-test.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* file-stress-test.js: Tests for stressing File transport
|
||||
*
|
||||
* (C) 2014 William Wong
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
!function (assert, fs, os, path, vows, winston) {
|
||||
'use strict';
|
||||
|
||||
vows.describe('winston/transports/file').addBatch({
|
||||
'A stressed instance of the File Transport': {
|
||||
topic: function () {
|
||||
var callback = this.callback.bind(this),
|
||||
logPath = path.resolve(__dirname, '../fixtures/logs/file-stress-test.log');
|
||||
|
||||
try {
|
||||
fs.unlinkSync(logPath);
|
||||
} catch (ex) {
|
||||
if (ex && ex.code !== 'ENOENT') { return callback(ex); }
|
||||
}
|
||||
|
||||
var fileTransport = new (winston.transports.File)({
|
||||
filename: logPath
|
||||
}),
|
||||
logger = new (winston.Logger)({
|
||||
transports: [fileTransport]
|
||||
});
|
||||
|
||||
fileTransport.on('open', function () {
|
||||
setTimeout(function () {
|
||||
clearInterval(interval);
|
||||
|
||||
logger.query({ order: 'asc' }, function (err, results) {
|
||||
callback(null, results);
|
||||
});
|
||||
}, 100);
|
||||
});
|
||||
|
||||
var logIndex = 0,
|
||||
interval = setInterval(function () {
|
||||
logger.info(++logIndex);
|
||||
stress(200);
|
||||
}, 0);
|
||||
|
||||
logger.info(++logIndex);
|
||||
stress(200);
|
||||
|
||||
function stress(duration) {
|
||||
var startTime = Date.now();
|
||||
|
||||
while (Date.now() - startTime < duration) {
|
||||
Math.sqrt(Math.PI);
|
||||
}
|
||||
}
|
||||
},
|
||||
'should not skip any log lines': function (results) {
|
||||
var testIndex = 0;
|
||||
|
||||
results.file.forEach(function (log) {
|
||||
if (+log.message !== ++testIndex) {
|
||||
throw new Error('Number skipped');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
}(
|
||||
require('assert'),
|
||||
require('fs'),
|
||||
require('os'),
|
||||
require('path'),
|
||||
require('vows'),
|
||||
require('../../lib/winston')
|
||||
);
|
||||
60
node_modules/winston/test/transports/file-test.js
generated
vendored
Normal file
60
node_modules/winston/test/transports/file-test.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* file-test.js: Tests for instances of the File transport
|
||||
*
|
||||
* (C) 2010 Charlie Robbins
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
vows = require('vows'),
|
||||
fs = require('fs'),
|
||||
assert = require('assert'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var transport = require('./transport');
|
||||
|
||||
var stream = fs.createWriteStream(
|
||||
path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log')
|
||||
),
|
||||
fileTransport = new (winston.transports.File)({
|
||||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfilename.log')
|
||||
}),
|
||||
streamTransport = new (winston.transports.File)({ stream: stream });
|
||||
|
||||
vows.describe('winston/transports/file').addBatch({
|
||||
"An instance of the File Transport": {
|
||||
"when passed a valid filename": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertFile(fileTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(fileTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
},
|
||||
"when passed a valid file stream": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertFile(streamTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(streamTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"These tests have a non-deterministic end": {
|
||||
topic: function () {
|
||||
setTimeout(this.callback, 200);
|
||||
},
|
||||
"and this should be fixed before releasing": function () {
|
||||
assert.isTrue(true);
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"An instance of the File Transport": transport(winston.transports.File, {
|
||||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log')
|
||||
})
|
||||
}).export(module);
|
||||
31
node_modules/winston/test/transports/memory-test.js
generated
vendored
Normal file
31
node_modules/winston/test/transports/memory-test.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var path = require('path'),
|
||||
vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var npmTransport = new (winston.transports.Memory)(),
|
||||
syslogTransport = new (winston.transports.Memory)({ levels: winston.config.syslog.levels });
|
||||
|
||||
vows.describe('winston/transports/memory').addBatch({
|
||||
"An instance of the Memory Transport": {
|
||||
"with npm levels": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertMemory(npmTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(npmTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
},
|
||||
"with syslog levels": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertMemory(syslogTransport);
|
||||
},
|
||||
"the log() method": helpers.testSyslogLevels(syslogTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
215
node_modules/winston/test/transports/transport.js
generated
vendored
Normal file
215
node_modules/winston/test/transports/transport.js
generated
vendored
Normal file
@@ -0,0 +1,215 @@
|
||||
var assert = require('assert'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
module.exports = function (transport, options) {
|
||||
var logger = transport instanceof winston.Logger
|
||||
? transport
|
||||
: new winston.Logger({
|
||||
transports: [
|
||||
new transport(options)
|
||||
]
|
||||
});
|
||||
|
||||
// hack to fix transports that don't log
|
||||
// any unit of time smaller than seconds
|
||||
var common = require('../../lib/winston/common');
|
||||
common.timestamp = function() {
|
||||
return new Date().toISOString();
|
||||
};
|
||||
|
||||
var transport = logger.transports[logger._names[0]];
|
||||
|
||||
var out = {
|
||||
'topic': logger,
|
||||
'when passed valid options': {
|
||||
'should have the proper methods defined': function () {
|
||||
switch (transport.name) {
|
||||
case 'console':
|
||||
helpers.assertConsole(transport);
|
||||
break;
|
||||
case 'file':
|
||||
helpers.assertFile(transport);
|
||||
break;
|
||||
case 'webhook':
|
||||
helpers.assertWebhook(transport);
|
||||
break;
|
||||
case 'couchdb':
|
||||
helpers.assertCouchdb(transport);
|
||||
break;
|
||||
}
|
||||
assert.isFunction(transport.log);
|
||||
}
|
||||
},
|
||||
'the log() method': helpers.testNpmLevels(transport,
|
||||
'should respond with true', function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isNotNull(logged);
|
||||
}
|
||||
),
|
||||
'the stream() method': {
|
||||
'using no options': {
|
||||
'topic': function () {
|
||||
if (!transport.stream) return;
|
||||
|
||||
logger.log('info', 'hello world', {});
|
||||
|
||||
var cb = this.callback,
|
||||
j = 10,
|
||||
i = 10,
|
||||
results = [],
|
||||
stream = logger.stream();
|
||||
|
||||
stream.on('log', function (log) {
|
||||
results.push(log);
|
||||
results.stream = stream;
|
||||
if (!--j) cb(null, results);
|
||||
});
|
||||
|
||||
stream.on('error', function (err) {
|
||||
j = -1; //don't call the callback again
|
||||
cb(err);
|
||||
});
|
||||
|
||||
while (i--) logger.log('info', 'hello world ' + i, {});
|
||||
},
|
||||
'should stream logs': function (err, results) {
|
||||
if (!transport.stream) return;
|
||||
assert.isNull(err);
|
||||
results.forEach(function (log) {
|
||||
assert.ok(log.message.indexOf('hello world') === 0
|
||||
|| log.message.indexOf('test message') === 0);
|
||||
});
|
||||
results.stream.destroy();
|
||||
}
|
||||
},
|
||||
'using the `start` option': {
|
||||
'topic': function () {
|
||||
if (!transport.stream) return;
|
||||
|
||||
var cb = this.callback,
|
||||
stream = logger.stream({ start: 0 });
|
||||
|
||||
stream.on('log', function (log) {
|
||||
log.stream = stream;
|
||||
if (cb) cb(null, log);
|
||||
cb = null;
|
||||
});
|
||||
},
|
||||
'should stream logs': function (err, log) {
|
||||
if (!transport.stream) return;
|
||||
assert.isNull(err);
|
||||
assert.isNotNull(log.message);
|
||||
log.stream.destroy();
|
||||
}
|
||||
}
|
||||
},
|
||||
'after the logs have flushed': {
|
||||
topic: function () {
|
||||
setTimeout(this.callback, 1000);
|
||||
},
|
||||
'the query() method': {
|
||||
'using basic querying': {
|
||||
'topic': function () {
|
||||
if (!transport.query) return;
|
||||
var cb = this.callback;
|
||||
logger.log('info', 'hello world', {}, function () {
|
||||
logger.query(cb);
|
||||
});
|
||||
},
|
||||
'should return matching results': function (err, results) {
|
||||
if (!transport.query) return;
|
||||
assert.isNull(err);
|
||||
results = results[transport.name];
|
||||
while (!Array.isArray(results)) {
|
||||
results = results[Object.keys(results).pop()];
|
||||
}
|
||||
var log = results.pop();
|
||||
assert.ok(log.message.indexOf('hello world') === 0
|
||||
|| log.message.indexOf('test message') === 0);
|
||||
}
|
||||
},
|
||||
'using the `rows` option': {
|
||||
'topic': function () {
|
||||
if (!transport.query) return;
|
||||
var cb = this.callback;
|
||||
logger.log('info', 'hello world', {}, function () {
|
||||
logger.query({ rows: 1 }, cb);
|
||||
});
|
||||
},
|
||||
'should return one result': function (err, results) {
|
||||
if (!transport.query) return;
|
||||
assert.isNull(err);
|
||||
results = results[transport.name];
|
||||
while (!Array.isArray(results)) {
|
||||
results = results[Object.keys(results).pop()];
|
||||
}
|
||||
assert.equal(results.length, 1);
|
||||
}
|
||||
},
|
||||
'using `fields` and `order` option': {
|
||||
'topic': function () {
|
||||
if (!transport.query) return;
|
||||
var cb = this.callback;
|
||||
logger.log('info', 'hello world', {}, function () {
|
||||
logger.query({ order: 'asc', fields: ['timestamp'] }, cb);
|
||||
});
|
||||
},
|
||||
'should return matching results': function (err, results) {
|
||||
if (!transport.query) return;
|
||||
assert.isNull(err);
|
||||
results = results[transport.name];
|
||||
while (!Array.isArray(results)) {
|
||||
results = results[Object.keys(results).pop()];
|
||||
}
|
||||
assert.equal(Object.keys(results[0]).length, 1);
|
||||
assert.ok(new Date(results.shift().timestamp)
|
||||
< new Date(results.pop().timestamp));
|
||||
}
|
||||
},
|
||||
'using the `from` and `until` option': {
|
||||
'topic': function () {
|
||||
if (!transport.query) return;
|
||||
var cb = this.callback;
|
||||
var start = new Date - 100 * 1000;
|
||||
var end = new Date + 100 * 1000;
|
||||
logger.query({ from: start, until: end }, cb);
|
||||
},
|
||||
'should return matching results': function (err, results) {
|
||||
if (!transport.query) return;
|
||||
assert.isNull(err);
|
||||
results = results[transport.name];
|
||||
while (!Array.isArray(results)) {
|
||||
results = results[Object.keys(results).pop()];
|
||||
}
|
||||
assert.ok(results.length >= 1);
|
||||
}
|
||||
},
|
||||
'using a bad `from` and `until` option': {
|
||||
'topic': function () {
|
||||
if (!transport.query) return;
|
||||
var cb = this.callback;
|
||||
logger.log('info', 'bad from and until', {}, function () {
|
||||
var now = new Date + 1000000;
|
||||
logger.query({ from: now, until: now }, cb);
|
||||
});
|
||||
},
|
||||
'should return no results': function (err, results) {
|
||||
if (!transport.query) return;
|
||||
assert.isNull(err);
|
||||
results = results[transport.name];
|
||||
while (!Array.isArray(results)) {
|
||||
results = results[Object.keys(results).pop()];
|
||||
}
|
||||
results = [results.filter(function(log) {
|
||||
return log.message === 'bad from and until';
|
||||
}).pop()];
|
||||
assert.isUndefined(results[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return out;
|
||||
};
|
||||
125
node_modules/winston/test/transports/webhook-test.js
generated
vendored
Normal file
125
node_modules/winston/test/transports/webhook-test.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* webhook-test.js: Tests for instances of the Webhook transport
|
||||
*
|
||||
* (C) 2011 Marak Squires
|
||||
* MIT LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
vows = require('vows'),
|
||||
fs = require('fs'),
|
||||
http = require('http'),
|
||||
https = require('https'),
|
||||
assert = require('assert'),
|
||||
winston = require('../../lib/winston'),
|
||||
helpers = require('../helpers');
|
||||
|
||||
var webhookTransport = new (winston.transports.Webhook)({
|
||||
"host": "localhost",
|
||||
"port": 8080,
|
||||
"path": "/winston-test"
|
||||
});
|
||||
|
||||
var httpsWebhookTransport = new (winston.transports.Webhook)({
|
||||
"host": "localhost",
|
||||
"port": 8081,
|
||||
"path": "/winston-test",
|
||||
"ssl": true
|
||||
});
|
||||
|
||||
var authWebhookTransport = new (winston.transports.Webhook)({
|
||||
"host": "localhost",
|
||||
"port": 8080,
|
||||
"path": "/winston-auth-test",
|
||||
"auth": {
|
||||
"username": "winston",
|
||||
"password": "churchill"
|
||||
}
|
||||
});
|
||||
|
||||
var requestsAuthenticated = true;
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
if (req.url == '/winston-auth-test') {
|
||||
//
|
||||
// Test if request has been correctly authenticated
|
||||
//
|
||||
// Strip 'Basic' from Authorization header
|
||||
var signature = req.headers['authorization'].substr(6);
|
||||
requestsAuthenticated = requestsAuthenticated &&
|
||||
new Buffer(signature, 'base64').toString('utf8') == 'winston:churchill';
|
||||
}
|
||||
res.end();
|
||||
});
|
||||
|
||||
server.listen(8080);
|
||||
|
||||
|
||||
var httpsServer = https.createServer({
|
||||
cert: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent2-cert.pem')),
|
||||
key: fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'keys', 'agent2-key.pem'))
|
||||
}, function (req, res) {
|
||||
res.end();
|
||||
});
|
||||
|
||||
httpsServer.listen(8081);
|
||||
|
||||
vows.describe('winston/transports/webhook').addBatch({
|
||||
"An instance of the Webhook Transport": {
|
||||
"when passed valid options": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertWebhook(webhookTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(webhookTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
},
|
||||
"An https instance of the Webhook Transport": {
|
||||
"when passed valid options": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertWebhook(httpsWebhookTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(httpsWebhookTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
},
|
||||
"An http Basic Auth instance of the Webhook Transport": {
|
||||
"when passed valid options": {
|
||||
"should have the proper methods defined": function () {
|
||||
helpers.assertWebhook(authWebhookTransport);
|
||||
},
|
||||
"the log() method": helpers.testNpmLevels(authWebhookTransport, "should respond with true", function (ign, err, logged) {
|
||||
assert.isNull(err);
|
||||
assert.isTrue(logged);
|
||||
})
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the tests are over": {
|
||||
topic: function () {
|
||||
//
|
||||
// Delay destruction of the server since the
|
||||
// WebHook transport responds before the request
|
||||
// has actually be completed.
|
||||
//
|
||||
setTimeout(this.callback, 1000);
|
||||
},
|
||||
"the server should cleanup": function () {
|
||||
server.close();
|
||||
},
|
||||
"requests have been correctly authenticated": function () {
|
||||
assert.ok(requestsAuthenticated);
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
// "An instance of the Webhook Transport": transport(winston.transports.Webhook, {
|
||||
// "host": "localhost",
|
||||
// "port": 8080,
|
||||
// "path": "/winston-test"
|
||||
// })
|
||||
}).export(module);
|
||||
Reference in New Issue
Block a user