Fixes the error with test/logglyAppender-test
Refs #172 I will add more relevant tests later
This commit is contained in:
parent
770f2da627
commit
9b4c7d1574
@ -1,33 +1,82 @@
|
||||
"use strict";
|
||||
var assert = require('assert')
|
||||
, vows = require('vows')
|
||||
, layouts = require('../lib/layouts')
|
||||
, sandbox = require('sandboxed-module');
|
||||
var vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, log4js = require('../lib/log4js')
|
||||
, sandbox = require('sandboxed-module')
|
||||
;
|
||||
|
||||
vows.describe('../lib/appenders/loggly').addBatch({
|
||||
'appender': {
|
||||
topic: function() {
|
||||
var messages = []
|
||||
, fakeLoggly = {
|
||||
log: function(msg) { messages.push(msg); }
|
||||
}
|
||||
, appenderModule = sandbox.require(
|
||||
'../lib/appenders/loggly',
|
||||
{
|
||||
globals: {
|
||||
'loggly': fakeLoggly
|
||||
}
|
||||
function setupLogging(category, options) {
|
||||
var msgs = [];
|
||||
|
||||
var fakeLoggly = {
|
||||
createClient: function (options) {
|
||||
return {
|
||||
config: options,
|
||||
log: function (msg, tags) {
|
||||
msgs.push({
|
||||
msg: msg,
|
||||
tags: tags
|
||||
});
|
||||
}
|
||||
)
|
||||
, appender = appenderModule.appender(layouts.messagePassThroughLayout);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
appender({ data: ["blah"] });
|
||||
return messages;
|
||||
var fakeLayouts = {
|
||||
layout: function(type, config) {
|
||||
this.type = type;
|
||||
this.config = config;
|
||||
return log4js.layouts.messagePassThroughLayout;
|
||||
},
|
||||
basicLayout: log4js.layouts.basicLayout,
|
||||
messagePassThroughLayout: log4js.layouts.messagePassThroughLayout
|
||||
};
|
||||
|
||||
'should output to loggly': function(messages) {
|
||||
assert.equal(messages[0], 'blah');
|
||||
var fakeConsole = {
|
||||
errors: [],
|
||||
error: function(msg, value) {
|
||||
this.errors.push({ msg: msg, value: value });
|
||||
}
|
||||
};
|
||||
|
||||
var logglyModule = sandbox.require('../lib/appenders/loggly', {
|
||||
requires: {
|
||||
'loggly': fakeLoggly,
|
||||
'../layouts': fakeLayouts
|
||||
},
|
||||
globals: {
|
||||
console: fakeConsole
|
||||
}
|
||||
});
|
||||
|
||||
log4js.addAppender(logglyModule.configure(options), category);
|
||||
|
||||
return {
|
||||
logger: log4js.getLogger(category),
|
||||
loggly: fakeLoggly,
|
||||
layouts: fakeLayouts,
|
||||
console: fakeConsole,
|
||||
results: msgs
|
||||
};
|
||||
}
|
||||
|
||||
log4js.clearAppenders();
|
||||
vows.describe('log4js logglyAppender').addBatch({
|
||||
'minimal config': {
|
||||
topic: function() {
|
||||
var setup = setupLogging('loggly', {
|
||||
token: 'your-really-long-input-token',
|
||||
subdomain: 'your-subdomain',
|
||||
tags: ['loggly-tag1', 'loggly-tag2', 'loggly-tagn']
|
||||
});
|
||||
|
||||
setup.logger.log('Log event #1');
|
||||
return setup;
|
||||
},
|
||||
'there should be one message only': function (topic) {
|
||||
//console.log('topic', topic);
|
||||
assert.equal(topic.results.length, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}).exportTo(module);
|
||||
|
||||
}).export(module);
|
||||
|
Loading…
Reference in New Issue
Block a user