Skip to content

Commit 07392a3

Browse files
committed
Drop logHandler from withApp
# Conflicts: # Tests/AppTests/Helpers/TestSupport.swift
1 parent d0fe059 commit 07392a3

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

Tests/AppTests/AnalyzeErrorTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ extension AllTests.AnalyzeErrorTests {
6262

6363
@Test func analyze_refreshCheckout_failed() async throws {
6464
let capturingLogger = CapturingLogger()
65-
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
65+
try await withApp(setup, defaultDependencies) { app in
6666
try await withDependencies {
6767
$0.environment.loadSPIManifest = { _ in nil }
6868
$0.fileManager.fileExists = { @Sendable _ in true }
69+
$0.logger.set(to: capturingLogger)
6970
$0.shell.run = { @Sendable cmd, path in
7071
switch cmd {
7172
case _ where cmd.description.contains("git clone https://github.com/foo/1"):
@@ -95,10 +96,11 @@ extension AllTests.AnalyzeErrorTests {
9596

9697
@Test func analyze_updateRepository_invalidPackageCachePath() async throws {
9798
let capturingLogger = CapturingLogger()
98-
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
99+
try await withApp(setup, defaultDependencies) { app in
99100
try await withDependencies {
100101
$0.environment.loadSPIManifest = { _ in nil }
101102
$0.fileManager.fileExists = { @Sendable _ in true }
103+
$0.logger.set(to: capturingLogger)
102104
} operation: {
103105
// setup
104106
let pkg = try await Package.find(badPackageID, on: app.db).unwrap()
@@ -124,10 +126,11 @@ extension AllTests.AnalyzeErrorTests {
124126

125127
@Test func analyze_getPackageInfo_gitCheckout_error() async throws {
126128
let capturingLogger = CapturingLogger()
127-
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
129+
try await withApp(setup, defaultDependencies) { app in
128130
try await withDependencies {
129131
$0.environment.loadSPIManifest = { _ in nil }
130132
$0.fileManager.fileExists = { @Sendable _ in true }
133+
$0.logger.set(to: capturingLogger)
131134
$0.shell.run = { @Sendable cmd, path in
132135
switch cmd {
133136
case .gitCheckout(branch: "main", quiet: true) where path.hasSuffix("foo-1"):
@@ -154,7 +157,7 @@ extension AllTests.AnalyzeErrorTests {
154157

155158
@Test func analyze_dumpPackage_missing_manifest() async throws {
156159
let capturingLogger = CapturingLogger()
157-
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
160+
try await withApp(setup, defaultDependencies) { app in
158161
try await withDependencies {
159162
$0.environment.loadSPIManifest = { _ in nil }
160163
$0.fileManager.fileExists = { @Sendable path in
@@ -163,6 +166,7 @@ extension AllTests.AnalyzeErrorTests {
163166
}
164167
return true
165168
}
169+
$0.logger.set(to: capturingLogger)
166170
} operation: {
167171
// MUT
168172
try await Analyze.analyze(client: app.client,

Tests/AppTests/AnalyzerTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ extension AllTests.AnalyzerTests {
14411441
// Ensure `latest` remains set in case of AppError.noValidVersions
14421442
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2571
14431443
let capturingLogger = CapturingLogger()
1444-
try await withApp(logHandler: capturingLogger) { app in
1444+
try await withApp { app in
14451445
try await withDependencies {
14461446
$0.date.now = .now
14471447
$0.fileManager.fileExists = { @Sendable _ in true }
@@ -1456,6 +1456,7 @@ extension AllTests.AnalyzerTests {
14561456
1\tPerson 2
14571457
"""
14581458
}
1459+
$0.logger.set(to: capturingLogger)
14591460
$0.shell.run = { @Sendable _, _ in return "" }
14601461
} operation: {
14611462
let pkgId = UUID()

Tests/AppTests/ErrorReportingTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ extension AllTests.ErrorReportingTests {
3737

3838
@Test func Ingestion_error_reporting() async throws {
3939
let capturingLogger = CapturingLogger()
40-
try await withApp(logHandler: capturingLogger) { app in
40+
try await withApp { app in
4141
// setup
4242
try await Package(id: .id0, url: "1", processingStage: .reconciliation).save(on: app.db)
4343

4444
try await withDependencies {
4545
$0.date.now = .now
4646
$0.github.fetchMetadata = { @Sendable _, _ throws(Github.Error) in throw Github.Error.invalidURL("1") }
47+
$0.logger.set(to: capturingLogger)
4748
} operation: {
4849
// MUT
4950
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))
@@ -61,14 +62,15 @@ extension AllTests.ErrorReportingTests {
6162
let capturingLogger = CapturingLogger()
6263
try await withDependencies {
6364
$0.fileManager.fileExists = { @Sendable _ in true }
65+
$0.logger.set(to: capturingLogger)
6466
$0.shell.run = { @Sendable cmd, _ in
6567
if cmd.description == "git tag" { return "1.0.0" }
6668
// returning a blank string will cause an exception when trying to
6769
// decode it as the manifest result - we use this to simulate errors
6870
return "invalid"
6971
}
7072
} operation: {
71-
try await withApp(logHandler: capturingLogger) { app in
73+
try await withApp { app in
7274
// setup
7375
try await Package(id: .id1, url: "1".asGithubUrl.url, processingStage: .ingestion).save(on: app.db)
7476

Tests/AppTests/Helpers/TestSupport.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import PostgresNIO
2121

2222
func withApp(_ setup: (Application) async throws -> Void = { _ in },
2323
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in },
24-
logHandler: LogHandler? = nil,
2524
environment: Environment = .testing,
2625
_ test: (Application) async throws -> Void) async throws {
2726
try await TestSupport.setupDb(environment)
@@ -30,11 +29,7 @@ func withApp(_ setup: (Application) async throws -> Void = { _ in },
3029
return try await run {
3130
try await setup(app)
3231
try await withDependencies(updateValuesForOperation) {
33-
try await withDependencies {
34-
$0.logger.set(to: logHandler)
35-
} operation: {
36-
try await test(app)
37-
}
32+
try await test(app)
3833
}
3934
} defer: {
4035
try await app.asyncShutdown()

Tests/AppTests/IngestionTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ extension AllTests.IngestionTests {
383383
// Test error behaviour when two packages resolving to the same owner/name are ingested:
384384
// - don't create repository records
385385
let capturingLogger = CapturingLogger()
386-
try await withApp(logHandler: capturingLogger) { app in
386+
try await withApp { app in
387387
// setup
388388
try await Package(id: .id0, url: "https://github.com/foo/0", status: .ok, processingStage: .reconciliation)
389389
.save(on: app.db)
@@ -413,6 +413,7 @@ extension AllTests.IngestionTests {
413413
summary: "desc")
414414
}
415415
$0.github.fetchReadme = { @Sendable _, _ in nil }
416+
$0.logger.set(to: capturingLogger)
416417
} operation: {
417418
// MUT
418419
try await Ingestion.ingest(client: app.client, database: app.db, mode: .limit(10))

0 commit comments

Comments
 (0)