forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventExclusionPlugin-spec.ts
More file actions
127 lines (106 loc) · 5.62 KB
/
EventExclusionPlugin-spec.ts
File metadata and controls
127 lines (106 loc) · 5.62 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
import { DefaultErrorParser } from '../../services/DefaultErrorParser';
import { ExceptionlessClient } from '../../ExceptionlessClient';
import { EventPluginContext } from '../EventPluginContext';
import { EventExclusionPlugin } from './EventExclusionPlugin';
import { expect } from 'chai';
import { IEvent } from '../../models/IEvent';
describe('EventExclusionPlugin', () => {
describe('should exclude log levels', () => {
function run(source: string, level: string, settingKey: string, settingValue: string): boolean {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
if (settingKey) {
client.config.settings[settingKey] = settingValue;
}
let ev: IEvent = { type: 'log', source: source, data: {} };
if (level) {
ev.data['@level'] = level;
}
let context = new EventPluginContext(client, ev);
let plugin = new EventExclusionPlugin();
plugin.run(context);
return !!context.cancelled;
}
it('<null>', () => expect(run(null, null, null, null)).to.be.false);
it('Test', () => expect(run('Test', null, null, null)).to.be.false);
it('[Trace] Test', () => expect(run('Test', 'Trace', null, null)).to.be.false);
it('[Off] Test', () => expect(run('Test', 'Off', null, null)).to.be.true);
it('[Abc] Test', () => expect(run('Test', 'Abc', null, null)).to.be.false);
it('[Trace] Test (source min level: Debug)', () => expect(run('Test', 'Trace', '@@log:Test', 'Debug')).to.be.true);
it('[Info] Test (source min level: Debug)', () => expect(run('Test', 'Info', '@@log:Test', 'Debug')).to.be.false);
it('[Trace] Test (global min level: Debug)', () => expect(run('Test', 'Trace', '@@log:*', 'Debug')).to.be.true);
it('[Warn] Test (global min level: Debug)', () => expect(run('Test', 'Warn', '@@log:*', 'Debug')).to.be.false);
});
describe('should exclude log levels with info default:', () => {
function run(source: string, level: string, settingKey: string, settingValue: string): boolean {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
client.config.settings['@@log:*'] = 'Info';
if (settingKey) {
client.config.settings[settingKey] = settingValue;
}
let ev: IEvent = { type: 'log', source: source, data: {} };
if (level) {
ev.data['@level'] = level;
}
let context = new EventPluginContext(client, ev);
let plugin = new EventExclusionPlugin();
plugin.run(context);
return !!context.cancelled;
}
it('<null>', () => expect(run(null, null, null, null)).to.be.false);
it('Test', () => expect(run('Test', null, null, null)).to.be.false);
it('[Trace] Test', () => expect(run('Test', 'Trace', null, null)).to.be.true);
it('[Warn] Test', () => expect(run('Test', 'Warn', null, null)).to.be.false);
it('[Error] Test (source min level: Debug)', () => expect(run('Test', 'Error', '@@log:Test', 'Debug')).to.be.false);
it('[Debug] Test (source min level: Debug)', () => expect(run('Test', 'Debug', '@@log:Test', 'Debug')).to.be.false);
});
describe('should exclude source type', () => {
function run(type: string, source: string, settingKey: string, settingValue: string|boolean): boolean {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
if (settingKey) {
client.config.settings[settingKey] = settingValue;
}
let context = new EventPluginContext(client, { type: type, source: source, data: {} });
let plugin = new EventExclusionPlugin();
plugin.run(context);
return !!context.cancelled;
}
it('<null>', () => expect(run(null, null, null, null)).to.be.false);
it('<null>', () => expect(run('feature', null, null, null)).to.be.false);
it('<null>', () => expect(run('feature', 'test', null, null)).to.be.false);
it('<null>', () => expect(run('feature', 'test', '@@feature:Test', true)).to.be.false);
it('<null>', () => expect(run('feature', 'test', '@@feature:Test', false)).to.be.true);
it('<null>', () => expect(run('feature', 'test', '@@feature:*', false)).to.be.true);
it('<null>', () => expect(run('404', '/unknown', '@@404:*', false)).to.be.true);
it('<null>', () => expect(run('404', '/unknown', '@@404:/unknown', false)).to.be.true);
it('<null>', () => expect(run('404', '/unknown', '@@404:/unknown', true)).to.be.false);
});
describe('should exclude exception type:', () => {
function createException() {
function throwError() {
throw new ReferenceError('This is a test');
}
try {
throwError();
} catch (e) {
return e;
}
}
function run(settingKey: string): boolean {
let client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
if (settingKey) {
client.config.settings[settingKey] = false;
}
let errorParser = new DefaultErrorParser();
let context = new EventPluginContext(client, { type: 'error', data: { } });
context.event.data['@error'] = errorParser.parse(context, createException());
let plugin = new EventExclusionPlugin();
plugin.run(context);
return !!context.cancelled;
}
it('<null>', () => expect(run(null)).to.be.false);
it('@@error:Error', () => expect(run('@@error:Error')).to.be.false);
it('@@error:ReferenceError', () => expect(run('@@error:ReferenceError')).to.be.true);
it('@@error:*Error', () => expect(run('@@error:*Error')).to.be.true);
it('@@error:*', () => expect(run('@@error:*')).to.be.true);
});
});