Test that prepareDatabase errors are rethrown

This commit is contained in:
Gwendal Roué committed 2019-09-03 09:07:14 +02:00
1 parent 1f48405b5c
commit d4928eff99
1 file changed
+43
@@ -29,4 +29,47 @@ class DatabaseConfigurationTests: GRDBTestCase {
try pool.makeSnapshot().read { _ in }
XCTAssertEqual(connectionCount, 5)
}
func testPrepareDatabaseError() throws {
struct TestError: Error { }
var error: TestError?
var configuration = Configuration()
configuration.prepareDatabase = { db in
if let error = error {
throw error
}
}
// TODO: what about in-memory DatabaseQueue???
do {
error = TestError()
_ = try makeDatabaseQueue(configuration: configuration)
XCTFail("Expected TestError")
} catch is TestError { }
do {
error = TestError()
_ = try makeDatabasePool(configuration: configuration)
XCTFail("Expected TestError")
} catch is TestError { }
do {
error = nil
let pool = try makeDatabasePool(configuration: configuration)
do {
error = TestError()
try pool.read { _ in }
XCTFail("Expected TestError")
} catch is TestError { }
do {
error = TestError()
_ = try pool.makeSnapshot()
XCTFail("Expected TestError")
} catch is TestError { }
}
}
}