Add failure scenarios tests for connection, appendToStream, deleteStream (wip)

This commit is contained in:
Nicolas Dextraze
2016-03-11 15:55:27 -08:00
parent b0a0af536d
commit 0b63df85e7
16 changed files with 420 additions and 32 deletions

View 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;

View 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;

View File

@ -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(""));
};