Skip to content

Commit 827b50c

Browse files
authored
chore: Restore PrivateSentrySDKOnlyTests (#6519)
1 parent 5cd61e0 commit 827b50c

File tree

2 files changed

+56
-50
lines changed

2 files changed

+56
-50
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@
978978
D8FFE50C2703DBB400607131 /* SwizzlingCallTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8FFE50B2703DAAE00607131 /* SwizzlingCallTests.swift */; };
979979
F40E42352EA1887000E53876 /* SentryFramesTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40E42342EA1887000E53876 /* SentryFramesTracker.swift */; };
980980
F40E423C2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40E423B2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift */; };
981+
F40E42FB2EAAAD4500E53876 /* PrivateSentrySDKOnlyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F40E42FA2EAAAD4500E53876 /* PrivateSentrySDKOnlyTests.swift */; };
981982
F41362112E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362102E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift */; };
982983
F41362132E1C566100B84443 /* SentryScopePersistentStore+User.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362122E1C566100B84443 /* SentryScopePersistentStore+User.swift */; };
983984
F41362152E1C568400B84443 /* SentryScopePersistentStore+Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362142E1C568400B84443 /* SentryScopePersistentStore+Context.swift */; };
@@ -2357,6 +2358,7 @@
23572358
D8FFE50B2703DAAE00607131 /* SwizzlingCallTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwizzlingCallTests.swift; sourceTree = "<group>"; };
23582359
F40E42342EA1887000E53876 /* SentryFramesTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFramesTracker.swift; sourceTree = "<group>"; };
23592360
F40E423B2EA18E8000E53876 /* SentryDelayedFramesTrackerWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDelayedFramesTrackerWrapper.swift; sourceTree = "<group>"; };
2361+
F40E42FA2EAAAD4500E53876 /* PrivateSentrySDKOnlyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateSentrySDKOnlyTests.swift; sourceTree = "<group>"; };
23602362
F41362102E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+Tags.swift"; sourceTree = "<group>"; };
23612363
F41362122E1C566100B84443 /* SentryScopePersistentStore+User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+User.swift"; sourceTree = "<group>"; };
23622364
F41362142E1C568400B84443 /* SentryScopePersistentStore+Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+Context.swift"; sourceTree = "<group>"; };
@@ -3060,6 +3062,7 @@
30603062
92235CAF2E155B2600865983 /* SentryLoggerTests.swift */,
30613063
928BED2A2E16977A00B4D398 /* SentryLogBatcherTests.swift */,
30623064
F49D41992DEA2FB000D9244E /* SentryCrashExceptionApplicationTests.swift */,
3065+
F40E42FA2EAAAD4500E53876 /* PrivateSentrySDKOnlyTests.swift */,
30633066
7B6438AD26A710E6000D0F65 /* Categories */,
30643067
D8BC28D32C00C6A60054DA4D /* Extensions */,
30653068
7BD7299B24654CD500EA3610 /* Helper */,
@@ -6395,6 +6398,7 @@
63956398
D8B76B062808066D000A58C4 /* SentryScreenshotIntegrationTests.swift in Sources */,
63966399
7B8CA85726DD4E6200DD872C /* SentryNetworkTrackerIntegrationTests.swift in Sources */,
63976400
D452FE6D2DDC873A00AFF56F /* SentryWatchdogTerminationAttributesProcessorTests.swift in Sources */,
6401+
F40E42FB2EAAAD4500E53876 /* PrivateSentrySDKOnlyTests.swift in Sources */,
63986402
7BAF3DD2243DD05C008A5414 /* SentryTransportInitializerTests.swift in Sources */,
63996403
7B68D93625FF5F1A0082D139 /* SentryAppState+Equality.m in Sources */,
64006404
7B5CAF7E27F5AD3500ED0DB6 /* TestNSURLRequestBuilder.m in Sources */,

Tests/SentryTests/PrivateSentrySDKOnlyTests.swift

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@testable import Sentry
2-
import SentryTestUtils
1+
@_spi(Private) @testable import Sentry
2+
@_spi(Private) import SentryTestUtils
33
import XCTest
44

