|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
var vows = require('vows')
|
|
|
|
|
, assert = require('assert')
|
|
|
|
|
, fs = require('fs')
|
|
|
|
@ -11,7 +12,7 @@ if (semver.satisfies(process.version, '>=0.10.0')) {
|
|
|
|
|
} else {
|
|
|
|
|
streams = require('readable-stream');
|
|
|
|
|
}
|
|
|
|
|
DateRollingFileStream = require('../../lib/streams').DateRollingFileStream
|
|
|
|
|
DateRollingFileStream = require('../../lib/streams').DateRollingFileStream;
|
|
|
|
|
|
|
|
|
|
function cleanUp(filename) {
|
|
|
|
|
return function() {
|
|
|
|
@ -25,7 +26,10 @@ function now() {
|
|
|
|
|
|
|
|
|
|
vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
'arguments': {
|
|
|
|
|
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-1', 'yyyy-mm-dd.hh'),
|
|
|
|
|
topic: new DateRollingFileStream(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-1',
|
|
|
|
|
'yyyy-mm-dd.hh'
|
|
|
|
|
),
|
|
|
|
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-1'),
|
|
|
|
|
|
|
|
|
|
'should take a filename and a pattern and return a WritableStream': function(stream) {
|
|
|
|
@ -51,20 +55,27 @@ vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'with stream arguments': {
|
|
|
|
|
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-3', 'yyyy-MM-dd', { mode: 0666 }),
|
|
|
|
|
topic: new DateRollingFileStream(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-3',
|
|
|
|
|
'yyyy-MM-dd',
|
|
|
|
|
{ mode: parseInt('0666', 8) }
|
|
|
|
|
),
|
|
|
|
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-3'),
|
|
|
|
|
|
|
|
|
|
'should pass them to the underlying stream': function(stream) {
|
|
|
|
|
assert.equal(stream.theStream.mode, 0666);
|
|
|
|
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'with stream arguments but no pattern': {
|
|
|
|
|
topic: new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-4', { mode: 0666 }),
|
|
|
|
|
topic: new DateRollingFileStream(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-4',
|
|
|
|
|
{ mode: parseInt('0666', 8) }
|
|
|
|
|
),
|
|
|
|
|
teardown: cleanUp(__dirname + '/test-date-rolling-file-stream-4'),
|
|
|
|
|
|
|
|
|
|
'should pass them to the underlying stream': function(stream) {
|
|
|
|
|
assert.equal(stream.theStream.mode, 0666);
|
|
|
|
|
assert.equal(stream.theStream.mode, parseInt('0666', 8));
|
|
|
|
|
},
|
|
|
|
|
'should use default pattern': function(stream) {
|
|
|
|
|
assert.equal(stream.pattern, '.yyyy-MM-dd');
|
|
|
|
@ -74,7 +85,11 @@ vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
'with a pattern of .yyyy-MM-dd': {
|
|
|
|
|
topic: function() {
|
|
|
|
|
var that = this,
|
|
|
|
|
stream = new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd', null, now);
|
|
|
|
|
stream = new DateRollingFileStream(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-5', '.yyyy-MM-dd',
|
|
|
|
|
null,
|
|
|
|
|
now
|
|
|
|
|
);
|
|
|
|
|
stream.write("First message\n", 'utf8', function() {
|
|
|
|
|
that.callback(null, stream);
|
|
|
|
|
});
|
|
|
|
@ -103,7 +118,14 @@ vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
fs.readdir(__dirname, this.callback);
|
|
|
|
|
},
|
|
|
|
|
'should be two': function(files) {
|
|
|
|
|
assert.equal(files.filter(function(file) { return file.indexOf('test-date-rolling-file-stream-5') > -1; }).length, 2);
|
|
|
|
|
assert.equal(
|
|
|
|
|
files.filter(
|
|
|
|
|
function(file) {
|
|
|
|
|
return file.indexOf('test-date-rolling-file-stream-5') > -1;
|
|
|
|
|
}
|
|
|
|
|
).length,
|
|
|
|
|
2
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -131,7 +153,12 @@ vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
topic: function() {
|
|
|
|
|
var that = this,
|
|
|
|
|
testTime = new Date(2012, 8, 12, 0, 10, 12),
|
|
|
|
|
stream = new DateRollingFileStream(__dirname + '/test-date-rolling-file-stream-pattern', '.yyyy-MM-dd', {alwaysIncludePattern: true}, now);
|
|
|
|
|
stream = new DateRollingFileStream(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-pattern',
|
|
|
|
|
'.yyyy-MM-dd',
|
|
|
|
|
{alwaysIncludePattern: true},
|
|
|
|
|
now
|
|
|
|
|
);
|
|
|
|
|
stream.write("First message\n", 'utf8', function() {
|
|
|
|
|
that.callback(null, stream);
|
|
|
|
|
});
|
|
|
|
@ -160,13 +187,23 @@ vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
fs.readdir(__dirname, this.callback);
|
|
|
|
|
},
|
|
|
|
|
'should be two': function(files) {
|
|
|
|
|
assert.equal(files.filter(function(file) { return file.indexOf('test-date-rolling-file-stream-pattern') > -1; }).length, 2);
|
|
|
|
|
assert.equal(
|
|
|
|
|
files.filter(
|
|
|
|
|
function(file) {
|
|
|
|
|
return file.indexOf('test-date-rolling-file-stream-pattern') > -1;
|
|
|
|
|
}
|
|
|
|
|
).length,
|
|
|
|
|
2
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'the file with the later date': {
|
|
|
|
|
topic: function() {
|
|
|
|
|
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13', this.callback);
|
|
|
|
|
fs.readFile(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-13',
|
|
|
|
|
this.callback
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
'should contain the second message': function(contents) {
|
|
|
|
|
assert.equal(contents.toString(), "Second message\n");
|
|
|
|
@ -175,7 +212,10 @@ vows.describe('DateRollingFileStream').addBatch({
|
|
|
|
|
|
|
|
|
|
'the file with the date': {
|
|
|
|
|
topic: function() {
|
|
|
|
|
fs.readFile(__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12', this.callback);
|
|
|
|
|
fs.readFile(
|
|
|
|
|
__dirname + '/test-date-rolling-file-stream-pattern.2012-09-12',
|
|
|
|
|
this.callback
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
'should contain the first message': function(contents) {
|
|
|
|
|
assert.equal(contents.toString(), "First message\n");
|
|
|
|
|