@@ -27,11 +27,16 @@ class AppTestCase: XCTestCase {
27
27
override func setUp( ) async throws {
28
28
try await super. setUp ( )
29
29
app = try await setup ( . testing)
30
+
31
+ // Always start with a baseline mock environment to avoid hitting live resources
32
+ Current = . mock( eventLoop: app. eventLoopGroup. next ( ) )
33
+
34
+ Current . setLogger ( . init( label: " test " , factory: { _ in logger } ) )
30
35
}
31
36
32
37
func setup( _ environment: Environment ) async throws -> Application {
33
38
try await Self . setupDb ( environment)
34
- return try await setupApp ( environment)
39
+ return try await Self . setupApp ( environment)
35
40
}
36
41
37
42
override func tearDown( ) async throws {
@@ -43,18 +48,14 @@ class AppTestCase: XCTestCase {
43
48
44
49
extension AppTestCase {
45
50
46
- func setupApp( _ environment: Environment ) async throws -> Application {
51
+ static func setupApp( _ environment: Environment ) async throws -> Application {
47
52
let app = try await Application . make ( environment)
48
53
let host = try await configure ( app)
49
54
50
- // Ensure `.testing` refers to "postgres" or "localhost"
55
+ // Ensure `.testing` refers to certain restricted db hostnames and nothing else
51
56
precondition ( [ " localhost " , " postgres " , " host.docker.internal " ] . contains ( host) ,
52
57
" .testing must be a local db, was: \( host) " )
53
58
54
- // Always start with a baseline mock environment to avoid hitting live resources
55
- Current = . mock( eventLoop: app. eventLoopGroup. next ( ) )
56
-
57
- Current . setLogger ( . init( label: " test " , factory: { _ in logger } ) )
58
59
// Silence app logging
59
60
app. logger = . init( label: " noop " ) { _ in SwiftLogNoOpLogHandler ( ) }
60
61
0 commit comments