55
class PrivateSentrySDKOnlyTests: XCTestCase {
@@ -16,7 +16,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
1616

1717
func testStoreEnvelope() {
1818
let client = TestClient(options: Options())
19-
SentrySDK.setCurrentHub(TestHub(client: client, andScope: nil))
19+
SentrySDKInternal.setCurrentHub(TestHub(client: client, andScope: nil))
2020

2121
let envelope = TestConstants.envelope
2222
PrivateSentrySDKOnly.store(envelope)
@@ -28,15 +28,15 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
2828
func testStoreEnvelopeWithUndhandled_MarksSessionAsCrashedAndDoesNotStartNewSession() throws {
2929
let client = TestClient(options: Options())
3030
let hub = TestHub(client: client, andScope: nil)
31-
SentrySDK.setCurrentHub(hub)
31+
SentrySDKInternal.setCurrentHub(hub)
3232
hub.setTestSession()
3333
let sessionToBeCrashed = hub.session
3434

3535
let envelope = getUnhandledExceptionEnvelope()
3636
PrivateSentrySDKOnly.store(envelope)
3737

3838
let storedEnvelope = client?.storedEnvelopeInvocations.first
39-
let attachedSessionData = storedEnvelope!.items.last!.data
39+
let attachedSessionData = try XCTUnwrap(storedEnvelope!.items.last!.data)
4040
let attachedSession = try XCTUnwrap(try! JSONSerialization.jsonObject(with: attachedSessionData) as? [String: Any])
4141

4242
XCTAssertEqual(0, hub.startSessionInvocations)
@@ -47,7 +47,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
4747

4848
func testCaptureEnvelope() {
4949
let client = TestClient(options: Options())
50-
SentrySDK.setCurrentHub(TestHub(client: client, andScope: nil))
50+
SentrySDKInternal.setCurrentHub(TestHub(client: client, andScope: nil))
5151

5252
let envelope = TestConstants.envelope
5353
PrivateSentrySDKOnly.capture(envelope)
@@ -59,15 +59,15 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
5959
func testCaptureEnvelopeWithUndhandled_MarksSessionAsCrashedAndStartsNewSession() throws {
6060
let client = TestClient(options: Options())
6161
let hub = TestHub(client: client, andScope: nil)
62-
SentrySDK.setCurrentHub(hub)
62+
SentrySDKInternal.setCurrentHub(hub)
6363
hub.setTestSession()
6464
let sessionToBeCrashed = hub.session
6565

6666
let envelope = getUnhandledExceptionEnvelope()
6767
PrivateSentrySDKOnly.capture(envelope)
6868

6969
let capturedEnvelope = client?.captureEnvelopeInvocations.first
70-
let attachedSessionData = capturedEnvelope!.items.last!.data
70+
let attachedSessionData = try XCTUnwrap(capturedEnvelope!.items.last!.data)
7171
let attachedSession = try XCTUnwrap(try! JSONSerialization.jsonObject(with: attachedSessionData) as? [String: Any])
7272

7373
// Assert new session was started
@@ -126,27 +126,19 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
126126
XCTAssertNil(PrivateSentrySDKOnly.envelope(with: itemData))
127127
}
128128

129-
func testGetDebugImages() {
130-
let images = PrivateSentrySDKOnly.getDebugImages()
131-
132-
// Only make sure we get some images. The actual tests are in
133-
// SentryDebugImageProviderTests
134-
XCTAssertGreaterThan(images.count, 100)
135-
}
136-
137129
#if canImport(UIKit)
138130
func testGetAppStartMeasurement() {
139131
let appStartMeasurement = TestData.getAppStartMeasurement(type: .warm, runtimeInitSystemTimestamp: 1)
140-
SentrySDK.setAppStartMeasurement(appStartMeasurement)
132+
SentrySDKInternal.setAppStartMeasurement(appStartMeasurement)
141133

142134
XCTAssertEqual(appStartMeasurement, PrivateSentrySDKOnly.appStartMeasurement)
143135

144-
SentrySDK.setAppStartMeasurement(nil)
136+
SentrySDKInternal.setAppStartMeasurement(nil)
145137
XCTAssertNil(PrivateSentrySDKOnly.appStartMeasurement)
146138
}
147139

148140
func testGetAppStartMeasurementWithSpansCold() throws {
149-
SentrySDK.setAppStartMeasurement(
141+
SentrySDKInternal.setAppStartMeasurement(
150142
TestData.getAppStartMeasurement(type: .cold, runtimeInitSystemTimestamp: 1)
151143
)
152144

@@ -162,7 +154,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
162154
}
163155

164156
func testGetAppStartMeasurementWithSpansPreWarmed() throws {
165-
SentrySDK.setAppStartMeasurement(
157+
SentrySDKInternal.setAppStartMeasurement(
166158
TestData.getAppStartMeasurement(
167159
type: .warm,
168160
runtimeInitSystemTimestamp: 1,
@@ -197,7 +189,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
197189
}
198190

199191
func testGetAppStartMeasurementWithSpansReturnsTimestampsInMs() throws {
200-
SentrySDK.setAppStartMeasurement(
192+
SentrySDKInternal.setAppStartMeasurement(
201193
TestData.getAppStartMeasurement(
202194
type: .cold,
203195
appStartTimestamp: Date(timeIntervalSince1970: 5),
@@ -237,7 +229,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
237229
let options = Options()
238230
options.dsn = TestConstants.dsnAsString(username: "SentryFramesTrackingIntegrationTests")
239231
let client = TestClient(options: options)
240-
SentrySDK.setCurrentHub(TestHub(client: client, andScope: nil))
232+
SentrySDKInternal.setCurrentHub(TestHub(client: client, andScope: nil))
241233

242234
XCTAssertEqual(PrivateSentrySDKOnly.options, options)
243235
}
@@ -254,7 +246,6 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
254246
*/
255247
func testProfilingStartAndCollect() throws {
256248
let image = DebugMeta()
257-
image.name = "sentrytest"
258249
image.imageAddress = "0x0000000105705000"
259250
image.imageVmAddress = "0x0000000105705000"
260251
image.codeFile = "codeFile"
@@ -272,7 +263,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
272263
let options = Options()
273264
options.dsn = TestConstants.dsnAsString(username: "SentryFramesTrackingIntegrationTests")
274265
let client = TestClient(options: options)
275-
SentrySDK.setCurrentHub(TestHub(client: client, andScope: nil))
266+
SentrySDKInternal.setCurrentHub(TestHub(client: client, andScope: nil))
276267

277268
let traceIdA = SentryId()
278269

@@ -287,7 +278,6 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
287278
let debugMeta = try XCTUnwrap(payload?["debug_meta"] as? [String: Any])
288279
let images = try XCTUnwrap(debugMeta["images"] as? [[String: Any]])
289280
let debugImage = try XCTUnwrap(images.first)
290-
XCTAssertEqual(debugImage["name"] as? String, image.name)
291281
XCTAssertEqual(debugImage["image_addr"] as? String, image.imageAddress)
292282
XCTAssertEqual(debugImage["image_vmaddr"] as? String, image.imageVmAddress)
293283
XCTAssertEqual(debugImage["code_file"] as? String, image.codeFile)
@@ -311,7 +301,7 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
311301
let options = Options()
312302
options.dsn = TestConstants.dsnAsString(username: "SentryFramesTrackingIntegrationTests")
313303
let client = TestClient(options: options)
314-
SentrySDK.setCurrentHub(TestHub(client: client, andScope: nil))
304+
SentrySDKInternal.setCurrentHub(TestHub(client: client, andScope: nil))
315305

316306
let traceIdA = SentryId()
317307

@@ -359,12 +349,13 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
359349
#endif
360350

361351
#if canImport(UIKit)
352+
@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
362353
func testCaptureReplayShouldCallReplayIntegration() {
363354
guard #available(iOS 16.0, tvOS 16.0, *) else { return }
364355

365356
let options = Options()
366357
options.setIntegrations([TestSentrySessionReplayIntegration.self])
367-
SentrySDK.start(options: options)
358+
SentrySDKInternal.start(options: options)
368359

369360
PrivateSentrySDKOnly.captureReplay()
370361

@@ -379,74 +370,84 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
379370
let client = TestClient(options: Options())
380371
let scope = Scope()
381372
scope.replayId = VALID_REPLAY_ID
382-
SentrySDK.setCurrentHub(TestHub(client: client, andScope: scope))
373+
SentrySDKInternal.setCurrentHub(TestHub(client: client, andScope: scope))
383374

384375
XCTAssertEqual(PrivateSentrySDKOnly.getReplayId(), VALID_REPLAY_ID)
385376
}
386377

378+
@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
387379
func testAddReplayIgnoreClassesShouldNotFailWhenReplayIsAvailable() {
388380
let options = Options()
389381
options.setIntegrations([TestSentrySessionReplayIntegration.self])
390-
SentrySDK.start(options: options)
382+
SentrySDKInternal.start(options: options)
391383

392384
PrivateSentrySDKOnly.addReplayIgnoreClasses([UILabel.self])
393385
}
394386

387+
@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
395388
func testAddReplayRedactShouldNotFailWhenReplayIsAvailable() {
396389
let options = Options()
397390
options.setIntegrations([TestSentrySessionReplayIntegration.self])
398-
SentrySDK.start(options: options)
391+
SentrySDKInternal.start(options: options)
399392

400393
PrivateSentrySDKOnly.addReplayRedactClasses([UILabel.self])
401394
}
402395

396+
@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
403397
func testAddIgnoreContainer() throws {
404398
class IgnoreContainer: UIView {}
405399

406-
SentrySDK.start {
407-
$0.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1)
400+
SentrySDKInternal.start {
401+
$0.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1)
408402
$0.setIntegrations([SentrySessionReplayIntegration.self])
409403
}
410404

411405
PrivateSentrySDKOnly.setIgnoreContainerClass(IgnoreContainer.self)
412406

413407
let replayIntegration = try getFirstIntegrationAsReplay()
414408

415-
let redactBuilder = replayIntegration.viewPhotographer.getRedactBuild()
409+
let redactBuilder = replayIntegration.viewPhotographer.getRedactBuilder()
416410
XCTAssertTrue(redactBuilder.isIgnoreContainerClassTestOnly(IgnoreContainer.self))
417411
}
418412

413+
@available(*, deprecated, message: "This is deprecated because SentryOptions integrations is deprecated")
419414
func testAddRedactContainer() throws {
420415
class RedactContainer: UIView {}
421416

422-
SentrySDK.start {
423-
$0.experimental.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1)
417+
SentrySDKInternal.start {
418+
$0.sessionReplay = SentryReplayOptions(sessionSampleRate: 1, onErrorSampleRate: 1)
424419
$0.setIntegrations([SentrySessionReplayIntegration.self])
425420
}
426421

427422
PrivateSentrySDKOnly.setRedactContainerClass(RedactContainer.self)
428423

429424
let replayIntegration = try getFirstIntegrationAsReplay()
430425

431-
let redactBuilder = replayIntegration.viewPhotographer.getRedactBuild()
426+
let redactBuilder = replayIntegration.viewPhotographer.getRedactBuilder()
432427
XCTAssertTrue(redactBuilder.isRedactContainerClassTestOnly(RedactContainer.self))
433428
}
434429

435-
func testAddExtraSdkPackages() {
430+
func testAddExtraSdkPackages() throws {
436431
PrivateSentrySDKOnly.addSdkPackage("package1", version: "version1")
437432
PrivateSentrySDKOnly.addSdkPackage("package2", version: "version2")
438433

439-
XCTAssertEqual(
440-
SentrySdkInfo.global().packages,
441-
[
442-
["name": "package1", "version": "version1"],
443-
["name": "package2", "version": "version2"]
444-
]
445-
)
434+
// In swift the order is not guaranteed
435+
let packages = try SentrySdkInfo.global().packages.sorted { package1, package2 in
436+
try XCTUnwrap(package1["name"]) < XCTUnwrap(package2["name"])
437+
}
438+
let expected = [
439+
["name": "package1", "version": "version1"],
440+
["name": "package2", "version": "version2"]
441+
]
442+
XCTAssertEqual(packages.count, expected.count)
443+
for (index, package) in packages.enumerated() {
444+
XCTAssertEqual(expected[index]["name"], package["name"])
445+
XCTAssertEqual(expected[index]["version"], package["version"])
446+
}
446447
}
447448

448449
private func getFirstIntegrationAsReplay() throws -> SentrySessionReplayIntegration {
449-
return try XCTUnwrap(SentrySDK.currentHub().installedIntegrations().first as? SentrySessionReplayIntegration)
450+
return try XCTUnwrap(SentrySDKInternal.currentHub().installedIntegrations().first as? SentrySessionReplayIntegration)
450451
}
451452

452453
private let VALID_REPLAY_ID = "0eac7ab503354dd5819b03e263627a29"
@@ -481,17 +482,18 @@ class PrivateSentrySDKOnlyTests: XCTestCase {
481482
func testSetTrace() {
482483
// -- Arrange --
483484
let traceId = SentryId()
484-
let spanId = SentrySpanId()
485+
let spanId = SpanId()
485486

486487
let scope = Scope()
487-
let hub = TestHub(client: nil, andScope: scope)
488-
SentrySDK.setCurrentHub(hub)
488+
let client = TestClient(options: Options())
489+
let hub = TestHub(client: client, andScope: scope)
490+
SentrySDKInternal.setCurrentHub(hub)
489491

490492
// -- Act --
491493
PrivateSentrySDKOnly.setTrace(traceId, spanId: spanId)
492494

493495
// -- Assert --
494-
XCTAssertEqual(scope.propagationContext?.traceId, traceId)
495-
XCTAssertEqual(scope.propagationContext?.spanId, spanId)
496+
XCTAssertEqual(scope.propagationContext.traceId, traceId)
497+
XCTAssertEqual(scope.propagationContext.spanId, spanId)
496498
}
497499
}

0 commit comments

Comments
 (0)