@@ -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