This PR contains the work done to do a little bit of housekeeping pass across all packages and the Website service. To provide further details about the work: * Refreshed the READMEs and source documentation to match the current code; * Tagged every test case consistently across the Infrastructure, Localization, Persistence, and Website test targets; * Removed Website middleware tests now covered by Infrastructure's own suite; * Conformed the `PrepareDB` method to Sendable; * Relaxes the production Compose DATABASE_TLS default from require to prefer; * Added Persistence test verifying the prefer posture falls back to plaintext connections. Reviewed-on: rock-n-code/loud-amsterdam#27 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
80 lines
1.8 KiB
Swift
80 lines
1.8 KiB
Swift
import FluentKit
|
|
import HummingbirdFluent
|
|
import Logging
|
|
import Testing
|
|
|
|
@testable import Persistence
|
|
|
|
@Suite(
|
|
"Probe method",
|
|
.tags(.method)
|
|
)
|
|
struct ProbeTests {
|
|
|
|
// MARK: Methods tests
|
|
|
|
@Test
|
|
func `reports a reachable database`() async throws {
|
|
let service = Service(
|
|
driver: .inMemory,
|
|
logger: Logger(label: "test")
|
|
)
|
|
let fluent = service()
|
|
let probe = Probe(fluent: fluent)
|
|
|
|
let isReachable = await probe()
|
|
|
|
try await fluent.shutdown()
|
|
|
|
#expect(isReachable)
|
|
}
|
|
|
|
@Test
|
|
func `reports an unreachable database`() async throws {
|
|
// Port 1 on the loopback interface has nothing listening, so the connection is refused
|
|
// immediately instead of timing out.
|
|
let service = Service(
|
|
driver: .mysql(
|
|
.init(
|
|
host: "127.0.0.1",
|
|
port: 1,
|
|
name: "unreachable",
|
|
username: "nobody",
|
|
password: "nothing",
|
|
tls: .off,
|
|
maxConnectionsPerEventLoop: 1
|
|
)
|
|
),
|
|
logger: Logger(label: "test")
|
|
)
|
|
let fluent = service()
|
|
let probe = Probe(fluent: fluent)
|
|
|
|
let isReachable = await probe()
|
|
|
|
try await fluent.shutdown()
|
|
|
|
#expect(!isReachable)
|
|
}
|
|
|
|
@Test
|
|
func `reports a default database that is not an SQL database`() async throws {
|
|
let fluent = Fluent(logger: Logger(label: "test"))
|
|
|
|
fluent.databases.use(
|
|
.init(make: { NotSQLConfiguration() }),
|
|
as: .init(string: "not-sql"),
|
|
isDefault: true
|
|
)
|
|
|
|
let probe = Probe(fluent: fluent)
|
|
|
|
let isReachable = await probe()
|
|
|
|
try await fluent.shutdown()
|
|
|
|
#expect(!isReachable)
|
|
}
|
|
|
|
}
|