-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
79 lines (70 loc) · 1.83 KB
/
index.test.js
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
/* eslint-env jest */
const http = require('http');
const jsonBody = require('body/json');
const setup = require('./');
/** @type {http.Server} */
let server;
/** @type {string} */
let address;
/**
* @type {(call: {
* path: string,
* headers: http.IncomingHttpHeaders,
* body: unknown
* }) => void}
*/
let resolveCall;
beforeAll(async () => {
server = http.createServer((req, res) => {
jsonBody(req, res, (err, body) => {
if (err) {
res.writeHead(500);
res.write(JSON.stringify([{ error: err }]));
} else {
resolveCall({ path: req.url || '', headers: req.headers, body });
res.write(JSON.stringify([{ status: 'ok' }]));
}
res.end();
});
});
await new Promise(done => server.listen(0, 'localhost', () => done(0)));
const addr = server.address();
if (addr && typeof addr == 'object') {
address = 'http://localhost:' + addr.port;
}
});
afterAll(() => {
server.close();
});
it('configures honeycomb for sending events', async () => {
const beeline = setup('testing', 'beefdad', {
APIHost: address,
APIKey: 'keystuff',
GlobalMetadata: {
global: 'fields',
},
DesiredSampleRate: 1,
TracingDataset: '',
});
const callP = new Promise(resolve => {
resolveCall = resolve;
});
const trace = beeline.startTrace({ field: 'value' }, 'trace1', 'parent1');
if (trace) beeline.finishTrace(trace);
const call = await callP;
expect(call.path).toMatch(/\/1\/batch\/testing$/);
expect(call.headers).toHaveProperty('x-honeycomb-team', 'keystuff');
expect(call.body).toMatchObject([
{
samplerate: 1,
data: {
'trace.trace_id': 'trace1',
'trace.parent_id': 'parent1',
service_name: 'testing',
'service.process': 'http',
app_sha: 'beefdad',
global: 'fields',
},
},
]);
});