Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / log4js / test / logLevelFilter-test.js
1 "use strict";
2 var vows = require('vows')
3 , fs = require('fs')
4 , assert = require('assert')
5 , os = require('os')
6 , EOL = require('os').EOL || '\n';
7
8 function remove(filename) {
9   try {
10     fs.unlinkSync(filename);
11   } catch (e) {
12     //doesn't really matter if it failed
13   }
14 }
15
16 vows.describe('log4js logLevelFilter').addBatch({
17   'appender': {
18     topic: function() {
19       var log4js = require('../lib/log4js'), logEvents = [], logger;
20       log4js.clearAppenders();
21       log4js.addAppender(
22         require('../lib/appenders/logLevelFilter')
23           .appender(
24             'ERROR',
25             undefined,
26             function(evt) { logEvents.push(evt); }
27           ),
28         "logLevelTest"
29       );
30
31       logger = log4js.getLogger("logLevelTest");
32       logger.debug('this should not trigger an event');
33       logger.warn('neither should this');
34       logger.error('this should, though');
35       logger.fatal('so should this');
36       return logEvents;
37     },
38     'should only pass log events greater than or equal to its own level' : function(logEvents) {
39       assert.equal(logEvents.length, 2);
40       assert.equal(logEvents[0].data[0], 'this should, though');
41       assert.equal(logEvents[1].data[0], 'so should this');
42     }
43   },
44
45   'configure': {
46     topic: function() {
47       var log4js = require('../lib/log4js')
48       , logger;
49
50       remove(__dirname + '/logLevelFilter.log');
51       remove(__dirname + '/logLevelFilter-warnings.log');
52       remove(__dirname + '/logLevelFilter-debugs.log');
53
54       log4js.configure('test/with-logLevelFilter.json');
55       logger = log4js.getLogger("tests");
56       logger.debug('debug');
57       logger.info('info');
58       logger.error('error');
59       logger.warn('warn');
60       logger.debug('debug');
61       logger.trace('trace');
62       //wait for the file system to catch up
63       setTimeout(this.callback, 500);
64     },
65     'tmp-tests.log': {
66       topic: function() {
67         fs.readFile(__dirname + '/logLevelFilter.log', 'utf8', this.callback);
68       },
69       'should contain all log messages': function (contents) {
70         var messages = contents.trim().split(EOL);
71         assert.deepEqual(messages, ['debug','info','error','warn','debug','trace']);
72       }
73     },
74     'tmp-tests-warnings.log': {
75       topic: function() {
76         fs.readFile(__dirname + '/logLevelFilter-warnings.log','utf8',this.callback);
77       },
78       'should contain only error and warning log messages': function(contents) {
79         var messages = contents.trim().split(EOL);
80         assert.deepEqual(messages, ['error','warn']);
81       }
82     },
83     'tmp-tests-debugs.log': {
84       topic: function() {
85         fs.readFile(__dirname + '/logLevelFilter-debugs.log','utf8',this.callback);
86       },
87       'should contain only trace and debug log messages': function(contents) {
88         var messages = contents.trim().split(EOL);
89         assert.deepEqual(messages, ['debug','debug','trace']);
90       }
91     }
92   }
93 }).export(module);