-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wip] Test maxsize options on file transport.
- Loading branch information
Showing
3 changed files
with
85 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
/* | |||
* file-test.js: Tests for instances of the File transport | |||
* | |||
* (C) 2010 Charlie Robbins | |||
* MIT LICENSE | |||
* | |||
*/ | |||
|
|||
const assert = require('assert'); | |||
const exec = require('child_process').exec; | |||
const fs = require('fs'); | |||
const path = require('path'); | |||
const assume = require('assume'); | |||
const winston = require('../../'); | |||
|
|||
const MESSAGE = Symbol.for('message'); | |||
const kbStr = new Array(1024).join('-'); | |||
const maxsizeTransport = new winston.transports.File({ | |||
level: 'info', | |||
format: winston.format.printf(info => info.message), | |||
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize.log'), | |||
maxsize: 4096 | |||
}); | |||
|
|||
// | |||
// Log the specified kbytes to the transport | |||
// | |||
function logKbytes (kbytes) { | |||
// | |||
// With printf format that displays the message only | |||
// winston adds exactly 0 characters. | |||
// | |||
for (var i = 0; i < kbytes; i++) { | |||
maxsizeTransport.log({ level: 'info', [MESSAGE]: kbStr }); | |||
} | |||
} | |||
|
|||
describe('File (maxsize)', function () { | |||
this.timeout(10000); | |||
|
|||
before(function (done) { | |||
exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize*'), done); | |||
}); | |||
|
|||
it('should create multiple files correctly when passed more than the maxsize', function (done) { | |||
// | |||
// Setup a list of files which we will later stat. | |||
// | |||
const files = []; | |||
|
|||
// | |||
// Assets all the files have been created with the | |||
// correct filesize | |||
// | |||
function assumeFilesCreated() { | |||
files.forEach(function (file) { | |||
let stats; | |||
try { | |||
stats = fs.statSync(file); | |||
assume(stats.size).equals(4096); | |||
} catch (ex) { | |||
assume(stats).is.an('object', `${file} failed to open: ${ex.message}`); | |||
} | |||
}); | |||
|
|||
done(); | |||
} | |||
|
|||
maxsizeTransport.on('open', function (file) { | |||
console.dir(arguments); | |||
const match = file.match(/(\d+)\.log$/); | |||
const count = match ? match[1] : 0; | |||
|
|||
files.push(file); | |||
if (files.length === 5) { | |||
return assumeFilesCreated(); | |||
} | |||
|
|||
logKbytes(4); | |||
}); | |||
|
|||
logKbytes(4); | |||
}); | |||
}); |