Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / log4js / test / streams / BaseRollingFileStream-test.js
1 "use strict";
2 var vows = require('vows')
3 , assert = require('assert')
4 , fs = require('fs')
5 , sandbox = require('sandboxed-module');
6
7 vows.describe('../../lib/streams/BaseRollingFileStream').addBatch({
8   'when node version < 0.10.0': {
9     topic: function() {
10       var streamLib = sandbox.load(
11         '../../lib/streams/BaseRollingFileStream',
12         {
13           globals: {
14             process: {
15               version: '0.8.11'
16             }
17           },
18           requires: {
19             'readable-stream': {
20               Writable: function() {}
21             }
22           }
23         }
24       );
25       return streamLib.required;
26     },
27     'it should use readable-stream to maintain compatibility': function(required) {
28       assert.ok(required['readable-stream']);
29       assert.ok(!required.stream);
30     }
31   },
32
33   'when node version > 0.10.0': {
34     topic: function() {
35       var streamLib = sandbox.load(
36         '../../lib/streams/BaseRollingFileStream',
37         {
38           globals: {
39             process: {
40               version: '0.10.1'
41             }
42           },
43           requires: {
44             'stream': {
45               Writable: function() {}
46             }
47           }
48         }
49       );
50       return streamLib.required;
51     },
52     'it should use the core stream module': function(required) {
53       assert.ok(required.stream);
54       assert.ok(!required['readable-stream']);
55     }
56   },
57
58   'when no filename is passed': {
59     topic: require('../../lib/streams/BaseRollingFileStream'),
60     'it should throw an error': function(BaseRollingFileStream) {
61       try {
62         new BaseRollingFileStream();
63         assert.fail('should not get here');
64       } catch (e) {
65         assert.ok(e);
66       }
67     }
68   },
69
70   'default behaviour': {
71     topic: function() {
72       var BaseRollingFileStream = require('../../lib/streams/BaseRollingFileStream')
73       , stream = new BaseRollingFileStream('basetest.log');
74       return stream;
75     },
76     teardown: function() {
77       try {
78         fs.unlink('basetest.log');
79       } catch (e) {
80         console.error("could not remove basetest.log", e);
81       }
82     },
83     'it should not want to roll': function(stream) {
84       assert.isFalse(stream.shouldRoll());
85     },
86     'it should not roll': function(stream) {
87       var cbCalled = false;
88       //just calls the callback straight away, no async calls
89       stream.roll('basetest.log', function() { cbCalled = true; });
90       assert.isTrue(cbCalled);
91     }
92   }
93 }).exportTo(module);