Files
ccn/Packages/Persistence/Tests/Utils/Methods/WithDatabase.swift
T

28 lines
629 B
Swift

import HummingbirdFluent
import Logging
@testable import Persistence
/// Runs the body against a migrated, seeded in-memory database, shutting the pool down after — even on failure, or the pool asserts on `deinit`.
func withDatabase(
_ body: (Fluent) async throws -> Void
) async throws {
let fluent = try Service(
driver: .inMemory,
logger: Logger(label: "test")
)()
do {
await PrepareDB()(for: fluent)
try await fluent.migrate()
try await body(fluent)
} catch {
try? await fluent.shutdown()
throw error
}
try await fluent.shutdown()
}