@@ -26,7 +26,7 @@ import XCTVapor
26
26
#warning("move/rename")
27
27
enum AppTestCase {
28
28
29
- static func setupApp( _ environment: Environment , databasePort: Int ) async throws -> Application {
29
+ static func setupApp( _ environment: Environment , databasePort: Int ? = nil ) async throws -> Application {
30
30
let app = try await Application . make ( environment)
31
31
try await configure ( app, databasePort: databasePort)
32
32
@@ -37,13 +37,14 @@ enum AppTestCase {
37
37
}
38
38
39
39
40
- static func setupDb( _ environment: Environment , databasePort: Int ) async throws {
40
+ static func setupDb( _ environment: Environment , databasePort: Int ? = nil ) async throws {
41
41
await DotEnvFile . load ( for: environment, fileio: . init( threadPool: . singleton) )
42
42
43
43
// Ensure DATABASE_HOST is from a restricted set db hostnames and nothing else.
44
44
// This is safeguard against accidental inheritance of setup in QueryPerformanceTests
45
45
// and to ensure the database resetting cannot impact any other network hosts.
46
46
let host = Environment . get ( " DATABASE_HOST " )
47
+ let databasePort = databasePort ?? Environment . get ( " DATABASE_PORT " ) . flatMap ( Int . init) !
47
48
precondition ( [ " localhost " , " postgres " , " host.docker.internal " ] . contains ( host) ,
48
49
" DATABASE_HOST must be a local db, was: \( host) " )
49
50
@@ -166,7 +167,6 @@ private func connect(to databaseName: String,
166
167
_ environment: Environment ) async throws -> PostgresClient {
167
168
await DotEnvFile . load ( for: environment, fileio: . init( threadPool: . singleton) )
168
169
let host = Environment . get ( " DATABASE_HOST " ) !
169
- // let port = Environment.get("DATABASE_PORT").flatMap(Int.init)!
170
170
let username = Environment . get ( " DATABASE_USERNAME " ) !
171
171
let password = Environment . get ( " DATABASE_PASSWORD " ) !
172
172
0 commit comments