Skip to content

Commit a9ae265

Browse files
committed
Make setupApp static, move Current config out of it
1 parent ee604fd commit a9ae265

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Tests/AppTests/AppTestCase.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ class AppTestCase: XCTestCase {
2727
override func setUp() async throws {
2828
try await super.setUp()
2929
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 }))
3035
}
3136

3237
func setup(_ environment: Environment) async throws -> Application {
3338
try await Self.setupDb(environment)
34-
return try await setupApp(environment)
39+
return try await Self.setupApp(environment)
3540
}
3641

3742
override func tearDown() async throws {
@@ -43,18 +48,14 @@ class AppTestCase: XCTestCase {
4348

4449
extension AppTestCase {
4550

46-
func setupApp(_ environment: Environment) async throws -> Application {
51+
static func setupApp(_ environment: Environment) async throws -> Application {
4752
let app = try await Application.make(environment)
4853
let host = try await configure(app)
4954

50-
// Ensure `.testing` refers to "postgres" or "localhost"
55+
// Ensure `.testing` refers to certain restricted db hostnames and nothing else
5156
precondition(["localhost", "postgres", "host.docker.internal"].contains(host),
5257
".testing must be a local db, was: \(host)")
5358

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 }))
5859
// Silence app logging
5960
app.logger = .init(label: "noop") { _ in SwiftLogNoOpLogHandler() }
6061

0 commit comments

Comments
 (0)