diff --git a/Tests/GRDBTests/DatabaseConfigurationTests.swift b/Tests/GRDBTests/DatabaseConfigurationTests.swift index b49c9a447..d9ab79d88 100644 --- a/Tests/GRDBTests/DatabaseConfigurationTests.swift +++ b/Tests/GRDBTests/DatabaseConfigurationTests.swift @@ -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 { } + } + } }