Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Sources/SQLiteDataTestSupport/AssertQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ public func assertQuery<
column: column
)
}
let results = includeSQL ? results : sql
do {
@Dependency(\.defaultDatabase) var defaultDatabase
let rows = try (database ?? defaultDatabase).write { try query.fetchAll($0) }
var table = ""
printTable(rows, to: &table)
if rows.isEmpty {
table = "(No results)"
} else {
printTable(rows, to: &table)
}
if !table.isEmpty {
assertInlineSnapshot(
of: table,
Expand All @@ -92,7 +97,7 @@ public func assertQuery<
trailingClosureLabel: "results",
trailingClosureOffset: includeSQL ? 1 : 0
),
matches: includeSQL ? results : sql,
matches: results,
fileID: fileID,
file: filePath,
function: function,
Expand All @@ -108,7 +113,7 @@ public func assertQuery<
trailingClosureLabel: "results",
trailingClosureOffset: includeSQL ? 1 : 0
),
matches: includeSQL ? results : sql,
matches: results,
fileID: fileID,
file: filePath,
function: function,
Expand All @@ -125,7 +130,7 @@ public func assertQuery<
trailingClosureLabel: "results",
trailingClosureOffset: includeSQL ? 1 : 0
),
matches: includeSQL ? results : sql,
matches: results,
fileID: fileID,
file: filePath,
function: function,
Expand Down
24 changes: 24 additions & 0 deletions Tests/SQLiteDataTests/AssertQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ struct AssertQueryTests {
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func assertQueryEmpty() throws {
assertQuery(
Record.all.where { $0.id == -1 }.select(\.id)
) {
"""
(No results)
"""
}
}

@Test(.snapshots(record: .never))
func assertQueryFailsNoResultsNonEmptySnapshot() {
withKnownIssue {
assertQuery(
Record.all.where { _ in false }
) {
"""
XYZ
"""
}
}
}

#if DEBUG
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func assertQueryBasicIncludeSQL() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,11 @@
}
)
func doNotUploadExistingDataToCloudKitWhenSignedOut() {
assertQuery(SyncMetadata.all, database: userDatabase.database)
assertQuery(SyncMetadata.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertInlineSnapshot(of: container, as: .customDump) {
"""
MockCloudContainer(
Expand Down
8 changes: 7 additions & 1 deletion Tests/SQLiteDataTests/CloudKitTests/CloudKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,11 @@
record._recordChangeTag = UUID().uuidString
try await syncEngine.modifyRecords(scope: .private, saving: [record]).notify()

assertQuery(Reminder.all, database: userDatabase.database)
assertQuery(Reminder.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(
SyncMetadata.select(\.userModificationTime),
database: syncEngine.metadatabase
Expand Down Expand Up @@ -736,10 +740,12 @@

assertQuery(RemindersList.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase) {
"""
(No results)
"""
}
assertInlineSnapshot(of: container, as: .customDump) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@
}
assertQuery(ModelB.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(ModelC.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(UnsyncedRecordID.all, database: syncEngine.metadatabase) {
Expand Down Expand Up @@ -180,14 +182,17 @@
}
assertQuery(ModelB.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(ModelC.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(UnsyncedRecordID.all, database: syncEngine.metadatabase) {
"""
(No results)
"""
}
assertInlineSnapshot(of: container, as: .customDump) {
Expand Down Expand Up @@ -335,6 +340,7 @@

assertQuery(Reminder.all, database: userDatabase.database) {
"""
(No results)
"""
}

Expand Down Expand Up @@ -843,7 +849,11 @@
}
}
try await syncEngine.processPendingRecordZoneChanges(scope: .private)
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase)
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase) {
"""
(No results)
"""
}
assertInlineSnapshot(of: container, as: .customDump) {
"""
MockCloudContainer(
Expand Down
42 changes: 35 additions & 7 deletions Tests/SQLiteDataTests/CloudKitTests/SharingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,21 @@

try await syncEngine.processPendingRecordZoneChanges(scope: .shared)

assertQuery(Reminder.all, database: userDatabase.database)
assertQuery(RemindersList.all, database: userDatabase.database)
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase)
assertQuery(Reminder.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(RemindersList.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase) {
"""
(No results)
"""
}

assertInlineSnapshot(of: container, as: .customDump) {
"""
Expand Down Expand Up @@ -1133,9 +1145,21 @@
try await syncEngine.modifyRecordZones(scope: .shared, deleting: [externalZone.zoneID])
.notify()

assertQuery(Reminder.all, database: userDatabase.database)
assertQuery(RemindersList.all, database: userDatabase.database)
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase)
assertQuery(Reminder.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(RemindersList.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(SyncMetadata.all, database: syncEngine.metadatabase) {
"""
(No results)
"""
}

assertInlineSnapshot(of: container, as: .customDump) {
"""
Expand Down Expand Up @@ -2148,7 +2172,11 @@
└────────────────┘
"""
}
assertQuery(ModelC.all, database: userDatabase.database)
assertQuery(ModelC.all, database: userDatabase.database) {
"""
(No results)
"""
}
assertQuery(
SyncMetadata.order { ($0.recordType, $0.recordName) },
database: syncEngine.metadatabase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@
)
"""
}
assertQuery(PendingRecordZoneChange.all, database: syncEngine.metadatabase)
assertQuery(PendingRecordZoneChange.all, database: syncEngine.metadatabase) {
"""
(No results)
"""
}
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
Expand Down
Loading