From d4928eff9998909dca602d567fb04ba75b49d5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 3 Sep 2019 09:07:14 +0200 Subject: [PATCH] Test that prepareDatabase errors are rethrown --- .../DatabaseConfigurationTests.swift | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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 { } + } + } }