Add failure scenarios tests for connection, appendToStream, deleteStream (wip)
This commit is contained in:
39
src/common/log/fileLogger.js
Normal file
39
src/common/log/fileLogger.js
Normal file
@ -0,0 +1,39 @@
|
||||
var util = require('util');
|
||||
var fs = require('fs');
|
||||
var os = require('os');
|
||||
|
||||
function FileLogger(filePath, append) {
|
||||
this._filePath = filePath;
|
||||
if (!append) {
|
||||
try {
|
||||
fs.unlink(filePath);
|
||||
} catch(e) {}
|
||||
}
|
||||
}
|
||||
|
||||
function createLine(level, args, argsStartIndex) {
|
||||
var msg = util.format.apply(util, Array.prototype.slice.call(args, argsStartIndex));
|
||||
return util.format('%s %s - %s%s', new Date().toISOString(), level, msg, os.EOL);
|
||||
}
|
||||
|
||||
FileLogger.prototype.debug = function() {
|
||||
var line = createLine('DEBUG', arguments, 0);
|
||||
fs.appendFileSync(this._filePath, line);
|
||||
};
|
||||
|
||||
FileLogger.prototype.info = function() {
|
||||
var line = createLine('INFO', arguments, 0);
|
||||
fs.appendFileSync(this._filePath, line);
|
||||
};
|
||||
|
||||
FileLogger.prototype.error = function(e) {
|
||||
var hasError = e instanceof Error;
|
||||
var line = createLine('ERROR', arguments, hasError ? 1 : 0);
|
||||
if (hasError) {
|
||||
line += e.stack + os.EOL;
|
||||
}
|
||||
fs.appendFileSync(this._filePath, line);
|
||||
};
|
||||
|
||||
|
||||
module.exports = FileLogger;
|
16
src/common/systemMetadata.js
Normal file
16
src/common/systemMetadata.js
Normal file
@ -0,0 +1,16 @@
|
||||
const SystemMetadata = {
|
||||
maxAge: '$maxAge',
|
||||
maxCount: '$maxCount',
|
||||
truncateBefore: '$tb',
|
||||
cacheControl: '$cacheControl',
|
||||
acl: '$acl',
|
||||
aclRead: '$r',
|
||||
aclWrite: '$w',
|
||||
aclDelete: '$d',
|
||||
aclMetaRead: '$mr',
|
||||
aclMetaWrite: '$mw',
|
||||
userStreamAcl: '$userStreamAcl',
|
||||
systemStreamAcl: '$systemStreamAcl'
|
||||
};
|
||||
|
||||
module.exports = SystemMetadata;
|
@ -8,4 +8,16 @@ module.exports.notNullOrEmpty = function(value, name) {
|
||||
module.exports.notNull = function(value, name) {
|
||||
if (value === null)
|
||||
throw new Error(name + " is null.");
|
||||
};
|
||||
|
||||
module.exports.isInteger = function(value, name) {
|
||||
if (typeof value !== 'number' || value % 1 !== 0)
|
||||
throw new TypeError(name + " is not an integer.");
|
||||
};
|
||||
|
||||
module.exports.isArrayOf = function(expectedType, value, name) {
|
||||
if (!Array.isArray(value))
|
||||
throw new TypeError(name + " is not an array.");
|
||||
if (!value.every(function(x) { return x instanceof expectedType; }))
|
||||
throw new TypeError([name, " is not an array of ", expectedType, "."].join(""));
|
||||
};
|
Reference in New Issue
Block a user