11import CloudKit
22import CustomDump
3+ import DependenciesTestSupport
34import Foundation
45import InlineSnapshotTesting
56import SharingGRDB
@@ -8,29 +9,7 @@ import Testing
89
910extension BaseCloudKitTests {
1011 @MainActor
11- final class SyncEngineTests : BaseCloudKitTests , @unchecked Sendable {
12- #if os(macOS) && compiler(>=6.2)
13- @available ( iOS 17 , macOS 14 , tvOS 17 , watchOS 10 , * )
14- @Test func foreignKeysDisabled( ) throws {
15- let result = #expect(
16- processExitsWith: . failure,
17- observing: [ \. standardErrorContent]
18- ) {
19- // TODO: finish in Xcode 26
20- // _ = try SyncEngine(
21- // syncEngine.private: MockSyncEngine(scope: .private, state: MockSyncEngineState()),
22- // syncEngine.shared: MockSyncEngine(scope: .shared, state: MockSyncEngineState()),
23- // database: databaseWithForeignKeys(),
24- // tables: []
25- // )
26- }
27- #expect(
28- String ( decoding: try #require( result) . standardOutputContent, as: UTF8 . self)
29- == " Foreign key support must be disabled to synchronize with CloudKit. "
30- )
31- }
32- #endif
33-
12+ final class SyncEngineTests {
3413 @Test func inMemory( ) throws {
3514 #expect( URL ( string: " " ) ? . isInMemory == nil )
3615 #expect( URL ( string: " :memory: " ) ? . isInMemory == true )
@@ -39,14 +18,55 @@ extension BaseCloudKitTests {
3918 #expect( URL ( string: " file:memdb1?mode=memory&cache=shared " ) ? . isInMemory == true )
4019 }
4120
21+ @Test func inMemoryUserDatabase( ) async throws {
22+ let syncEngine = try await SyncEngine (
23+ container: MockCloudContainer (
24+ containerIdentifier: " test " ,
25+ privateCloudDatabase: MockCloudDatabase ( databaseScope: . private) ,
26+ sharedCloudDatabase: MockCloudDatabase ( databaseScope: . shared)
27+ ) ,
28+ userDatabase: UserDatabase ( database: DatabaseQueue ( ) ) ,
29+ tables: [ ]
30+ )
31+
32+ try await syncEngine. userDatabase. read { db in
33+ try SQLQueryExpression (
34+ """
35+ SELECT 1 FROM " sqlitedata_icloud_metadata "
36+ """
37+ )
38+ . execute ( db)
39+ }
40+ }
41+
42+ @Test ( . dependency( \. context, . live) )
43+ func inMemoryUserDatabase_LiveContext( ) async throws {
44+ let error = await #expect( throws: ( any Error ) . self) {
45+ try await SyncEngine (
46+ container: MockCloudContainer (
47+ containerIdentifier: " test " ,
48+ privateCloudDatabase: MockCloudDatabase ( databaseScope: . private) ,
49+ sharedCloudDatabase: MockCloudDatabase ( databaseScope: . shared)
50+ ) ,
51+ userDatabase: UserDatabase ( database: DatabaseQueue ( ) ) ,
52+ tables: [ ]
53+ )
54+ }
55+ assertInlineSnapshot ( of: error, as: . customDump) {
56+ """
57+ InMemoryDatabase()
58+ """
59+ }
60+ }
61+
4262 @Test func metadatabaseMismatch( ) async throws {
4363 let error = await #expect( throws: ( any Error ) . self) {
4464 var configuration = Configuration ( )
4565 configuration. prepareDatabase { db in
4666 try db. attachMetadatabase ( containerIdentifier: " iCloud.co.pointfree " )
4767 }
4868 let database = try DatabasePool (
49- path: NSTemporaryDirectory ( ) + UUID ( ) . uuidString ,
69+ path: " /tmp/db.sqlite " ,
5070 configuration: configuration
5171 )
5272 _ = try await SyncEngine (
@@ -63,8 +83,8 @@ extension BaseCloudKitTests {
6383 #"""
6484 SyncEngine.SchemaError(
6585 reason: .metadatabaseMismatch(
66- attachedPath: "/private/var/folders/vj/bzr5j4ld7cz6jgpphc5kbs8m0000gn/T/.C1938F73-8A6E-40BA-BCF5-A10C07CA1EB6 .metadata-iCloud.co.pointfree.sqlite",
67- syncEngineConfiguredPath: "/var/folders/vj/bzr5j4ld7cz6jgpphc5kbs8m0000gn/T/.C1938F73-8A6E-40BA-BCF5-A10C07CA1EB6 .metadata-iCloud.co.point-free.sqlite"
86+ attachedPath: "/private/tmp/.db .metadata-iCloud.co.pointfree.sqlite",
87+ syncEngineConfiguredPath: "/tmp/.db .metadata-iCloud.co.point-free.sqlite"
6888 ),
6989 debugDescription: "Metadatabase attached in \'prepareDatabase\' does not match metadatabase prepared in \'SyncEngine.init\'. Are the CloudKit container identifiers different?"
7090 )
0 commit comments