mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
chore(test): improve test coverage for fileSyncAppender
appenders/fileSync.js - Line 58 - throw new Error(`maxLogSize (${maxLogSize}) should be > 0`);
This commit is contained in:
parent
6e6dbad5d3
commit
8ad41831d1
@ -51,19 +51,15 @@ function touchFile(file, options) {
|
||||
}
|
||||
|
||||
class RollingFileSync {
|
||||
constructor(filename, size, backups, options) {
|
||||
constructor(filename, maxLogSize, backups, options) {
|
||||
debug('In RollingFileStream');
|
||||
|
||||
function throwErrorIfArgumentsAreNotValid() {
|
||||
if (!filename || !size || size <= 0) {
|
||||
throw new Error('You must specify a filename and file size');
|
||||
}
|
||||
if (maxLogSize < 0) {
|
||||
throw new Error(`maxLogSize (${maxLogSize}) should be > 0`);
|
||||
}
|
||||
|
||||
throwErrorIfArgumentsAreNotValid();
|
||||
|
||||
this.filename = filename;
|
||||
this.size = size;
|
||||
this.size = maxLogSize;
|
||||
this.backups = backups;
|
||||
this.options = options;
|
||||
this.currentSize = 0;
|
||||
|
||||
@ -61,6 +61,28 @@ test("log4js fileSyncAppender", batch => {
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.test("should give error if invalid maxLogSize", async t => {
|
||||
const maxLogSize = -1;
|
||||
const expectedError = new Error(`maxLogSize (${maxLogSize}) should be > 0`);
|
||||
t.throws(
|
||||
() =>
|
||||
log4js.configure({
|
||||
appenders: {
|
||||
file: {
|
||||
type: "fileSync",
|
||||
filename: path.join(__dirname, "fa-invalidMaxFileSize-sync-test.log"),
|
||||
maxLogSize: -1
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ["file"], level: "debug" }
|
||||
}
|
||||
}),
|
||||
expectedError
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
batch.test("with a max file size and no backups", t => {
|
||||
const testFile = path.join(__dirname, "/fa-maxFileSize-sync-test.log");
|
||||
const logger = log4js.getLogger("max-file-size");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user