forked from getsentry/sentry-cocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestData.swift
332 lines (280 loc) · 10.6 KB
/
TestData.swift
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
import Sentry
import SentryTestUtils
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
import UIKit
#endif
class TestData {
static let timestamp = Date(timeIntervalSince1970: 10)
static var timestampAs8601String: String {
get {
(timestamp as NSDate).sentry_toIso8601String()
}
}
static let sdk = ["name": SentryMeta.sdkName, "version": SentryMeta.versionString]
static let context: [String: [String: Any]] = ["context": ["c": "a", "date": timestamp]]
static var crumb: Breadcrumb {
let crumb = Breadcrumb()
crumb.level = SentryLevel.info
crumb.timestamp = timestamp
crumb.type = "user"
crumb.message = "Clicked something"
crumb.data = ["some": ["data": "data", "date": timestamp] as [String: Any]]
return crumb
}
static var event: Event {
let event = Event(level: SentryLevel.info)
event.breadcrumbs = [crumb]
event.context = context
event.debugMeta = [debugMeta]
event.dist = "dist"
event.environment = "environment"
event.exceptions = [exception]
event.extra = ["some": "extra"]
event.fingerprint = ["fingerprint"]
event.logger = "logger"
event.message = SentryMessage(formatted: "message")
event.modules = ["module": "1"]
event.platform = "Apple"
event.releaseName = SentryMeta.versionString
event.sdk = sdk
event.serverName = "serverName"
event.stacktrace = stacktrace
event.startTimestamp = timestamp
event.tags = ["tag": "tag"]
event.threads = [thread]
event.timestamp = timestamp
event.transaction = "transaction"
event.type = "type"
event.user = user
event.request = request
return event
}
static var user: User {
let user = User(userId: "id")
user.email = "[email protected]"
user.username = "user123"
user.ipAddress = "127.0.0.1"
user.segment = "segmentA"
user.name = "User"
user.geo = geo
user.data = ["some": ["data": "data", "date": timestamp] as [String: Any]]
return user
}
static var geo: Geo {
let geo = Geo()
geo.city = "Vienna"
geo.countryCode = "at"
geo.region = "Vienna"
return geo
}
static var debugMeta: DebugMeta {
let debugMeta = DebugMeta()
debugMeta.imageAddress = "0x0000000105705000"
debugMeta.imageSize = 352_256
debugMeta.imageVmAddress = "0x00007fff51af0000"
debugMeta.name = "/tmp/scratch/dyld_sim"
debugMeta.codeFile = "/tmp/scratch/dyld_sim"
debugMeta.type = "macho"
debugMeta.uuid = "84BAEBDA-AD1A-33F4-B35D-8A45F5DAF322"
debugMeta.debugID = "84BAEBDA-AD1A-33F4-B35D-8A45F5DAF321"
return debugMeta
}
static var exception: Exception {
let exception = Exception(value: "value", type: "type")
exception.mechanism = mechanism
exception.module = "module"
exception.threadId = thread.threadId
exception.stacktrace = thread.stacktrace
return exception
}
static var mechanism: Mechanism {
let currentDateProvider = TestCurrentDateProvider()
let mechanism = Mechanism(type: "type")
mechanism.data = ["something": ["date": currentDateProvider.date()]]
mechanism.desc = "desc"
mechanism.handled = true
mechanism.synthetic = false
mechanism.helpLink = "https://www.sentry.io"
mechanism.meta = mechanismMeta
return mechanism
}
static var mechanismMeta: MechanismMeta {
let mechanismMeta = MechanismMeta()
mechanismMeta.machException = [
"name": "EXC_BAD_ACCESS",
"exception": 1,
"subcode": 8,
"code": 0
]
mechanismMeta.signal = [
"number": 10,
"code": 0,
"name": "SIGBUS",
"code_name": "BUS_NOOP"
]
mechanismMeta.error = SentryNSError(domain: "SentrySampleDomain", code: 1)
return mechanismMeta
}
static var thread: SentryThread {
let thread = SentryThread(threadId: 10)
thread.crashed = false
thread.current = true
thread.name = "main"
thread.stacktrace = stacktrace
thread.isMain = true
return thread
}
static var thread2: SentryThread {
let thread = SentryThread(threadId: 0)
thread.crashed = false
thread.current = true
thread.name = "main"
thread.stacktrace = stacktrace2
return thread
}
static var stacktrace: SentryStacktrace {
let stacktrace = SentryStacktrace(frames: [mainFrame], registers: ["register": "one"])
stacktrace.snapshot = true
return stacktrace
}
static var stacktrace2: SentryStacktrace {
let stacktrace = SentryStacktrace(frames: [mainFrame, testFrame], registers: ["register": "one"])
stacktrace.snapshot = true
return stacktrace
}
static var mainFrame: Frame {
let frame = Frame()
frame.columnNumber = 1
frame.fileName = "fileName"
frame.function = "main"
frame.imageAddress = "0x0000000105705000"
frame.inApp = true
frame.instructionAddress = "0x000000008fd09c40"
frame.lineNumber = 207
frame.module = "module"
frame.package = "sentrytest"
frame.platform = "iOS"
frame.symbolAddress = "0x000000008e902bf0"
frame.stackStart = true
return frame
}
static var testFrame: Frame {
let frame = Frame()
frame.columnNumber = 1
frame.fileName = "testFile"
frame.function = "test"
frame.imageAddress = "0x0000000105705000"
frame.inApp = true
frame.instructionAddress = "0x000000008fd09c90"
frame.lineNumber = 107
frame.module = "module"
frame.package = "sentrytest"
frame.platform = "iOS"
frame.symbolAddress = "0x000000008e902b97"
frame.stackStart = false
return frame
}
static var outsideFrame: Frame {
let frame = Frame()
frame.columnNumber = 1
frame.fileName = "helperFile"
frame.function = "helper"
frame.imageAddress = "0x0000000105709000"
frame.inApp = false
frame.instructionAddress = "0x000000008fd09a40"
frame.lineNumber = 307
frame.module = "outsideModule"
frame.package = "ThirdPartyLib"
frame.platform = "iOS"
frame.symbolAddress = "0x000000008e902e51"
frame.stackStart = false
return frame
}
static var debugImage: DebugMeta {
let image = DebugMeta()
image.name = "sentrytest"
image.imageAddress = "0x0000000105705000"
image.imageVmAddress = "0x0000000105705000"
return image
}
static var fileAttachment: Attachment {
return Attachment(path: "path/to/file.txt", filename: "file.txt")
}
static var dataAttachment: Attachment {
return Attachment(data: "hello".data(using: .utf8)!, filename: "file.txt")
}
static var spanContext: SpanContext {
SpanContext(operation: "Test Context")
}
enum SampleError: Error {
case bestDeveloper
case happyCustomer
case awesomeCentaur
}
static var someUUID = "12345678-1234-1234-1234-12344567890AB"
static var appState: SentryAppState {
return SentryAppState(releaseName: "1.0.0", osVersion: "14.4.1", vendorId: someUUID, isDebugging: false, systemBootTimestamp: timestamp)
}
static var oomEvent: Event {
let event = Event(level: SentryLevel.fatal)
let exception = Exception(value: SentryWatchdogTerminationExceptionValue, type: SentryWatchdogTerminationExceptionType)
exception.mechanism = Mechanism(type: SentryWatchdogTerminationMechanismType)
event.exceptions = [exception]
return event
}
static var metricKitEvent: Event {
let event = Event(level: .warning)
let exception = Exception(value: "MXCPUException totalCPUTime:90.009 sec totalSampledTime:91.952 sec", type: SentryMetricKitCpuExceptionType)
exception.mechanism = Mechanism(type: SentryMetricKitCpuExceptionMechanism)
event.exceptions = [exception]
return event
}
static func scopeWith(observer: SentryScopeObserver) -> Scope {
let scope = Scope()
scope.add(observer)
scope.setUser(TestData.user)
scope.setDist("dist")
setContext(scope)
scope.setEnvironment("Production")
let tags = ["tag1": "tag1", "tag2": "tag2"]
scope.setTags(tags)
scope.setExtras(["extra1": "extra1", "extra2": "extra2"])
scope.setFingerprint(["finger", "print"])
scope.setLevel(SentryLevel.fatal)
let crumb1 = TestData.crumb
crumb1.message = "Crumb 1"
scope.addBreadcrumb(crumb1)
let crumb2 = TestData.crumb
crumb2.message = "Crumb 2"
scope.addBreadcrumb(crumb2)
return scope
}
static var userFeedback: UserFeedback {
let userFeedback = UserFeedback(eventId: SentryId())
userFeedback.comments = "It doesn't really"
userFeedback.email = "[email protected]"
userFeedback.name = "John Me"
return userFeedback
}
static func setContext(_ scope: Scope) {
scope.setContext(value: TestData.context["context"]!, key: "context")
}
static var request: SentryRequest {
let request = SentryRequest()
request.url = "https://sentry.io"
request.fragment = "fragment"
request.bodySize = 10
request.queryString = "query"
request.cookies = "cookies"
request.method = "GET"
request.headers = ["header": "value"]
return request
}
static func getAppStartMeasurement(type: SentryAppStartType, appStartTimestamp: Date = TestData.timestamp) -> SentryAppStartMeasurement {
let appStartDuration = 0.5
let main = appStartTimestamp.addingTimeInterval(0.15)
let runtimeInit = appStartTimestamp.addingTimeInterval(0.05)
let didFinishLaunching = appStartTimestamp.addingTimeInterval(0.3)
return SentryAppStartMeasurement(type: type, isPreWarmed: false, appStartTimestamp: appStartTimestamp, duration: appStartDuration, runtimeInitTimestamp: runtimeInit, moduleInitializationTimestamp: main, didFinishLaunchingTimestamp: didFinishLaunching)
}
}