Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* file-test.js: Tests for instances of the File transport
3
*
4
* (C) 2010 Charlie Robbins
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
exec = require('child_process').exec,
11
fs = require('fs'),
12
path = require('path'),
13
vows = require('vows'),
14
winston = require('../../lib/winston'),
15
helpers = require('../helpers');
16
17
var maxsizeTransport = new winston.transports.File({
18
timestamp: false,
19
json: false,
20
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize.log'),
21
maxsize: 4096
22
});
23
24
vows.describe('winston/transports/file/maxsize').addBatch({
25
"An instance of the File Transport": {
26
"when passed a valid filename": {
27
"the log() method": {
28
topic: function () {
29
exec('rm -rf ' + path.join(__dirname, '..', 'fixtures', 'logs', 'testmaxsize*'), this.callback);
30
},
31
"when passed more than the maxsize": {
32
topic: function () {
33
var that = this,
34
data = new Array(1018).join('-');
35
36
//
37
// Setup a list of files which we will later stat.
38
//
39
that.files = [];
40
41
function logKbytes (kbytes) {
42
//
43
// With no timestamp and at the info level,
44
// winston adds exactly 7 characters:
45
// [info](4)[ :](2)[\n](1)
46
//
47
for (var i = 0; i < kbytes; i++) {
48
maxsizeTransport.log('info', data, null, function () { });
49
}
50
}
51
52
maxsizeTransport.on('open', function (file) {
53
var match = file.match(/(\d+)\.log$/),
54
count = match ? match[1] : 0;
55
56
that.files.push(file);
57
58
if (that.files.length === 5) {
59
return that.callback();
60
}
61
62
logKbytes(4);
63
});
64
65
logKbytes(4);
66
},
67
"should create multiple files correctly": function () {
68
this.files.forEach(function (file) {
69
try {
70
var stats = fs.statSync(file);
71
assert.equal(stats.size, 4096);
72
}
73
catch (ex) {
74
assert.isNull(ex);
75
}
76
});
77
}
78
}
79
}
80
}
81
}
82
}).export(module);
83