Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / log4js / test / logglyAppender-test.js
1 "use strict";
2 var vows = require('vows')
3   , assert = require('assert')
4   , log4js = require('../lib/log4js')
5   , sandbox = require('sandboxed-module')
6   ;
7
8 function setupLogging(category, options) {
9   var msgs = [];
10
11   var fakeLoggly = {
12     createClient: function(options) {
13       return {
14         config: options,
15         log: function(msg, tags) {
16           msgs.push({
17             msg: msg,
18             tags: tags
19           });
20         }
21       };
22     }
23   };
24
25   var fakeLayouts = {
26     layout: function(type, config) {
27       this.type = type;
28       this.config = config;
29       return log4js.layouts.messagePassThroughLayout;
30     },
31     basicLayout: log4js.layouts.basicLayout,
32     messagePassThroughLayout: log4js.layouts.messagePassThroughLayout
33   };
34
35   var fakeConsole = {
36     errors: [],
37     error: function(msg, value) {
38       this.errors.push({ msg: msg, value: value });
39     }
40   };
41
42   var logglyModule = sandbox.require('../lib/appenders/loggly', {
43     requires: {
44       'loggly': fakeLoggly,
45       '../layouts': fakeLayouts
46     },
47     globals: {
48       console: fakeConsole
49     }
50   });
51
52   log4js.addAppender(logglyModule.configure(options), category);
53
54   return {
55     logger: log4js.getLogger(category),
56     loggly: fakeLoggly,
57     layouts: fakeLayouts,
58     console: fakeConsole,
59     results: msgs
60   };
61 }
62
63 log4js.clearAppenders();
64
65 function setupTaggedLogging() {
66   return setupLogging('loggly', {
67     token: 'your-really-long-input-token',
68     subdomain: 'your-subdomain',
69     tags: ['loggly-tag1', 'loggly-tag2', 'loggly-tagn']
70   });
71 }
72
73 vows.describe('log4js logglyAppender').addBatch({
74   'with minimal config': {
75     topic: function() {
76       var setup = setupTaggedLogging();
77       setup.logger.log('trace', 'Log event #1', 'Log 2', { tags: ['tag1', 'tag2'] });
78       return setup;
79     },
80     'has a results.length of 1': function(topic) {
81       assert.equal(topic.results.length, 1);
82     },
83     'has a result msg with both args concatenated': function(topic) {
84       assert.equal(topic.results[0].msg.msg, 'Log event #1 Log 2');
85     },
86     'has a result tags with the arg that contains tags': function(topic) {
87       assert.deepEqual(topic.results[0].tags, ['tag1', 'tag2']);
88     }
89   }
90 }).addBatch({
91   'config with object with tags and other keys': {
92     topic: function() {
93       var setup = setupTaggedLogging();
94
95       // ignore this tags object b/c there are 2 keys
96       setup.logger.log('trace', 'Log event #1', { other: 'other', tags: ['tag1', 'tag2'] });
97       return setup;
98     },
99     'has a results.length of 1': function(topic) {
100       assert.equal(topic.results.length, 1);
101     },
102     'has a result msg with the args concatenated': function(topic) {
103       assert.equal(topic.results[0].msg.msg,
104         'Log event #1 { other: \'other\', tags: [ \'tag1\', \'tag2\' ] }');
105     },
106     'has a result tags with the arg that contains no tags': function(topic) {
107       assert.deepEqual(topic.results[0].tags, []);
108     }
109   }
110 }).export(module);