-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconfig.js
More file actions
154 lines (143 loc) · 6.59 KB
/
Copy pathconfig.js
File metadata and controls
154 lines (143 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (c) 2024 BMC Software, Inc.
'use strict'
var expect = require('chai').expect,
sinon = require('sinon'),
debug = require('../lib/debug'),
config = require('../config/config'),
path = require('path'),
fs = require('fs'),
api = require('../lib/api'), // wrappers for API calls
exception = require('../lib/exception'), // exception handler module
logger = require('../index'), // exception handler module
currentDebugLogPath = path.join(process.cwd(), 'stackify-debug.log');
process.env['STACKIFY_TEST'] = true
describe('Config Debug', function() {
context('With Debug Disabled', function () {
it('should not call fs.access', function (done) {
const accessSpy = sinon.spy(fs, 'access');
debug.set({
debug: false,
debug_log_path: config.DEBUG_LOG_PATH
}, function callback() {
expect(accessSpy.calledOnce).to.be.false;
expect(accessSpy.calledWith(currentDebugLogPath, fs.constants.F_OK | fs.constants.W_OK)).to.be.false;
accessSpy.restore();
config.DEBUG_LOG_PATH = currentDebugLogPath;
config.DEBUG = false;
done();
});
});
});
context('With Debug Enabled', function () {
it('should call fs.access and createWriteStream with default setting', function (done) {
const accessSpy = sinon.spy(fs, 'access');
const writeStreamSpy = sinon.spy(fs, 'createWriteStream');
debug.set({
debug: true,
debug_log_path: config.DEBUG_LOG_PATH
}, function callback() {
expect(accessSpy.calledOnce).to.be.true;
expect(accessSpy.calledWith(currentDebugLogPath, fs.constants.F_OK | fs.constants.W_OK)).to.be.true;
expect(writeStreamSpy.calledWith(currentDebugLogPath, {flags: 'a'})).to.be.true;
accessSpy.restore();
writeStreamSpy.restore();
config.DEBUG_LOG_PATH = currentDebugLogPath;
config.DEBUG = false;
done();
});
});
});
context('With Debug Enabled but non existing directory', function () {
it('should call fs.access and createWriteStream with stdout setting', function (done) {
const accessSpy = sinon.spy(fs, 'access');
const writeStreamSpy = sinon.spy(fs, 'createWriteStream');
config._setupConfig({
debug_log_path: '/path/to/none',
debug: true
});
console.log(config.DEBUG_LOG_PATH);
debug.set({
debug: true,
debug_log_path: config.DEBUG_LOG_PATH
}, function callback() {
expect(accessSpy.calledOnce).to.be.true;
expect(accessSpy.calledWith('/path/to/none', fs.constants.F_OK | fs.constants.W_OK)).to.be.true;
expect(writeStreamSpy.calledWith(null, { fd: process.stdout.fd })).to.be.true;
accessSpy.restore();
writeStreamSpy.restore();
config.DEBUG_LOG_PATH = currentDebugLogPath;
config.DEBUG = false;
done();
});
});
});
});
describe('Config Debug Integration', function() {
context('With Debug Disabled', function () {
it('should not call fs.access', function (done) {
const accessSpy = sinon.spy(fs, 'access');
const apiStub = sinon.stub(api, 'initialize', (options) => {
expect(accessSpy.calledOnce).to.be.false;
expect(accessSpy.calledWith(currentDebugLogPath, fs.constants.F_OK | fs.constants.W_OK)).to.be.false;
accessSpy.restore();
apiStub.restore();
exceptionExitStub.restore();
exceptionExceptionStub.restore();
done();
});
const exceptionExitStub = sinon.stub(exception, 'gracefulExitHandler');
const exceptionExceptionStub = sinon.stub(exception, 'catchException');
logger.start({
debug: false,
debug_log_path: config.DEBUG_LOG_PATH
});
});
});
context('With Debug Enabled', function () {
it('should call fs.access and createWriteStream with default setting', function (done) {
const accessSpy = sinon.spy(fs, 'access');
const writeStreamSpy = sinon.spy(fs, 'createWriteStream');
const apiStub = sinon.stub(api, 'initialize', (options) => {
expect(accessSpy.calledOnce).to.be.true;
expect(accessSpy.calledWith(currentDebugLogPath, fs.constants.F_OK | fs.constants.W_OK)).to.be.true;
expect(writeStreamSpy.calledWith(currentDebugLogPath, {flags: 'a'})).to.be.true;
accessSpy.restore();
writeStreamSpy.restore();
apiStub.restore();
exceptionExitStub.restore();
exceptionExceptionStub.restore();
done();
});
const exceptionExitStub = sinon.stub(exception, 'gracefulExitHandler');
const exceptionExceptionStub = sinon.stub(exception, 'catchException');
logger.start({
debug: true,
debug_log_path: config.DEBUG_LOG_PATH
});
});
});
context('With Debug Enabled but non existing directory', function () {
it('should call fs.access and createWriteStream with stdout setting', function (done) {
const accessSpy = sinon.spy(fs, 'access');
const writeStreamSpy = sinon.spy(fs, 'createWriteStream');
const apiStub = sinon.stub(api, 'initialize', (options) => {
expect(accessSpy.calledOnce).to.be.true;
console.log('args', accessSpy.args);
expect(accessSpy.calledWith('/path/to/none', fs.constants.F_OK | fs.constants.W_OK)).to.be.true;
expect(writeStreamSpy.calledWith(null, { fd: process.stdout.fd })).to.be.true;
accessSpy.restore();
writeStreamSpy.restore();
apiStub.restore();
exceptionExitStub.restore();
exceptionExceptionStub.restore();
done();
});
const exceptionExitStub = sinon.stub(exception, 'gracefulExitHandler');
const exceptionExceptionStub = sinon.stub(exception, 'catchException');
logger.start({
debug: true,
debug_log_path: '/path/to/none'
});
});
});
});