-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathcrashtracker.spec.js
More file actions
164 lines (123 loc) · 4.68 KB
/
Copy pathcrashtracker.spec.js
File metadata and controls
164 lines (123 loc) · 4.68 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
155
156
157
158
159
160
161
162
163
164
'use strict'
const assert = require('node:assert/strict')
const os = require('node:os')
const proxyquire = require('proxyquire')
const sinon = require('sinon')
require('../setup/core')
const describeNotWindows = os.platform() !== 'win32' ? describe : describe.skip
describeNotWindows('crashtracker', () => {
let crashtracker
let binding
let config
let libdatadog
let log
beforeEach(() => {
libdatadog = require('@datadog/libdatadog')
binding = libdatadog.load('crashtracker')
config = {
port: 7357,
tags: {
foo: 'bar',
},
}
log = {
error: sinon.stub(),
}
sinon.stub(binding, 'init')
sinon.stub(binding, 'updateConfig')
sinon.stub(binding, 'updateMetadata')
crashtracker = proxyquire('../../src/crashtracking/crashtracker', {
'../log': log,
})
})
afterEach(() => {
binding.init.restore()
binding.updateConfig.restore()
binding.updateMetadata.restore()
})
describe('start', () => {
it('should initialize the binding', () => {
crashtracker.start(config)
sinon.assert.called(binding.init)
sinon.assert.notCalled(log.error)
})
it('should initialize the binding only once', () => {
crashtracker.start(config)
crashtracker.start(config)
sinon.assert.calledOnce(binding.init)
})
it('should reconfigure when started multiple times', () => {
crashtracker.start(config)
crashtracker.start(config)
sinon.assert.called(binding.updateConfig)
sinon.assert.called(binding.updateMetadata)
})
it('should handle errors', () => {
crashtracker.start(null)
assert.doesNotThrow(() => crashtracker.start(config))
})
it('should handle unix sockets', () => {
config.url = new URL('unix:///var/datadog/apm/test.socket')
crashtracker.start(config)
sinon.assert.called(binding.init)
sinon.assert.notCalled(log.error)
})
})
describe('configure', () => {
it('should reconfigure the binding when started', () => {
crashtracker.start(config)
crashtracker.configure(config)
sinon.assert.called(binding.updateConfig)
sinon.assert.called(binding.updateMetadata)
})
it('should reconfigure the binding only when started', () => {
crashtracker.configure(config)
sinon.assert.notCalled(binding.updateConfig)
sinon.assert.notCalled(binding.updateMetadata)
})
it('should handle errors', () => {
crashtracker.start(config)
crashtracker.configure(null)
assert.doesNotThrow(() => crashtracker.configure(config))
})
})
describe('process tags', () => {
it('should include process tags in metadata', () => {
crashtracker.start(config)
sinon.assert.calledOnce(binding.init)
const metadata = binding.init.firstCall.args[2]
assert.ok(metadata)
assert.ok(Array.isArray(metadata.tags))
// Check that process tags are included
const hasEntrypointType = metadata.tags.some(tag => tag.startsWith('entrypoint.type:'))
const hasEntrypointName = metadata.tags.some(tag => tag.startsWith('entrypoint.name:'))
const hasEntrypointWorkdir = metadata.tags.some(tag => tag.startsWith('entrypoint.workdir:'))
const hasEntrypointBasedir = metadata.tags.some(tag => tag.startsWith('entrypoint.basedir:'))
assert.ok(hasEntrypointType, 'should include entrypoint.type tag')
assert.ok(hasEntrypointName, 'should include entrypoint.name tag')
assert.ok(hasEntrypointWorkdir, 'should include entrypoint.workdir tag')
assert.ok(hasEntrypointBasedir, 'should include entrypoint.basedir tag')
})
it('should include user tags and process tags together', () => {
crashtracker.start(config)
const metadata = binding.init.firstCall.args[2]
// Check that user tags are included
const hasFooTag = metadata.tags.some(tag => tag === 'foo:bar')
assert.ok(hasFooTag, 'should include user-defined tags')
// Check that process tags are also included
const hasProcessTags = metadata.tags.some(tag => tag.startsWith('entrypoint.'))
assert.ok(hasProcessTags, 'should include process tags')
})
it('should update process tags when reconfiguring', () => {
crashtracker.start(config)
crashtracker.configure(config)
sinon.assert.called(binding.updateMetadata)
const metadata = binding.updateMetadata.firstCall.args[0]
assert.ok(metadata)
assert.ok(Array.isArray(metadata.tags))
// Verify process tags are in the updated metadata
const hasProcessTags = metadata.tags.some(tag => tag.startsWith('entrypoint.'))
assert.ok(hasProcessTags, 'should include process tags in updated metadata')
})
})
})