Skip to content

Commit 76a5c9b

Browse files
committed
Update SentrySDKTests tests
1 parent e5fa2e9 commit 76a5c9b

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

Sources/Swift/Persistence/SentryScopePersistentStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ enum SentryScopeField: UInt, CaseIterable {
118118
}
119119

120120
func writeEnvironmentToDisk(environment: String) {
121-
writeFieldToDisk(field: .user, data: encode(string: environment))
121+
writeFieldToDisk(field: .environment, data: encode(string: environment))
122122
}
123123

124124
// MARK: - Private Functions

Tests/SentryTests/SentrySDKTests.swift

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,62 @@ class SentrySDKTests: XCTestCase {
10181018
let result = try XCTUnwrap(scopePersistentStore.readPreviousUserFromDisk())
10191019
XCTAssertEqual(result.userId, "user1234")
10201020
}
1021+
1022+
func testStartWithOptions_shouldMoveCurrentDistFileToPreviousFile() throws {
1023+
// -- Arrange --
1024+
let (options, dispatchQueueWrapper, scopePersistentStore, observer) = try createTestModels()
1025+
1026+
observer.setDist("dist-string")
1027+
1028+
// Wait for the observer to complete
1029+
let expectation = XCTestExpectation(description: "setDist completes")
1030+
dispatchQueueWrapper.dispatchAsync {
1031+
// Dispatching a block on the same queue will be run after the context processor.
1032+
expectation.fulfill()
1033+
}
1034+
wait(for: [expectation], timeout: 1.0)
1035+
1036+
// Delete the previous context file if it exists
1037+
scopePersistentStore.deleteAllPreviousState()
1038+
// Sanity-check for the pre-condition
1039+
let previousUser = scopePersistentStore.readPreviousDistFromDisk()
1040+
XCTAssertNil(previousUser)
1041+
1042+
// -- Act --
1043+
SentrySDK.start(options: options)
1044+
1045+
// -- Assert --
1046+
let result = try XCTUnwrap(scopePersistentStore.readPreviousDistFromDisk())
1047+
XCTAssertEqual(result, "dist-string")
1048+
}
1049+
1050+
func testStartWithOptions_shouldMoveCurrentEnvironmentFileToPreviousFile() throws {
1051+
// -- Arrange --
1052+
let (options, dispatchQueueWrapper, scopePersistentStore, observer) = try createTestModels()
1053+
1054+
observer.setEnvironment("prod-string")
1055+
1056+
// Wait for the observer to complete
1057+
let expectation = XCTestExpectation(description: "setEnvironment completes")
1058+
dispatchQueueWrapper.dispatchAsync {
1059+
// Dispatching a block on the same queue will be run after the context processor.
1060+
expectation.fulfill()
1061+
}
1062+
wait(for: [expectation], timeout: 1.0)
1063+
1064+
// Delete the previous context file if it exists
1065+
scopePersistentStore.deleteAllPreviousState()
1066+
// Sanity-check for the pre-condition
1067+
let previousUser = scopePersistentStore.readPreviousEnvironmentFromDisk()
1068+
XCTAssertNil(previousUser)
1069+
1070+
// -- Act --
1071+
SentrySDK.start(options: options)
1072+
1073+
// -- Assert --
1074+
let result = try XCTUnwrap(scopePersistentStore.readPreviousEnvironmentFromDisk())
1075+
XCTAssertEqual(result, "prod-string")
1076+
}
10211077
#endif // os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
10221078

10231079
#if os(macOS)

0 commit comments

Comments
 (0)