-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.ts
53 lines (46 loc) · 1.54 KB
/
index.spec.ts
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
import { HttpInstrumentation, HttpHandler } from './index';
const span = {
setAttribute: jest.fn(),
setAttributes: jest.fn(),
};
describe('HttpInstrumentation', () => {
const httpHandler = new HttpHandler();
it(`#onRequestBody`, () => {
// @ts-ignore
httpHandler.onRequestBody(span, '{"example": "example" }');
expect(span.setAttributes).toHaveBeenLastCalledWith({
'http.request.body': '{"example": "example" }',
});
});
it(`#onResponseBody`, () => {
// @ts-ignore
httpHandler.onResponseBody(span, '{"example": "example" }');
expect(span.setAttributes).toHaveBeenLastCalledWith({
'http.response.body': '{"example": "example" }',
});
});
it(`#onRequestHeaders`, () => {
// @ts-ignore
httpHandler.onRequestHeaders(span, { 'x-header': 'example' });
expect(span.setAttributes).toHaveBeenLastCalledWith({
'http.request.headers': '{"x-header":"example"}',
});
});
it(`#onResponseHeaders`, () => {
// @ts-ignore
httpHandler.onResponseHeaders(span, { 'x-header': 'example' });
expect(span.setAttributes).toHaveBeenLastCalledWith({
'http.response.headers': '{"x-header":"example"}',
});
});
describe('HttpInstrumentation', () => {
it('mask secrets values', () => {
const httpHandler = new HttpHandler(['my-password']);
// @ts-ignore
httpHandler.onRequestBody(span, '{"password": "my-password" }');
expect(span.setAttributes).toHaveBeenLastCalledWith({
'http.request.body': '{"password": "*****" }',
});
});
});
});