Skip to content

Commit 4a0a963

Browse files
authored
Update tests to compile in Xcode (#17)
* Update tests. * wip
1 parent 8b9bfe7 commit 4a0a963

File tree

3 files changed

+69
-54
lines changed

3 files changed

+69
-54
lines changed

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SharingGRDBTests/IntegrationTests.swift

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,6 @@ import Sharing
55
import SharingGRDB
66
import Testing
77

8-
private struct SyncUp: Codable, Equatable, FetchableRecord, MutablePersistableRecord {
9-
var id: Int64?
10-
var isActive: Bool
11-
var title: String
12-
static let databaseTableName = "syncUps"
13-
mutating func didInsert(_ inserted: InsertionSuccess) {
14-
id = inserted.rowID
15-
}
16-
}
17-
18-
private struct Attendee: Codable, Equatable, FetchableRecord, MutablePersistableRecord {
19-
var id: Int64?
20-
var name: String
21-
var syncUpID: Int
22-
static let databaseTableName = "attendees"
23-
mutating func didInsert(_ inserted: InsertionSuccess) {
24-
id = inserted.rowID
25-
}
26-
}
27-
28-
private extension DatabaseWriter where Self == DatabaseQueue {
29-
static func syncUps() throws -> Self {
30-
let database = try DatabaseQueue()
31-
var migrator = DatabaseMigrator()
32-
migrator.registerMigration("Create schema") { db in
33-
try db.create(table: SyncUp.databaseTableName) { t in
34-
t.autoIncrementedPrimaryKey("id")
35-
t.column("isActive", .boolean).notNull()
36-
t.column("title", .text).notNull()
37-
}
38-
try db.create(table: Attendee.databaseTableName) { t in
39-
t.autoIncrementedPrimaryKey("id")
40-
t.column("syncUpID", .integer).notNull()
41-
t.column("name", .text).notNull()
42-
}
43-
}
44-
try migrator.migrate(database)
45-
return database
46-
}
47-
}
48-
498
@Suite(.dependency(\.defaultDatabase, try .syncUps()))
509
struct IntegrationTests {
5110
@Test
@@ -59,19 +18,19 @@ struct IntegrationTests {
5918
_ = try SyncUp(isActive: true, title: "Engineering")
6019
.inserted(db)
6120
}
62-
try await Task.sleep(for: .seconds(0.1))
21+
try await Task.sleep(nanoseconds: 10_000_000)
6322
#expect(syncUps == [SyncUp(id: 1, isActive: true, title: "Engineering")])
6423
try await database.write { db in
6524
_ = try SyncUp(id: 1, isActive: false, title: "Engineering")
6625
.saved(db)
6726
}
68-
try await Task.sleep(for: .seconds(0.1))
27+
try await Task.sleep(nanoseconds: 10_000_000)
6928
#expect(syncUps == [])
7029
try await database.write { db in
7130
_ = try SyncUp(id: 1, isActive: true, title: "Engineering")
7231
.saved(db)
7332
}
74-
try await Task.sleep(for: .seconds(0.1))
33+
try await Task.sleep(nanoseconds: 10_000_000)
7534
#expect(syncUps == [SyncUp(id: 1, isActive: true, title: "Engineering")])
7635
}
7736

@@ -86,23 +45,64 @@ struct IntegrationTests {
8645
_ = try SyncUp(isActive: true, title: "Engineering")
8746
.inserted(db)
8847
}
89-
try await Task.sleep(for: .seconds(0.1))
48+
try await Task.sleep(nanoseconds: 10_000_000)
9049
#expect(syncUps == [SyncUp(id: 1, isActive: true, title: "Engineering")])
9150
try await database.write { db in
9251
_ = try SyncUp(id: 1, isActive: false, title: "Engineering")
9352
.saved(db)
9453
}
95-
try await Task.sleep(for: .seconds(0.1))
54+
try await Task.sleep(nanoseconds: 10_000_000)
9655
#expect(syncUps == [])
9756
try await database.write { db in
9857
_ = try SyncUp(id: 1, isActive: true, title: "Engineering")
9958
.saved(db)
10059
}
101-
try await Task.sleep(for: .seconds(0.1))
60+
try await Task.sleep(nanoseconds: 10_000_000)
10261
#expect(syncUps == [SyncUp(id: 1, isActive: true, title: "Engineering")])
10362
}
10463
}
10564

65+
private struct SyncUp: Codable, Equatable, FetchableRecord, MutablePersistableRecord {
66+
var id: Int64?
67+
var isActive: Bool
68+
var title: String
69+
static let databaseTableName = "syncUps"
70+
mutating func didInsert(_ inserted: InsertionSuccess) {
71+
id = inserted.rowID
72+
}
73+
}
74+
75+
private struct Attendee: Codable, Equatable, FetchableRecord, MutablePersistableRecord {
76+
var id: Int64?
77+
var name: String
78+
var syncUpID: Int
79+
static let databaseTableName = "attendees"
80+
mutating func didInsert(_ inserted: InsertionSuccess) {
81+
id = inserted.rowID
82+
}
83+
}
84+
85+
private extension DatabaseWriter where Self == DatabaseQueue {
86+
static func syncUps() throws -> Self {
87+
let database = try DatabaseQueue()
88+
var migrator = DatabaseMigrator()
89+
migrator.registerMigration("Create schema") { db in
90+
try db.create(table: SyncUp.databaseTableName) { t in
91+
t.autoIncrementedPrimaryKey("id")
92+
t.column("isActive", .boolean).notNull()
93+
t.column("title", .text).notNull()
94+
}
95+
try db.create(table: Attendee.databaseTableName) { t in
96+
t.autoIncrementedPrimaryKey("id")
97+
t.column("syncUpID", .integer).notNull()
98+
t.column("name", .text).notNull()
99+
}
100+
}
101+
try migrator.migrate(database)
102+
return database
103+
}
104+
}
105+
106106
private struct ActiveSyncUps: FetchKeyRequest {
107107
func fetch(_ db: Database) throws -> [SyncUp] {
108108
try SyncUp

Tests/SharingGRDBTests/SharingGRDBTests.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import Sharing
44
import SharingGRDB
55
import Testing
66

7-
struct GRDBSharingTests {
7+
@Suite struct GRDBSharingTests {
88
@Test
99
func fetchOne() async throws {
10-
try withDependencies {
10+
try await withDependencies {
1111
$0.defaultDatabase = try DatabaseQueue()
1212
} operation: {
1313
@SharedReader(.fetchOne(sql: "SELECT 1")) var bool = false
14+
try await Task.sleep(nanoseconds: 10_000_000)
1415
#expect(bool)
16+
#expect($bool.loadError == nil)
1517
}
1618
}
1719

@@ -24,4 +26,17 @@ struct GRDBSharingTests {
2426
#expect(bool == nil)
2527
}
2628
}
29+
30+
@Test func fetchSyntaxError() async throws {
31+
try await withDependencies {
32+
$0.defaultDatabase = try DatabaseQueue()
33+
} operation: {
34+
@SharedReader(.fetchOne(sql: "SELEC 1")) var bool = false
35+
#expect(bool == false)
36+
try await Task.sleep(nanoseconds: 10_000_000)
37+
#expect($bool.loadError is DatabaseError?)
38+
let error = try #require($bool.loadError as? DatabaseError)
39+
#expect(error.message == #"near "SELEC": syntax error"#)
40+
}
41+
}
2742
}

0 commit comments

Comments
 (0)