From c6dc9b3948fd30f8a87b0e9dbe52e02fce5c73eb Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Wed, 16 Apr 2025 13:06:29 +0200 Subject: [PATCH] Update to VaporTesting --- Package.swift | 2 +- ...ackageController+GetRoute+ModelTests.swift | 16 +- .../API+PackageController+GetRouteTests.swift | 4 +- .../AppTests/API+PackageControllerTests.swift | 10 +- .../API_DependencyControllerTests.swift | 2 +- Tests/AppTests/AnalyzeErrorTests.swift | 8 +- Tests/AppTests/AnalyzerTests.swift | 60 ++--- .../AnalyzerVersionThrottlingTests.swift | 22 +- Tests/AppTests/ApiTests.swift | 118 ++++----- Tests/AppTests/AppTests.swift | 2 +- .../AppTests/ArrayVersionExtensionTests.swift | 2 +- Tests/AppTests/AuthorControllerTests.swift | 17 +- Tests/AppTests/BuildIndexModelTests.swift | 2 +- .../BuildMonitorControllerTests.swift | 4 +- .../BuildMonitorIndexModelTests.swift | 8 +- Tests/AppTests/BuildResultTests.swift | 2 +- Tests/AppTests/BuildShowModelTests.swift | 2 +- Tests/AppTests/BuildTests.swift | 22 +- Tests/AppTests/BuildTriggerTests.swift | 46 ++-- .../CustomCollectionControllerTests.swift | 12 +- Tests/AppTests/CustomCollectionTests.swift | 20 +- Tests/AppTests/DocUploadTests.swift | 16 +- Tests/AppTests/DocumentationTargetTests.swift | 8 +- Tests/AppTests/ErrorMiddlewareTests.swift | 14 +- Tests/AppTests/ErrorReportingTests.swift | 8 +- Tests/AppTests/GitlabBuilderTests.swift | 2 +- Tests/AppTests/Helpers/Database+ext.swift | 2 +- Tests/AppTests/Helpers/TestSupport.swift | 2 +- Tests/AppTests/HomeIndexModelTests.swift | 2 +- Tests/AppTests/IngestionTests.swift | 32 +-- Tests/AppTests/Joined3Tests.swift | 8 +- Tests/AppTests/JoinedQueryBuilderTests.swift | 2 +- Tests/AppTests/JoinedTests.swift | 6 +- Tests/AppTests/KeywordControllerTests.swift | 14 +- Tests/AppTests/MastodonTests.swift | 2 +- Tests/AppTests/MetricsTests.swift | 14 +- .../PackageCollectionControllerTests.swift | 12 +- Tests/AppTests/PackageCollectionTests.swift | 34 +-- Tests/AppTests/PackageContributorsTests.swift | 2 +- .../PackageController+BuildsRouteTests.swift | 6 +- .../PackageController+routesTests.swift | 234 +++++++++--------- Tests/AppTests/PackageInfoTests.swift | 4 +- .../AppTests/PackageReleasesModelTests.swift | 2 +- Tests/AppTests/PackageResultTests.swift | 14 +- Tests/AppTests/PackageTests.swift | 32 +-- Tests/AppTests/PipelineTests.swift | 18 +- Tests/AppTests/ProductTests.swift | 4 +- Tests/AppTests/RSSTests.swift | 24 +- Tests/AppTests/ReAnalyzeVersionsTests.swift | 6 +- Tests/AppTests/RecentViewsTests.swift | 8 +- Tests/AppTests/ReconcilerTests.swift | 16 +- Tests/AppTests/RepositoryTests.swift | 18 +- Tests/AppTests/RoutesTests.swift | 18 +- Tests/AppTests/SQLKitExtensionTests.swift | 4 +- Tests/AppTests/ScoreTests.swift | 4 +- Tests/AppTests/SearchFilterTests.swift | 26 +- Tests/AppTests/SearchShowModelAppTests.swift | 2 +- Tests/AppTests/SearchTests.swift | 100 ++++---- Tests/AppTests/SitemapTests.swift | 28 +-- Tests/AppTests/SocialTests.swift | 8 +- Tests/AppTests/StatsTests.swift | 2 +- Tests/AppTests/TargetTests.swift | 4 +- Tests/AppTests/VersionDiffTests.swift | 2 +- Tests/AppTests/VersionTests.swift | 14 +- Tests/AppTests/ViewUtilsTests.swift | 2 +- 65 files changed, 581 insertions(+), 580 deletions(-) diff --git a/Package.swift b/Package.swift index c1867bbeb..5dc2d78dc 100644 --- a/Package.swift +++ b/Package.swift @@ -95,7 +95,7 @@ let package = Package( .product(name: "DependenciesTestSupport", package: "swift-dependencies"), .product(name: "SnapshotTesting", package: "swift-snapshot-testing"), .product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"), - .product(name: "XCTVapor", package: "vapor"), + .product(name: "VaporTesting", package: "vapor"), .target(name: "App"), ], exclude: ["__Snapshots__", "Fixtures"], diff --git a/Tests/AppTests/API+PackageController+GetRoute+ModelTests.swift b/Tests/AppTests/API+PackageController+GetRoute+ModelTests.swift index feed830b2..5b7082fbd 100644 --- a/Tests/AppTests/API+PackageController+GetRoute+ModelTests.swift +++ b/Tests/AppTests/API+PackageController+GetRoute+ModelTests.swift @@ -26,7 +26,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { @Test func init_no_packageName() async throws { // Tests behaviour when we're lacking data - try await withApp { app in + try await withSPIApp { app in // setup package without package name let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db) @@ -56,7 +56,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { } @Test func init_packageIdentity() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, URL(string: "https://github.com/foo/swift-bar.git")!) try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db) let version = try App.Version(package: pkg, latest: .defaultBranch, packageName: nil, reference: .branch("main")) @@ -81,7 +81,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { } @Test func init_generated_documentation() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db) let version = try App.Version(package: pkg, latest: .defaultBranch, packageName: nil, reference: .branch("main")) @@ -107,7 +107,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { } @Test func init_external_documentation() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, name: "bar", owner: "foo").save(on: app.db) let version = try App.Version(package: pkg, latest: .defaultBranch, packageName: nil, reference: .branch("main")) @@ -137,7 +137,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { } @Test func ForkedFromInfo_query() async throws { - try await withApp { app in + try await withSPIApp { app in let originalPkg = try await savePackage(on: app.db, id: .id0, "https://github.com/original/original") try await Repository(package: originalPkg, name: "original", @@ -159,7 +159,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { @Test func ForkedFromInfo_query_fallback() async throws { // when the package can't be found resort to fallback URL - try await withApp { app in + try await withSPIApp { app in // MUT let forkedFrom = await API.PackageController.GetRoute.Model.ForkedFromInfo.query(on: app.db, packageId: .id0, fallbackURL: "https://github.com/original/original.git") @@ -544,7 +544,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { } @Test func groupBuildInfo() async throws { - try await withApp { app in + try await withSPIApp { app in let result1: BuildResults = .init(results: [.v5_8: .compatible, .v5_9: .compatible, .v5_10: .compatible, @@ -595,7 +595,7 @@ extension AllTests.API_PackageController_GetRoute_ModelTests { } @Test func languagePlatformInfo() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, diff --git a/Tests/AppTests/API+PackageController+GetRouteTests.swift b/Tests/AppTests/API+PackageController+GetRouteTests.swift index 132f8ad52..eee557f43 100644 --- a/Tests/AppTests/API+PackageController+GetRouteTests.swift +++ b/Tests/AppTests/API+PackageController+GetRouteTests.swift @@ -22,7 +22,7 @@ extension AllTests.API_PackageController_GetRouteTests { typealias PackageResult = PackageController.PackageResult @Test func releaseInfo() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, @@ -70,7 +70,7 @@ extension AllTests.API_PackageController_GetRouteTests { @Test func releaseInfo_exclude_non_latest() async throws { // Test to ensure that we don't include versions with `latest IS NULL` - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, diff --git a/Tests/AppTests/API+PackageControllerTests.swift b/Tests/AppTests/API+PackageControllerTests.swift index 0f99181c0..bb47e19a7 100644 --- a/Tests/AppTests/API+PackageControllerTests.swift +++ b/Tests/AppTests/API+PackageControllerTests.swift @@ -27,7 +27,7 @@ extension AllTests.API_PackageControllerTests { try await withDependencies { $0.date.now = .december15_2020 } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, commitCount: 1433, @@ -66,7 +66,7 @@ extension AllTests.API_PackageControllerTests { try await withDependencies { $0.date.now = .december15_2020 } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, commitCount: 1433, @@ -137,7 +137,7 @@ extension AllTests.API_PackageControllerTests { @Test func ProductCount_query() async throws { // setup - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, defaultBranch: "main", @@ -285,7 +285,7 @@ extension AllTests.API_PackageControllerTests { @Test func BuildInfo_query() async throws { // setup - try await withApp { app in + try await withSPIApp { app in do { let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -353,7 +353,7 @@ extension AllTests.API_PackageControllerTests { @Test func GetRoute_query() async throws { // ensure GetRoute.query is wired up correctly (detailed tests are elsewhere) - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "bar", owner: "foo") diff --git a/Tests/AppTests/API_DependencyControllerTests.swift b/Tests/AppTests/API_DependencyControllerTests.swift index 97ee8a92e..be1c82a53 100644 --- a/Tests/AppTests/API_DependencyControllerTests.swift +++ b/Tests/AppTests/API_DependencyControllerTests.swift @@ -21,7 +21,7 @@ import Vapor extension AllTests.API_DependencyControllerTests { @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, id: .id0, "http://github.com/foo/bar") try await Repository(package: pkg, diff --git a/Tests/AppTests/AnalyzeErrorTests.swift b/Tests/AppTests/AnalyzeErrorTests.swift index 9707b61d9..315b2bfed 100644 --- a/Tests/AppTests/AnalyzeErrorTests.swift +++ b/Tests/AppTests/AnalyzeErrorTests.swift @@ -62,7 +62,7 @@ extension AllTests.AnalyzeErrorTests { @Test func analyze_refreshCheckout_failed() async throws { let capturingLogger = CapturingLogger() - try await withApp(setup, defaultDependencies) { app in + try await withSPIApp(setup, defaultDependencies) { app in try await withDependencies { $0.environment.loadSPIManifest = { _ in nil } $0.fileManager.fileExists = { @Sendable _ in true } @@ -96,7 +96,7 @@ extension AllTests.AnalyzeErrorTests { @Test func analyze_updateRepository_invalidPackageCachePath() async throws { let capturingLogger = CapturingLogger() - try await withApp(setup, defaultDependencies) { app in + try await withSPIApp(setup, defaultDependencies) { app in try await withDependencies { $0.environment.loadSPIManifest = { _ in nil } $0.fileManager.fileExists = { @Sendable _ in true } @@ -126,7 +126,7 @@ extension AllTests.AnalyzeErrorTests { @Test func analyze_getPackageInfo_gitCheckout_error() async throws { let capturingLogger = CapturingLogger() - try await withApp(setup, defaultDependencies) { app in + try await withSPIApp(setup, defaultDependencies) { app in try await withDependencies { $0.environment.loadSPIManifest = { _ in nil } $0.fileManager.fileExists = { @Sendable _ in true } @@ -157,7 +157,7 @@ extension AllTests.AnalyzeErrorTests { @Test func analyze_dumpPackage_missing_manifest() async throws { let capturingLogger = CapturingLogger() - try await withApp(setup, defaultDependencies) { app in + try await withSPIApp(setup, defaultDependencies) { app in try await withDependencies { $0.environment.loadSPIManifest = { _ in nil } $0.fileManager.fileExists = { @Sendable path in diff --git a/Tests/AppTests/AnalyzerTests.swift b/Tests/AppTests/AnalyzerTests.swift index dc4027425..faa1b92b9 100644 --- a/Tests/AppTests/AnalyzerTests.swift +++ b/Tests/AppTests/AnalyzerTests.swift @@ -32,7 +32,7 @@ extension AllTests.AnalyzerTests { // End-to-end test, where we mock at the shell command level (i.e. we // don't mock the git commands themselves to ensure we're running the // expected shell commands for the happy path.) - try await withApp { app in + try await withSPIApp { app in let checkoutDir = QueueIsolated(nil) let firstDirCloned = QueueIsolated(false) let commands = QueueIsolated<[Command]>([]) @@ -215,7 +215,7 @@ extension AllTests.AnalyzerTests { // Ensure that new incoming versions update the latest properties and // move versions in case commits change. Tests both default branch commits // changing as well as a tag being moved to a different commit. - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .now $0.environment.allowSocialPosts = { true } @@ -311,7 +311,7 @@ extension AllTests.AnalyzerTests { @Test func forward_progress_on_analysisError() async throws { // Ensure a package that fails analysis goes back to ingesting and isn't stuck in an analysis loop - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .now $0.fileManager.fileExists = { @Sendable _ in true } @@ -356,7 +356,7 @@ extension AllTests.AnalyzerTests { @Test func package_status() async throws { // Ensure packages record success/error status - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .now $0.environment.allowSocialPosts = { true } @@ -407,7 +407,7 @@ extension AllTests.AnalyzerTests { @Test func continue_on_exception() async throws { // Test to ensure exceptions don't interrupt processing - try await withApp { app in + try await withSPIApp { app in let checkoutDir: NIOLockedValueBox = .init(nil) let commands = QueueIsolated<[Command]>([]) let refs: [Reference] = [.tag(1, 0, 0), .tag(1, 1, 1), .branch("main")] @@ -496,7 +496,7 @@ extension AllTests.AnalyzerTests { } @Test func refreshCheckout() async throws { - try await withApp { app in + try await withSPIApp { app in let commands = QueueIsolated<[String]>([]) try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } @@ -520,7 +520,7 @@ extension AllTests.AnalyzerTests { } @Test func updateRepository() async throws { - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } $0.git.commitCount = { @Sendable _ in 12 } @@ -563,7 +563,7 @@ extension AllTests.AnalyzerTests { } @Test func getIncomingVersions() async throws { - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.git.getTags = { @Sendable _ in [.tag(1, 2, 3)] } $0.git.hasBranch = { @Sendable _, _ in true } @@ -587,7 +587,7 @@ extension AllTests.AnalyzerTests { } @Test func getIncomingVersions_default_branch_mismatch() async throws { - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.git.hasBranch = { @Sendable _, _ in false} // simulate branch mismatch } operation: { @@ -613,7 +613,7 @@ extension AllTests.AnalyzerTests { } @Test func getIncomingVersions_no_default_branch() async throws { - try await withApp { app in + try await withSPIApp { app in // setup // saving Package without Repository means it has no default branch try await Package(id: .id0, url: "1".asGithubUrl.url).save(on: app.db) @@ -632,7 +632,7 @@ extension AllTests.AnalyzerTests { } @Test func diffVersions() async throws { - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.git.getTags = { @Sendable _ in [.tag(1, 2, 3)] } $0.git.hasBranch = { @Sendable _, _ in true } @@ -674,7 +674,7 @@ extension AllTests.AnalyzerTests { @Test func mergeReleaseInfo() async throws { // setup - try await withApp { app in + try await withSPIApp { app in let pkg = Package(id: .id0, url: "1".asGithubUrl.url) try await pkg.save(on: app.db) try await Repository(package: pkg, releases:[ @@ -721,7 +721,7 @@ extension AllTests.AnalyzerTests { @Test func applyVersionDelta() async throws { // Ensure the existing default doc archives are preserved when replacing the default branch version // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2288 - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: .id0, url: "1") try await pkg.save(on: app.db) @@ -746,7 +746,7 @@ extension AllTests.AnalyzerTests { @Test func applyVersionDelta_newRelease() async throws { // Ensure the existing default doc archives aren't copied over to a new release - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: .id0, url: "1") try await pkg.save(on: app.db) @@ -772,7 +772,7 @@ extension AllTests.AnalyzerTests { @Test func getPackageInfo() async throws { // Tests getPackageInfo(package:version:) - try await withApp { app in + try await withSPIApp { app in let commands = QueueIsolated<[String]>([]) try await withDependencies { $0.environment.loadSPIManifest = { _ in nil } @@ -808,7 +808,7 @@ extension AllTests.AnalyzerTests { } @Test func updateVersion() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: UUID(), url: "1") try await pkg.save(on: app.db) @@ -845,7 +845,7 @@ extension AllTests.AnalyzerTests { } @Test func createProducts() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(id: UUID(), url: "1") let v = try Version(id: UUID(), package: p, packageName: "1", reference: .tag(.init(1, 0, 0))) @@ -873,7 +873,7 @@ extension AllTests.AnalyzerTests { } @Test func createTargets() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(id: UUID(), url: "1") let v = try Version(id: UUID(), package: p, packageName: "1", reference: .tag(.init(1, 0, 0))) @@ -895,7 +895,7 @@ extension AllTests.AnalyzerTests { } @Test func updatePackages() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let packages = try await savePackages(on: app.db, ["1", "2"].asURLs) .map(Joined.init(model:)) @@ -920,7 +920,7 @@ extension AllTests.AnalyzerTests { @Test func issue_29() async throws { // Regression test for issue 29 // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/29 - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .now $0.environment.allowSocialPosts = { true } @@ -989,7 +989,7 @@ extension AllTests.AnalyzerTests { @Test func issue_70() async throws { // Certain git commands fail when index.lock exists // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/70 - try await withApp { app in + try await withSPIApp { app in let commands = QueueIsolated<[String]>([]) try await withDependencies { // claim every file exists, including our ficticious 'index.lock' for which @@ -1021,7 +1021,7 @@ extension AllTests.AnalyzerTests { @Test func issue_498() async throws { // git checkout can still fail despite git reset --hard + git clean // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/498 - try await withApp { app in + try await withSPIApp { app in let commands = QueueIsolated<[String]>([]) try await withDependencies { // claim every file exists, including our ficticious 'index.lock' for which @@ -1160,7 +1160,7 @@ extension AllTests.AnalyzerTests { @Test func issue_577() async throws { // Duplicate "latest release" versions // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/577 - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let pkg = Package(id: pkgId, url: "1") @@ -1189,7 +1189,7 @@ extension AllTests.AnalyzerTests { @Test func issue_693() async throws { // Handle moved tags // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/693 - try await withApp { app in + try await withSPIApp { app in let commands = QueueIsolated<[String]>([]) try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } @@ -1215,7 +1215,7 @@ extension AllTests.AnalyzerTests { } @Test func updateLatestVersions() async throws { - try await withApp { app in + try await withSPIApp { app in // setup func t(_ seconds: TimeInterval) -> Date { Date(timeIntervalSince1970: seconds) } let pkg = Package(id: UUID(), url: "1") @@ -1247,7 +1247,7 @@ extension AllTests.AnalyzerTests { // and that faulty db content (outdated beta marked as latest pre-release) // is correctly reset. // See https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/188 - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: UUID(), url: "1") try await pkg.save(on: app.db) @@ -1281,7 +1281,7 @@ extension AllTests.AnalyzerTests { @Test func issue_914() async throws { // Ensure we handle 404 repos properly // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/914 - try await withApp { app in + try await withSPIApp { app in // setup let checkoutDir = "/checkouts" let url = "1".asGithubUrl.url @@ -1341,7 +1341,7 @@ extension AllTests.AnalyzerTests { @Test func issue_2571_tags() async throws { // Ensure bad git commands do not delete existing tag revisions // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2571 - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } $0.git.commitCount = { @Sendable _ in 2 } @@ -1448,7 +1448,7 @@ extension AllTests.AnalyzerTests { // Ensure `latest` remains set in case of AppError.noValidVersions // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2571 let capturingLogger = CapturingLogger() - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .now $0.fileManager.fileExists = { @Sendable _ in true } @@ -1557,7 +1557,7 @@ extension AllTests.AnalyzerTests { @Test func issue_2873() async throws { // Ensure we preserve dependency counts from previous default branch version // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2873 - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .now $0.environment.loadSPIManifest = { _ in nil } diff --git a/Tests/AppTests/AnalyzerVersionThrottlingTests.swift b/Tests/AppTests/AnalyzerVersionThrottlingTests.swift index e656b682c..f702cd11e 100644 --- a/Tests/AppTests/AnalyzerVersionThrottlingTests.swift +++ b/Tests/AppTests/AnalyzerVersionThrottlingTests.swift @@ -24,7 +24,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { @Test func throttle_keep_old() async throws { // Test keeping old when within throttling window - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -45,7 +45,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { @Test func throttle_take_new() async throws { // Test picking new version when old one is outside the window - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -66,7 +66,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { @Test func throttle_ignore_tags() async throws { // Test to ensure tags are exempt from throttling - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -87,7 +87,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { @Test func throttle_new_package() async throws { // Test picking up a new package's branch - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -109,7 +109,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { // Test behaviour when changing default branch names // Changed to return [new] to avoid branch renames causing 404s // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2217 - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -132,7 +132,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { // Ensure incoming branch renames are throttled // Changed to return [new] to avoid branch renames causing 404s // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2217 - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -155,7 +155,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { // Test behaviour with multiple incoming branch revisions // NB: this is a theoretical scenario, in practise there should only // ever be one branch revision among the incoming revisions. - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -181,7 +181,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { // Test behaviour with multiple incoming branch revisions // NB: this is a theoretical scenario, in practise there should only // ever be one branch revision among the incoming revisions. - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { @@ -205,7 +205,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { @Test func diffVersions() async throws { // Test that diffVersions applies throttling - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 $0.git.getTags = { @Sendable _ in [.branch("main")] } @@ -260,7 +260,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { @Test func progression() async throws { // Simulate progression through a time span of branch and tag updates // and checking the diffs are as expected. - try await withApp { app in + try await withSPIApp { app in try await withDependencies { // Leaving tags out of it for simplicity - they are tested specifically // in test_throttle_ignore_tags above. @@ -352,7 +352,7 @@ extension AllTests.AnalyzerVersionThrottlingTests { // the "existing" (ex) revision, replacing it with an older "incoming" // (inc) revision. // setup - try await withApp { app in + try await withSPIApp { app in try await withDependencies { $0.date.now = .t0 } operation: { diff --git a/Tests/AppTests/ApiTests.swift b/Tests/AppTests/ApiTests.swift index 71f789075..afc7f803d 100644 --- a/Tests/AppTests/ApiTests.swift +++ b/Tests/AppTests/ApiTests.swift @@ -17,14 +17,14 @@ import Dependencies import SnapshotTesting import Testing -import XCTVapor +import VaporTesting extension AllTests.ApiTests { @Test func version() async throws { - try await withApp { app in - try await app.test(.GET, "api/version", afterResponse: { res async throws in + try await withSPIApp { app in + try await app.testing().test(.GET, "api/version", afterResponse: { res async throws in #expect(res.status == .ok) #expect(try res.content.decode(API.Version.self) == API.Version(version: "Unknown")) }) @@ -36,9 +36,9 @@ extension AllTests.ApiTests { $0.environment.apiSigningKey = { "secret" } $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "api/search", + try await app.testing().test(.GET, "api/search", headers: .bearerApplicationJSON(try .apiToken(secretKey: "secret", tier: .tier1)), afterResponse: { res async throws in #expect(res.status == .ok) @@ -59,7 +59,7 @@ extension AllTests.ApiTests { await event.setValue(.init(kind: kind, path: path)) } } operation: { - try await withApp { app in + try await withSPIApp { app in let p1 = Package(id: .id0, url: "1") try await p1.save(on: app.db) let p2 = Package(id: .id1, url: "2") @@ -79,7 +79,7 @@ extension AllTests.ApiTests { try await Search.refresh(on: app.db) // MUT - try await app.test(.GET, "api/search?query=foo%20bar", + try await app.testing().test(.GET, "api/search?query=foo%20bar", headers: .bearerApplicationJSON(try .apiToken(secretKey: "secret", tier: .tier1)), afterResponse: { res async throws in // validation @@ -118,9 +118,9 @@ extension AllTests.ApiTests { $0.environment.apiSigningKey = { "secret" } $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "api/search?query=test") { res async in + try await app.testing().test(.GET, "api/search?query=test") { res async in // validation #expect(res.status == .unauthorized) } @@ -142,7 +142,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) @@ -170,7 +170,7 @@ extension AllTests.ApiTests { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .secondsSince1970 let body: ByteBuffer = .init(data: try encoder.encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -217,7 +217,7 @@ extension AllTests.ApiTests { swiftVersion: .init(5, 2, 0) ) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -251,7 +251,7 @@ extension AllTests.ApiTests { swiftVersion: .init(5, 2, 0) ) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -278,7 +278,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) @@ -293,7 +293,7 @@ extension AllTests.ApiTests { swiftVersion: .latest ) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -317,7 +317,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p) @@ -333,7 +333,7 @@ extension AllTests.ApiTests { status: .infrastructureError, swiftVersion: .init(5, 2, 0)) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -356,7 +356,7 @@ extension AllTests.ApiTests { $0.environment.builderToken = { "secr3t" } $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p) @@ -370,7 +370,7 @@ extension AllTests.ApiTests { let db = app.db // MUT - no auth header - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .applicationJSON, @@ -383,7 +383,7 @@ extension AllTests.ApiTests { ) // MUT - wrong token - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("wrong"), @@ -399,7 +399,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { nil } } operation: { - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -421,7 +421,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) @@ -433,7 +433,7 @@ extension AllTests.ApiTests { #expect(data.count > 16_000, "was: \(data.count) bytes") let body: ByteBuffer = .init(data: data) let outOfTheWayPort = 12_345 - try await app.testable(method: .running(port: outOfTheWayPort)).test( + try await app.testing(method: .running(port: outOfTheWayPort)).test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -452,7 +452,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let originalPackageUpdate = try #require(p.updatedAt) @@ -483,7 +483,7 @@ extension AllTests.ApiTests { let encoder = JSONEncoder() encoder.dateEncodingStrategy = .secondsSince1970 let body: ByteBuffer = .init(data: try encoder.encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/versions/\(versionId)/build-report", headers: .bearerApplicationJSON("secr3t"), @@ -516,7 +516,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) @@ -533,7 +533,7 @@ extension AllTests.ApiTests { mbSize: 900, status: .skipped) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/builds/\(buildId)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -559,7 +559,7 @@ extension AllTests.ApiTests { status: .ok ) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/builds/\(buildId)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -580,7 +580,7 @@ extension AllTests.ApiTests { do { // make sure a .pending report without docArchives does not reset them let dto: API.PostDocReportDTO = .init(docArchives: nil, status: .pending) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/builds/\(buildId)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -607,7 +607,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { "secr3t" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) @@ -619,7 +619,7 @@ extension AllTests.ApiTests { do { // initial insert let dto = API.PostDocReportDTO(status: .pending) - try await app.test( + try await app.testing().test( .POST, "api/builds/\(b1.id!)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -637,7 +637,7 @@ extension AllTests.ApiTests { do { // MUT - override let dto = API.PostDocReportDTO(status: .ok) - try await app.test( + try await app.testing().test( .POST, "api/builds/\(b2.id!)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -661,14 +661,14 @@ extension AllTests.ApiTests { $0.environment.builderToken = { "secr3t" } $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let nonExistingBuildId = UUID() do { // send report to non-existing buildId let dto: API.PostDocReportDTO = .init(status: .ok) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test( + try await app.testing().test( .POST, "api/builds/\(nonExistingBuildId)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -689,7 +689,7 @@ extension AllTests.ApiTests { $0.environment.builderToken = { "secr3t" } $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) @@ -701,7 +701,7 @@ extension AllTests.ApiTests { let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) // MUT - no auth header - try await app.test( + try await app.testing().test( .POST, "api/builds/\(buildId)/doc-report", headers: .applicationJSON, @@ -714,7 +714,7 @@ extension AllTests.ApiTests { ) // MUT - wrong token - try await app.test( + try await app.testing().test( .POST, "api/builds/\(buildId)/doc-report", headers: .bearerApplicationJSON("wrong"), @@ -730,7 +730,7 @@ extension AllTests.ApiTests { try await withDependencies { $0.environment.builderToken = { nil } } operation: { - try await app.test( + try await app.testing().test( .POST, "api/builds/\(buildId)/doc-report", headers: .bearerApplicationJSON("secr3t"), @@ -747,7 +747,7 @@ extension AllTests.ApiTests { } @Test func BadgeRoute_query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .release, reference: .tag(.init(1, 2, 3))) @@ -788,7 +788,7 @@ extension AllTests.ApiTests { @Test func get_badge() async throws { // sas 2024-12-20: Badges are not reporting plausbile events, because they triggered way too many events. (This is an old changes, just adding this comment today as I'm removing the old, commented out test remnants we still had in place.) - try await withApp { app in + try await withSPIApp { app in // setup let owner = "owner" let repo = "repo" @@ -807,7 +807,7 @@ extension AllTests.ApiTests { .save(on: app.db) // MUT - swift versions - try await app.test( + try await app.testing().test( .GET, "api/packages/\(owner)/\(repo)/badge?type=swift-versions", afterResponse: { res async throws in @@ -825,7 +825,7 @@ extension AllTests.ApiTests { }) // MUT - platforms - try await app.test( + try await app.testing().test( .GET, "api/packages/\(owner)/\(repo)/badge?type=platforms", afterResponse: { res async throws in @@ -857,7 +857,7 @@ extension AllTests.ApiTests { // await event.setValue(.init(kind: kind, path: path)) // } // } operation: { -// try await withApp { app in +// try await withSPIApp { app in // // setup // let p1 = Package(id: .id1, url: "1") // try await p1.save(on: app.db) @@ -894,7 +894,7 @@ extension AllTests.ApiTests { // } // """) // -// try await app.test(.POST, "api/package-collections", +// try await app.testing().test(.POST, "api/package-collections", // headers: .bearerApplicationJSON(try .apiToken(secretKey: "secret", tier: .tier3)), // body: body, // afterResponse: { res async throws in @@ -926,7 +926,7 @@ extension AllTests.ApiTests { $0.environment.collectionSigningPrivateKey = EnvironmentClient.liveValue.collectionSigningPrivateKey $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p1 = Package(id: UUID(uuidString: "442cf59f-0135-4d08-be00-bc9a7cebabd3")!, url: "1") @@ -984,7 +984,7 @@ extension AllTests.ApiTests { } """) - try await app.test(.POST, + try await app.testing().test(.POST, "api/package-collections", headers: .bearerApplicationJSON((try .apiToken(secretKey: "secret", tier: .tier3))), body: body, @@ -1004,14 +1004,14 @@ extension AllTests.ApiTests { $0.environment.apiSigningKey = { "secret" } $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in let dto = API.PostPackageCollectionDTO( // request 21 urls - this should raise a 400 selection: .packageURLs((0...20).map(String.init)) ) let body: ByteBuffer = .init(data: try JSONEncoder().encode(dto)) - try await app.test(.POST, + try await app.testing().test(.POST, "api/package-collections", headers: .bearerApplicationJSON((try .apiToken(secretKey: "secret", tier: .tier3))), body: body, @@ -1028,7 +1028,7 @@ extension AllTests.ApiTests { $0.environment.apiSigningKey = { "secret" } $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - happy path let body: ByteBuffer = .init(string: """ { @@ -1049,7 +1049,7 @@ extension AllTests.ApiTests { """) // Test with bad token - try await app.test(.POST, "api/package-collections", + try await app.testing().test(.POST, "api/package-collections", headers: .bearerApplicationJSON("bad token"), body: body, afterResponse: { res async in @@ -1058,7 +1058,7 @@ extension AllTests.ApiTests { }) // Test with wrong tier - try await app.test(.POST, "api/package-collections", + try await app.testing().test(.POST, "api/package-collections", headers: .bearerApplicationJSON(.apiToken(secretKey: "secret", tier: .tier1)), body: body, afterResponse: { res async in @@ -1075,7 +1075,7 @@ extension AllTests.ApiTests { $0.environment.dbId = { nil } $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in let owner = "owner" let repo = "repo" let p = try await savePackage(on: app.db, "1") @@ -1088,7 +1088,7 @@ extension AllTests.ApiTests { owner: owner).save(on: app.db) do { // MUT - happy path - try await app.test(.GET, "api/packages/owner/repo", + try await app.testing().test(.GET, "api/packages/owner/repo", headers: .bearerApplicationJSON(try .apiToken(secretKey: "secret", tier: .tier3)), afterResponse: { res async throws in // validation @@ -1099,7 +1099,7 @@ extension AllTests.ApiTests { } do { // MUT - unauthorized (no token provided) - try await app.test(.GET, "api/packages/owner/repo", + try await app.testing().test(.GET, "api/packages/owner/repo", headers: .applicationJSON, afterResponse: { res async in // validation @@ -1108,7 +1108,7 @@ extension AllTests.ApiTests { } do { // MUT - unauthorized (wrong token provided) - try await app.test(.GET, "api/packages/owner/repo", + try await app.testing().test(.GET, "api/packages/owner/repo", headers: .bearerApplicationJSON("bad token"), afterResponse: { res async in // validation @@ -1117,7 +1117,7 @@ extension AllTests.ApiTests { } do { // MUT - unauthorized (signed with wrong key) - try await app.test(.GET, "api/packages/unknown/package", + try await app.testing().test(.GET, "api/packages/unknown/package", headers: .bearerApplicationJSON((try .apiToken(secretKey: "wrong", tier: .tier3))), afterResponse: { res async in // validation @@ -1125,7 +1125,7 @@ extension AllTests.ApiTests { }) } do { // MUT - package not found - try await app.test(.GET, "api/packages/unknown/package", + try await app.testing().test(.GET, "api/packages/unknown/package", headers: .bearerApplicationJSON((try .apiToken(secretKey: "secret", tier: .tier3))), afterResponse: { res async in // validation @@ -1141,7 +1141,7 @@ extension AllTests.ApiTests { $0.environment.apiSigningKey = { "secret" } $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, id: .id0, "http://github.com/foo/bar") try await Repository(package: pkg, defaultBranch: "default", @@ -1155,7 +1155,7 @@ extension AllTests.ApiTests { .save(on: app.db) // MUT - try await app.test(.GET, "api/dependencies", + try await app.testing().test(.GET, "api/dependencies", headers: .bearerApplicationJSON((try .apiToken(secretKey: "secret", tier: .tier3))), afterResponse: { res async in // validation diff --git a/Tests/AppTests/AppTests.swift b/Tests/AppTests/AppTests.swift index bc15aa3a5..2a77c057a 100644 --- a/Tests/AppTests/AppTests.swift +++ b/Tests/AppTests/AppTests.swift @@ -21,7 +21,7 @@ import Testing extension AllTests.AppTests { @Test func migrations() async throws { - try await withApp { app in + try await withSPIApp { app in await #expect(throws: Never.self) { try await app.autoRevert() } await #expect(throws: Never.self) { try await app.autoMigrate() } } diff --git a/Tests/AppTests/ArrayVersionExtensionTests.swift b/Tests/AppTests/ArrayVersionExtensionTests.swift index 99665a260..39b369283 100644 --- a/Tests/AppTests/ArrayVersionExtensionTests.swift +++ b/Tests/AppTests/ArrayVersionExtensionTests.swift @@ -22,7 +22,7 @@ import Testing extension AllTests.ArrayVersionExtensionTests { @Test func Array_canonicalDocumentationTarget() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1".url) let archive = DocArchive(name: "foo", title: "Foo") diff --git a/Tests/AppTests/AuthorControllerTests.swift b/Tests/AppTests/AuthorControllerTests.swift index 875200374..c7962ee30 100644 --- a/Tests/AppTests/AuthorControllerTests.swift +++ b/Tests/AppTests/AuthorControllerTests.swift @@ -17,12 +17,13 @@ import Dependencies import Testing import Vapor +import VaporTesting extension AllTests.AuthorControllerTests { @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p, owner: "owner").save(on: app.db) @@ -37,7 +38,7 @@ extension AllTests.AuthorControllerTests { } @Test func query_no_version() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p, owner: "owner").save(on: app.db) @@ -56,7 +57,7 @@ extension AllTests.AuthorControllerTests { } @Test func query_sort_alphabetically() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for packageName in ["gamma", "alpha", "beta"] { let p = Package(url: "\(packageName)".url) @@ -77,13 +78,13 @@ extension AllTests.AuthorControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in let p = try await savePackage(on: app.db, "1") try await Repository(package: p, owner: "owner").save(on: app.db) try await Version(package: p, latest: .defaultBranch).save(on: app.db) // MUT - try await app.test(.GET, "/owner", afterResponse: { response async in + try await app.testing().test(.GET, "/owner", afterResponse: { response async in #expect(response.status == .ok) }) } @@ -94,13 +95,13 @@ extension AllTests.AuthorControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in let p = try await savePackage(on: app.db, "1") try await Repository(package: p, owner: "owner").save(on: app.db) try await Version(package: p, latest: .defaultBranch).save(on: app.db) - + // MUT - try await app.test(.GET, "/fake-owner", afterResponse: { response async in + try await app.testing().test(.GET, "/fake-owner", afterResponse: { response async in #expect(response.status == .notFound) }) } diff --git a/Tests/AppTests/BuildIndexModelTests.swift b/Tests/AppTests/BuildIndexModelTests.swift index 1334bf8c6..f069c6c49 100644 --- a/Tests/AppTests/BuildIndexModelTests.swift +++ b/Tests/AppTests/BuildIndexModelTests.swift @@ -24,7 +24,7 @@ extension AllTests.BuildIndexModelTests { @Test func init_no_name() async throws { // Tests behaviour when we're lacking data - try await withApp { app in + try await withSPIApp { app in // setup package without package name let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, diff --git a/Tests/AppTests/BuildMonitorControllerTests.swift b/Tests/AppTests/BuildMonitorControllerTests.swift index 8a38f9e0b..d41bcef03 100644 --- a/Tests/AppTests/BuildMonitorControllerTests.swift +++ b/Tests/AppTests/BuildMonitorControllerTests.swift @@ -26,7 +26,7 @@ extension AllTests.BuildMonitorControllerTests { $0.date.now = .now $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad") let version = try Version(package: package) try await version.save(on: app.db) @@ -37,7 +37,7 @@ extension AllTests.BuildMonitorControllerTests { try await Repository(package: package).save(on: app.db) // MUT - try await app.test(.GET, "/build-monitor", afterResponse: { response async in + try await app.testing().test(.GET, "/build-monitor", afterResponse: { response async in #expect(response.status == .ok) }) } diff --git a/Tests/AppTests/BuildMonitorIndexModelTests.swift b/Tests/AppTests/BuildMonitorIndexModelTests.swift index 5a413dd08..7faa718d0 100644 --- a/Tests/AppTests/BuildMonitorIndexModelTests.swift +++ b/Tests/AppTests/BuildMonitorIndexModelTests.swift @@ -21,7 +21,7 @@ import Testing extension AllTests.BuildMonitorIndexModelTests { @Test func init_from_Build() async throws { - try await withApp { app in + try await withSPIApp { app in do { let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad") let version = try Version(package: package, @@ -56,7 +56,7 @@ extension AllTests.BuildMonitorIndexModelTests { } @Test func init_from_Build_without_repository_name() async throws { - try await withApp { app in + try await withSPIApp { app in do { let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad") let version = try Version(package: package, @@ -81,7 +81,7 @@ extension AllTests.BuildMonitorIndexModelTests { } @Test func init_from_Build_with_no_package_name() async throws { - try await withApp { app in + try await withSPIApp { app in do { let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad") let version = try Version(package: package, @@ -107,7 +107,7 @@ extension AllTests.BuildMonitorIndexModelTests { } @Test func init_from_Build_without_ownerName() async throws { - try await withApp { app in + try await withSPIApp { app in do { let package = try await savePackage(on: app.db, "https://github.com/daveverwer/LeftPad") let version = try Version(package: package) diff --git a/Tests/AppTests/BuildResultTests.swift b/Tests/AppTests/BuildResultTests.swift index f7894d856..060794267 100644 --- a/Tests/AppTests/BuildResultTests.swift +++ b/Tests/AppTests/BuildResultTests.swift @@ -21,7 +21,7 @@ import Vapor extension AllTests.BuildResultTests { @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) let repo = try Repository(package: pkg) diff --git a/Tests/AppTests/BuildShowModelTests.swift b/Tests/AppTests/BuildShowModelTests.swift index d14f0717a..69a756833 100644 --- a/Tests/AppTests/BuildShowModelTests.swift +++ b/Tests/AppTests/BuildShowModelTests.swift @@ -31,7 +31,7 @@ extension AllTests.BuildShowModelTests { } @Test func Model_init() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, diff --git a/Tests/AppTests/BuildTests.swift b/Tests/AppTests/BuildTests.swift index 2e37eae64..32e35f83c 100644 --- a/Tests/AppTests/BuildTests.swift +++ b/Tests/AppTests/BuildTests.swift @@ -27,7 +27,7 @@ import Vapor extension AllTests.BuildTests { @Test func save() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(package: pkg) @@ -58,7 +58,7 @@ extension AllTests.BuildTests { @Test func delete_cascade() async throws { // Ensure deleting a version also deletes the builds - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(package: pkg) @@ -86,7 +86,7 @@ extension AllTests.BuildTests { @Test func unique_constraint() async throws { // Ensure builds are unique over (id, platform, swiftVersion) - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v1 = try Version(package: pkg) @@ -138,7 +138,7 @@ extension AllTests.BuildTests { } @Test func trigger() async throws { - try await withApp { app in + try await withSPIApp { app in let buildId = UUID.id0 let versionId = UUID.id1 let called = QueueIsolated(false) @@ -215,7 +215,7 @@ extension AllTests.BuildTests { return try .created(jsonEncode: Gitlab.Builder.Response(webUrl: "http://web_url")) } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(id: versionId, package: p, reference: .branch("main")) @@ -238,7 +238,7 @@ extension AllTests.BuildTests { @Test func query() async throws { // Test querying by (platform/swiftVersion/versionId) - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v1 = try Version(package: pkg) @@ -301,7 +301,7 @@ extension AllTests.BuildTests { } @Test func delete_by_versionId() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let vid1 = UUID() @@ -326,7 +326,7 @@ extension AllTests.BuildTests { } @Test func delete_by_packageId() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId1 = UUID() let pkg1 = Package(id: pkgId1, url: "1") @@ -358,7 +358,7 @@ extension AllTests.BuildTests { } @Test func delete_by_packageId_versionKind() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId1 = UUID() let pkg1 = Package(id: pkgId1, url: "1") @@ -393,7 +393,7 @@ extension AllTests.BuildTests { } @Test func pending_to_triggered_migration() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(url: "1") try await p.save(on: app.db) @@ -425,7 +425,7 @@ extension AllTests.BuildTests { } @Test func DeleteArmBuilds_migration() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(url: "1") try await p.save(on: app.db) diff --git a/Tests/AppTests/BuildTriggerTests.swift b/Tests/AppTests/BuildTriggerTests.swift index dcf56a4ea..a7e3e2f75 100644 --- a/Tests/AppTests/BuildTriggerTests.swift +++ b/Tests/AppTests/BuildTriggerTests.swift @@ -35,7 +35,7 @@ extension AllTests.BuildTriggerTests { try await withDependencies { $0.environment.buildTriggerAllowList = { [] } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkgIdComplete = UUID() let pkgIdIncomplete1 = UUID() @@ -95,7 +95,7 @@ extension AllTests.BuildTriggerTests { try await withDependencies { $0.environment.buildTriggerAllowList = { [] } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // save package without any builds let pkgId = UUID() @@ -123,7 +123,7 @@ extension AllTests.BuildTriggerTests { try await withDependencies { $0.environment.buildTriggerAllowList = { [] } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup do { // save package with just latest Swift version builds missing let p = Package(id: .id1, url: "1") @@ -175,7 +175,7 @@ extension AllTests.BuildTriggerTests { try await withDependencies { $0.environment.buildTriggerAllowList = { [.id1] } } operation: { - try await withApp { app in + try await withSPIApp { app in // save two packages with partially completed builds for id in [UUID.id0, .id1] { let p = Package(id: id, url: id.uuidString.url) @@ -223,7 +223,7 @@ extension AllTests.BuildTriggerTests { } @Test func TriggerBuilds_findMissingBuilds() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let versionId = UUID() @@ -310,7 +310,7 @@ extension AllTests.BuildTriggerTests { } @Test func TriggerBuilds_findMissingBuilds_docPairs() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let versionId = UUID() @@ -368,7 +368,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let versionId = UUID() do { // save package with partially completed builds @@ -418,7 +418,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let versionId = UUID() @@ -491,7 +491,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let buildId = UUID() let versionId = UUID() @@ -553,7 +553,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in do { // fist run: we are at capacity and should not be triggering more builds try await withDependencies { $0.buildSystem.getStatusCount = { @Sendable _ in 300 } @@ -654,7 +654,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkgIds = [UUID(), UUID()] for id in pkgIds { @@ -687,7 +687,7 @@ extension AllTests.BuildTriggerTests { $0.environment.siteURL = { "http://example.com" } } operation: { // Ensure we trim builds as part of triggering - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(id: .id0, url: "2") try await p.save(on: app.db) @@ -737,7 +737,7 @@ extension AllTests.BuildTriggerTests { } } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(id: .id0, url: "1") try await p.save(on: app.db) @@ -843,7 +843,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup try await withDependencies { // confirm that the off switch prevents triggers @@ -906,7 +906,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // confirm that bad luck prevents triggers try await withDependencies { $0.environment.random = { @Sendable _ in 0.05 } // rolling a 0.05 ... so close! @@ -968,7 +968,7 @@ extension AllTests.BuildTriggerTests { return .created(webUrl: "http://web_url") } } operation: { - try await withApp { app in + try await withSPIApp { app in // confirm that we trigger even when rolling above the threshold try await withDependencies { $0.environment.random = { @Sendable _ in 0.051 } @@ -990,7 +990,7 @@ extension AllTests.BuildTriggerTests { } @Test func TriggerBuilds_trimBuilds_significant_version() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let p = Package(id: pkgId, url: "1") @@ -1028,7 +1028,7 @@ extension AllTests.BuildTriggerTests { } @Test func TriggerBuilds_trimBuilds_non_significant_version() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let p = Package(id: pkgId, url: "1") @@ -1072,7 +1072,7 @@ extension AllTests.BuildTriggerTests { // latest: not null / null // This test sets up 8 builds covering all combinations to confirm whether the build is // being trimmed or not. - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(url: "1") try await p.save(on: app.db) @@ -1127,7 +1127,7 @@ extension AllTests.BuildTriggerTests { @Test func TriggerBuilds_trimBuilds_bindParam() async throws { // Bind parameter issue regression test, details: // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/909 - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let p = Package(id: pkgId, url: "1") @@ -1151,7 +1151,7 @@ extension AllTests.BuildTriggerTests { @Test func TriggerBuilds_trimBuilds_timeout() async throws { // Ensure timouts are not deleted - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let p = Package(id: pkgId, url: "1") @@ -1189,7 +1189,7 @@ extension AllTests.BuildTriggerTests { @Test func TriggerBuilds_trimBuilds_infrastructureError() async throws { // Ensure infrastructerErrors are deleted - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let p = Package(id: pkgId, url: "1") @@ -1278,7 +1278,7 @@ extension AllTests.BuildTriggerTests { // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/1065 // addressing a problem with findMissingBuilds not ignoring // Swift patch versions. - try await withApp { app in + try await withSPIApp { app in // setup let pkgId = UUID() let versionId = UUID() diff --git a/Tests/AppTests/CustomCollectionControllerTests.swift b/Tests/AppTests/CustomCollectionControllerTests.swift index 67276f457..6a1714fde 100644 --- a/Tests/AppTests/CustomCollectionControllerTests.swift +++ b/Tests/AppTests/CustomCollectionControllerTests.swift @@ -23,7 +23,7 @@ import Vapor extension AllTests.CustomCollectionControllerTests { @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup try await CustomCollection.save( on: app.db, @@ -46,7 +46,7 @@ extension AllTests.CustomCollectionControllerTests { } @Test func query_pagination() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgInfo = [UUID.id0, .id1, .id2, .id3, .id4].enumerated().shuffled().map { (idx, id) in (id, URL(string: "https://github.com/foo/\(idx)")!, "foo", "\(idx)") @@ -98,7 +98,7 @@ extension AllTests.CustomCollectionControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in try await CustomCollection.save( on: app.db, key: "list", @@ -108,7 +108,7 @@ extension AllTests.CustomCollectionControllerTests { ) // MUT - try await app.test(.GET, "/collections/list") { req async in + try await app.testing().test(.GET, "/collections/list") { req async in // validate #expect(req.status == .ok) } @@ -120,8 +120,8 @@ extension AllTests.CustomCollectionControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in - try await app.test(.GET, "/collections/list") { res async in + try await withSPIApp { app in + try await app.testing().test(.GET, "/collections/list") { res async in #expect(res.status == .notFound) } } diff --git a/Tests/AppTests/CustomCollectionTests.swift b/Tests/AppTests/CustomCollectionTests.swift index 218bac530..019464efd 100644 --- a/Tests/AppTests/CustomCollectionTests.swift +++ b/Tests/AppTests/CustomCollectionTests.swift @@ -23,7 +23,7 @@ import Testing extension AllTests.CustomCollectionTests { @Test func CustomCollection_save() async throws { - try await withApp { app in + try await withSPIApp { app in // MUT try await CustomCollection(id: .id0, .init(key: "list", name: "List", @@ -75,7 +75,7 @@ extension AllTests.CustomCollectionTests { } @Test func CustomCollection_findOrCreate() async throws { - try await withApp { app in + try await withSPIApp { app in do { // initial call creates collection // MUT let res = try await CustomCollection.findOrCreate(on: app.db, .init(key: "list", @@ -132,7 +132,7 @@ extension AllTests.CustomCollectionTests { } @Test func CustomCollectionPackage_attach() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: .id0, url: "1".asGithubUrl.url) try await pkg.save(on: app.db) @@ -167,7 +167,7 @@ extension AllTests.CustomCollectionTests { } @Test func CustomCollectionPackage_detach() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: .id0, url: "1".asGithubUrl.url) try await pkg.save(on: app.db) @@ -194,7 +194,7 @@ extension AllTests.CustomCollectionTests { @Test func CustomCollection_packages() async throws { // Test CustomCollection.packages relation - try await withApp { app in + try await withSPIApp { app in // setup let p1 = Package(id: .id0, url: "1".asGithubUrl.url) try await p1.save(on: app.db) @@ -217,7 +217,7 @@ extension AllTests.CustomCollectionTests { @Test func Package_customCollections() async throws { // Test Package.customCollections relation - try await withApp { app in + try await withSPIApp { app in // setup let p1 = Package(id: .id0, url: "1".asGithubUrl.url) try await p1.save(on: app.db) @@ -245,7 +245,7 @@ extension AllTests.CustomCollectionTests { } @Test func CustomCollection_cascade() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: .id0, url: "1".asGithubUrl.url) try await pkg.save(on: app.db) @@ -287,7 +287,7 @@ extension AllTests.CustomCollectionTests { } @Test func Package_cascade() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: .id0, url: "1".asGithubUrl.url) try await pkg.save(on: app.db) @@ -330,7 +330,7 @@ extension AllTests.CustomCollectionTests { @Test func CustomCollection_reconcile() async throws { // Test reconciliation of a custom collection against a list of package URLs - try await withApp { app in + try await withSPIApp { app in let collection = CustomCollection(id: .id0, .init(key: "list", name: "List", url: "https://github.com/foo/bar/list.json")) @@ -389,7 +389,7 @@ extension AllTests.CustomCollectionTests { @Test func CustomCollection_reconcile_caseInsensitive() async throws { // Test reconciliation with a case-insensitive matching URL - try await withApp { app in + try await withSPIApp { app in let collection = CustomCollection(id: .id0, .init(key: "list", name: "List", url: "https://github.com/foo/bar/list.json")) diff --git a/Tests/AppTests/DocUploadTests.swift b/Tests/AppTests/DocUploadTests.swift index 771d8957a..25d3b8ad5 100644 --- a/Tests/AppTests/DocUploadTests.swift +++ b/Tests/AppTests/DocUploadTests.swift @@ -22,7 +22,7 @@ import Testing extension AllTests.DocUploadTests { @Test func attach() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let versionId = UUID() @@ -59,7 +59,7 @@ extension AllTests.DocUploadTests { @Test func detachAndDelete() async throws { // Ensure deleting doc_uploads doesn't cascade into builds - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(id: UUID(), package: pkg) @@ -92,7 +92,7 @@ extension AllTests.DocUploadTests { } @Test func delete_cascade_build() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let buildId = UUID() @@ -119,7 +119,7 @@ extension AllTests.DocUploadTests { } @Test func delete_cascade_version() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let versionId = UUID() @@ -147,7 +147,7 @@ extension AllTests.DocUploadTests { @Test func unique_constraint_doc_uploads_build_id() async throws { // Ensure different doc_uploads cannot be attached to the same build - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(id: UUID(), package: pkg) @@ -174,7 +174,7 @@ extension AllTests.DocUploadTests { @Test func unique_constraint_builds_doc_upload_id_1() async throws { // Ensure doc_upload cannot be attached to two different versions (via builds from two different versions) - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v1 = try Version(id: UUID(), package: pkg) @@ -204,7 +204,7 @@ extension AllTests.DocUploadTests { @Test func unique_constraint_builds_doc_upload_id_2() async throws { // Ensure doc_upload cannot be attached to same version more than once (via two builds from same version) - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(id: UUID(), package: pkg) @@ -232,7 +232,7 @@ extension AllTests.DocUploadTests { @Test func unique_constraint_builds_version_id_partial() async throws { // Ensure no single version can reference two doc_uploads - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(id: UUID(), package: pkg) diff --git a/Tests/AppTests/DocumentationTargetTests.swift b/Tests/AppTests/DocumentationTargetTests.swift index da5253e42..df4439593 100644 --- a/Tests/AppTests/DocumentationTargetTests.swift +++ b/Tests/AppTests/DocumentationTargetTests.swift @@ -23,7 +23,7 @@ extension AllTests.DocumentationTargetTests { @Test func external() async throws { // Test external doc url lookup - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -53,7 +53,7 @@ extension AllTests.DocumentationTargetTests { @Test func external_override() async throws { // Test external doc url lookup overriding internal doc archives - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -85,7 +85,7 @@ extension AllTests.DocumentationTargetTests { } @Test func internal_defaultBranch() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -110,7 +110,7 @@ extension AllTests.DocumentationTargetTests { } @Test func internal_stableBranch() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, diff --git a/Tests/AppTests/ErrorMiddlewareTests.swift b/Tests/AppTests/ErrorMiddlewareTests.swift index fdc623b61..d13c2b2e1 100644 --- a/Tests/AppTests/ErrorMiddlewareTests.swift +++ b/Tests/AppTests/ErrorMiddlewareTests.swift @@ -29,9 +29,9 @@ extension AllTests.ErrorMiddlewareTests { } @Test func custom_routes() async throws { - try await withApp(setup) { app in + try await withSPIApp(setup) { app in // Test to ensure the test routes we've set up in setUpWithError are in effect - try await app.test(.GET, "ok", afterResponse: { response async in + try await app.testing().test(.GET, "ok", afterResponse: { response async in #expect(response.status == .ok) #expect(response.body.asString() == "ok") }) @@ -43,8 +43,8 @@ extension AllTests.ErrorMiddlewareTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp(setup) { app in - try await app.test(.GET, "404", afterResponse: { response async in + try await withSPIApp(setup) { app in + try await app.testing().test(.GET, "404", afterResponse: { response async in #expect(response.content.contentType == .html) #expect(response.body.asString().contains("404 - Not Found")) }) @@ -59,12 +59,12 @@ extension AllTests.ErrorMiddlewareTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp(setup) { app in - try await app.test(.GET, "404", afterResponse: { response async in + try await withSPIApp(setup) { app in + try await app.testing().test(.GET, "404", afterResponse: { response async in #expect(response.status == .notFound) #expect(response.content.contentType == .html) }) - try await app.test(.GET, "500", afterResponse: { response async in + try await app.testing().test(.GET, "500", afterResponse: { response async in #expect(response.status == .internalServerError) #expect(response.content.contentType == .html) }) diff --git a/Tests/AppTests/ErrorReportingTests.swift b/Tests/AppTests/ErrorReportingTests.swift index 2b040f1e9..be08ee424 100644 --- a/Tests/AppTests/ErrorReportingTests.swift +++ b/Tests/AppTests/ErrorReportingTests.swift @@ -23,7 +23,7 @@ import Testing extension AllTests.ErrorReportingTests { @Test func Analyze_recordError() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") try await Analyze.recordError(database: app.db, error: AppError.cacheDirectoryDoesNotExist(pkg.id, "path")) @@ -37,7 +37,7 @@ extension AllTests.ErrorReportingTests { @Test func Ingestion_error_reporting() async throws { let capturingLogger = CapturingLogger() - try await withApp { app in + try await withSPIApp { app in // setup try await Package(id: .id0, url: "1", processingStage: .reconciliation).save(on: app.db) @@ -59,7 +59,7 @@ extension AllTests.ErrorReportingTests { } @Test func Analyzer_error_reporting() async throws { - try await withApp { app in + try await withSPIApp { app in let capturingLogger = CapturingLogger() try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } @@ -92,7 +92,7 @@ extension AllTests.ErrorReportingTests { try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup try await savePackages(on: app.db, ["1", "2"], processingStage: .ingestion) diff --git a/Tests/AppTests/GitlabBuilderTests.swift b/Tests/AppTests/GitlabBuilderTests.swift index 1cf299319..6f4e76615 100644 --- a/Tests/AppTests/GitlabBuilderTests.swift +++ b/Tests/AppTests/GitlabBuilderTests.swift @@ -31,7 +31,7 @@ extension AllTests.GitlabBuilderTests { @Test func variables_encoding() async throws { // Ensure the POST variables are encoded correctly // setup - try await withApp { app in + try await withSPIApp { app in let req = Request(application: app, on: app.eventLoopGroup.next()) let dto = Gitlab.Builder.PostDTO(token: "token", ref: "ref", diff --git a/Tests/AppTests/Helpers/Database+ext.swift b/Tests/AppTests/Helpers/Database+ext.swift index 422bc20ab..c951a623d 100644 --- a/Tests/AppTests/Helpers/Database+ext.swift +++ b/Tests/AppTests/Helpers/Database+ext.swift @@ -20,7 +20,7 @@ import Fluent import SQLKit -// FIXME: Check if we can just create a PostgresDB object from scratch rather than using withApp and app.db for this at the call site (i.e. check if these need to be extensions on Database). That does a whole migration + reset just to render the SQL needlessly. +// FIXME: Check if we can just create a PostgresDB object from scratch rather than using withSPIApp and app.db for this at the call site (i.e. check if these need to be extensions on Database). That does a whole migration + reset just to render the SQL needlessly. extension Database { func renderSQL(_ builder: SQLSelectBuilder) -> String { renderSQL(builder.query) diff --git a/Tests/AppTests/Helpers/TestSupport.swift b/Tests/AppTests/Helpers/TestSupport.swift index 535419f6f..c13b862a3 100644 --- a/Tests/AppTests/Helpers/TestSupport.swift +++ b/Tests/AppTests/Helpers/TestSupport.swift @@ -19,7 +19,7 @@ import Vapor import PostgresNIO -func withApp( +func withSPIApp( environment: Environment = .testing, _ setup: @Sendable (Application) async throws -> Void = { _ in }, _ updateValuesForOperation: @Sendable (inout DependencyValues) async throws -> Void = { _ in }, diff --git a/Tests/AppTests/HomeIndexModelTests.swift b/Tests/AppTests/HomeIndexModelTests.swift index bb7d620bf..1c82e8cca 100644 --- a/Tests/AppTests/HomeIndexModelTests.swift +++ b/Tests/AppTests/HomeIndexModelTests.swift @@ -23,7 +23,7 @@ import Testing extension AllTests.HomeIndexModelTests { @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1".url) try await pkg.save(on: app.db) diff --git a/Tests/AppTests/IngestionTests.swift b/Tests/AppTests/IngestionTests.swift index 7b29e009a..fbd98de4d 100644 --- a/Tests/AppTests/IngestionTests.swift +++ b/Tests/AppTests/IngestionTests.swift @@ -24,7 +24,7 @@ import Vapor extension AllTests.IngestionTests { @Test func ingest_basic() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let packages = ["https://github.com/finestructure/Gala", "https://github.com/finestructure/Rester", @@ -75,7 +75,7 @@ extension AllTests.IngestionTests { } $0.github.fetchReadme = { @Sendable _, _ in nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let packages = try await savePackages(on: app.db, ["https://github.com/foo/1", "https://github.com/foo/2"], processingStage: .reconciliation) @@ -100,7 +100,7 @@ extension AllTests.IngestionTests { } @Test func updateRepository_insert() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "https://github.com/foo/bar") let repo = Repository(packageId: try pkg.requireID()) @@ -122,7 +122,7 @@ extension AllTests.IngestionTests { } @Test func updateRepository_update() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "https://github.com/foo/bar") let repo = Repository(packageId: try pkg.requireID()) let md: Github.Metadata = .init(defaultBranch: "main", @@ -217,7 +217,7 @@ extension AllTests.IngestionTests { } @Test func homePageEmptyString() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "2") let repo = Repository(packageId: try pkg.requireID()) @@ -257,7 +257,7 @@ extension AllTests.IngestionTests { } @Test func updatePackage() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkgs = try await savePackages(on: app.db, ["https://github.com/foo/1", "https://github.com/foo/2"]) @@ -288,7 +288,7 @@ extension AllTests.IngestionTests { @Test func updatePackage_new() async throws { // Ensure newly ingested packages are passed on with status = new to fast-track // them into analysis - try await withApp { app in + try await withSPIApp { app in let pkgs = [ Package(id: UUID(), url: "https://github.com/foo/1", status: .ok, processingStage: .reconciliation), Package(id: UUID(), url: "https://github.com/foo/2", status: .new, processingStage: .reconciliation) @@ -316,7 +316,7 @@ extension AllTests.IngestionTests { @Test func partial_save_issue() async throws { // Test to ensure futures are properly waited for and get flushed to the db in full - try await withApp { app in + try await withSPIApp { app in // setup let packages = testUrls.map { Package(url: $0, processingStage: .reconciliation) } try await packages.save(on: app.db) @@ -340,7 +340,7 @@ extension AllTests.IngestionTests { @Test func ingest_badMetadata() async throws { // setup - try await withApp { app in + try await withSPIApp { app in let urls = ["https://github.com/foo/1", "https://github.com/foo/2", "https://github.com/foo/3"] @@ -383,7 +383,7 @@ extension AllTests.IngestionTests { // Test error behaviour when two packages resolving to the same owner/name are ingested: // - don't create repository records let capturingLogger = CapturingLogger() - try await withApp { app in + try await withSPIApp { app in // setup try await Package(id: .id0, url: "https://github.com/foo/0", status: .ok, processingStage: .reconciliation) .save(on: app.db) @@ -513,7 +513,7 @@ extension AllTests.IngestionTests { return "objectUrl" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "https://github.com/foo/bar".url, processingStage: .reconciliation) try await pkg.save(on: app.db) @@ -567,7 +567,7 @@ extension AllTests.IngestionTests { } @Test func ingest_storeS3Readme_withPrivateImages() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "https://github.com/foo/bar".url, processingStage: .reconciliation) try await pkg.save(on: app.db) @@ -615,7 +615,7 @@ extension AllTests.IngestionTests { @Test func ingest_storeS3Readme_error() async throws { // Test caching behaviour in case the storeS3Readme call fails - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "https://github.com/foo/bar".url, processingStage: .reconciliation) try await pkg.save(on: app.db) @@ -670,7 +670,7 @@ extension AllTests.IngestionTests { } } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "https://github.com/foo/1") try await pkg.save(on: app.db) @@ -685,7 +685,7 @@ extension AllTests.IngestionTests { } @Test func migration076_updateRepositoryResetReadmes() async throws { - try await withApp { app in + try await withSPIApp { app in let package = Package(url: "https://example.com/owner/repo") try await package.save(on: app.db) let repository = try Repository(package: package, s3Readme: .cached(s3ObjectUrl: "object-url", githubEtag: "etag")) @@ -705,7 +705,7 @@ extension AllTests.IngestionTests { } @Test func getFork() async throws { - try await withApp { app in + try await withSPIApp { app in try await Package(id: .id0, url: "https://github.com/foo/parent.git".url, processingStage: .analysis).save(on: app.db) try await Package(url: "https://github.com/bar/forked.git", processingStage: .analysis).save(on: app.db) diff --git a/Tests/AppTests/Joined3Tests.swift b/Tests/AppTests/Joined3Tests.swift index 3918335fd..2ab156a15 100644 --- a/Tests/AppTests/Joined3Tests.swift +++ b/Tests/AppTests/Joined3Tests.swift @@ -21,7 +21,7 @@ import Vapor extension AllTests.Joined3Tests { @Test func query_no_version() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p).save(on: app.db) @@ -36,7 +36,7 @@ extension AllTests.Joined3Tests { @Test func query_multiple_versions() async throws { // Ensure multiple versions don't multiply the package selection - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p).save(on: app.db) @@ -55,7 +55,7 @@ extension AllTests.Joined3Tests { @Test func query_relationship_properties() async throws { // Ensure relationship properties are populated by query - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p, owner: "owner").save(on: app.db) @@ -78,7 +78,7 @@ extension AllTests.Joined3Tests { // Neither should be possible in practice, this is just ensuring we cannot // force unwrap the `repository` or `version` properties in the pathological // event, because there are no results to access the properties on. - try await withApp { app in + try await withSPIApp { app in do { // no repository let p = try await savePackage(on: app.db, "1") try await Version(package: p, diff --git a/Tests/AppTests/JoinedQueryBuilderTests.swift b/Tests/AppTests/JoinedQueryBuilderTests.swift index 795f7e0e5..918be0df4 100644 --- a/Tests/AppTests/JoinedQueryBuilderTests.swift +++ b/Tests/AppTests/JoinedQueryBuilderTests.swift @@ -25,7 +25,7 @@ import Testing extension AllTests.JoinedQueryBuilderTests { @Test func sort() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for idx in (0..<3).shuffled() { try await Package(url: "\(idx)".url).save(on: app.db) diff --git a/Tests/AppTests/JoinedTests.swift b/Tests/AppTests/JoinedTests.swift index 0ad9c201b..38c8dad40 100644 --- a/Tests/AppTests/JoinedTests.swift +++ b/Tests/AppTests/JoinedTests.swift @@ -21,7 +21,7 @@ extension AllTests.JoinedTests { typealias JPR = Joined @Test func query_owner_repository() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1") try await pkg.save(on: app.db) @@ -46,7 +46,7 @@ extension AllTests.JoinedTests { @Test func repository_access() async throws { // Test accessing repository through the join vs through the package relation - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p).save(on: app.db) @@ -69,7 +69,7 @@ extension AllTests.JoinedTests { @Test func repository_update() async throws { // Test updating the repository through the join - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p).save(on: app.db) diff --git a/Tests/AppTests/KeywordControllerTests.swift b/Tests/AppTests/KeywordControllerTests.swift index 665a4d942..43cb573d6 100644 --- a/Tests/AppTests/KeywordControllerTests.swift +++ b/Tests/AppTests/KeywordControllerTests.swift @@ -16,13 +16,13 @@ import Dependencies import Testing -import XCTVapor +import VaporTesting extension AllTests.KeywordControllerTests { @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { let p = try await savePackage(on: app.db, "0") @@ -63,7 +63,7 @@ extension AllTests.KeywordControllerTests { } @Test func query_pagination() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for idx in (0..<9).shuffled() { let p = Package(url: "\(idx)".url, score: 10 - idx) @@ -111,7 +111,7 @@ extension AllTests.KeywordControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in do { let p = try await savePackage(on: app.db, "1") try await Repository(package: p, @@ -121,7 +121,7 @@ extension AllTests.KeywordControllerTests { try await Version(package: p, latest: .defaultBranch).save(on: app.db) } // MUT - try await app.test(.GET, "/keywords/foo") { req async in + try await app.testing().test(.GET, "/keywords/foo") { req async in // validate #expect(req.status == .ok) } @@ -133,8 +133,8 @@ extension AllTests.KeywordControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in - try await app.test(.GET, "/keywords/baz") { res async in + try await withSPIApp { app in + try await app.testing().test(.GET, "/keywords/baz") { res async in #expect(res.status == .notFound) } } diff --git a/Tests/AppTests/MastodonTests.swift b/Tests/AppTests/MastodonTests.swift index 3d3d41189..a977bc021 100644 --- a/Tests/AppTests/MastodonTests.swift +++ b/Tests/AppTests/MastodonTests.swift @@ -62,7 +62,7 @@ extension AllTests.MastodonTests { return "" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let url = "https://github.com/foo/bar" diff --git a/Tests/AppTests/MetricsTests.swift b/Tests/AppTests/MetricsTests.swift index 5f9e82cd2..8302e8da9 100644 --- a/Tests/AppTests/MetricsTests.swift +++ b/Tests/AppTests/MetricsTests.swift @@ -31,7 +31,7 @@ extension AllTests.MetricsTests { $0.environment.builderToken = { "builder token" } $0.environment.gitlabPipelineToken = { "pipeline token" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup - trigger build to increment counter let versionId = UUID() do { // save minimal package + version @@ -46,7 +46,7 @@ extension AllTests.MetricsTests { ]) // MUT - try await app.test(.GET, "metrics", afterResponse: { res async in + try await app.testing().test(.GET, "metrics", afterResponse: { res async in // validation #expect(res.status == .ok) let content = res.body.asString() @@ -59,7 +59,7 @@ extension AllTests.MetricsTests { } @Test func versions_added() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let new = [ @@ -99,7 +99,7 @@ extension AllTests.MetricsTests { $0.packageListRepository.fetchPackageDenyList = { @Sendable _ in [] } $0.packageListRepository.fetchCustomCollections = { @Sendable _ in [] } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT try await reconcile(client: app.client, database: app.db) @@ -110,7 +110,7 @@ extension AllTests.MetricsTests { } @Test func ingestDurationSeconds() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") @@ -126,7 +126,7 @@ extension AllTests.MetricsTests { try await withDependencies { $0.fileManager.fileExists = { @Sendable _ in true } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") @@ -143,7 +143,7 @@ extension AllTests.MetricsTests { try await withDependencies { $0.environment.allowBuildTriggers = { true } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") diff --git a/Tests/AppTests/PackageCollectionControllerTests.swift b/Tests/AppTests/PackageCollectionControllerTests.swift index 496b79298..f85710106 100644 --- a/Tests/AppTests/PackageCollectionControllerTests.swift +++ b/Tests/AppTests/PackageCollectionControllerTests.swift @@ -35,7 +35,7 @@ extension AllTests.PackageCollectionControllerTests { $0.environment.collectionSigningCertificateChain = EnvironmentClient.liveValue.collectionSigningCertificateChain $0.environment.collectionSigningPrivateKey = EnvironmentClient.liveValue.collectionSigningPrivateKey } operation: { - try await withApp { app in + try await withSPIApp { app in let p = try await savePackage(on: app.db, "https://github.com/foo/1") do { let v = try Version(id: UUID(), @@ -72,7 +72,7 @@ extension AllTests.PackageCollectionControllerTests { // MUT let encoder = self.encoder - try await app.test( + try await app.testing().test( .GET, "foo/collection.json", afterResponse: { @MainActor res async throws in @@ -97,7 +97,7 @@ extension AllTests.PackageCollectionControllerTests { $0.environment.collectionSigningCertificateChain = EnvironmentClient.liveValue.collectionSigningCertificateChain $0.environment.collectionSigningPrivateKey = EnvironmentClient.liveValue.collectionSigningPrivateKey } operation: { - try await withApp { app in + try await withSPIApp { app in let p = try await savePackage(on: app.db, "https://github.com/foo/1") do { let v = try Version(id: UUID(), @@ -139,7 +139,7 @@ extension AllTests.PackageCollectionControllerTests { // MUT let encoder = self.encoder - try await app.test( + try await app.testing().test( .GET, "collections/custom-collection/collection.json", afterResponse: { @MainActor res async throws in @@ -157,9 +157,9 @@ extension AllTests.PackageCollectionControllerTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test( + try await app.testing().test( .GET, "foo/collection.json", afterResponse: { res async in diff --git a/Tests/AppTests/PackageCollectionTests.swift b/Tests/AppTests/PackageCollectionTests.swift index 3d2f66036..7e02d792d 100644 --- a/Tests/AppTests/PackageCollectionTests.swift +++ b/Tests/AppTests/PackageCollectionTests.swift @@ -34,7 +34,7 @@ extension AllTests.PackageCollectionTests { @Test func query_filter_urls() async throws { // Tests PackageResult.query with the url filter option - try await withApp { app in + try await withSPIApp { app in // setup for index in (0..<3) { let pkg = try await savePackage(on: app.db, "url-\(index)".url) @@ -80,7 +80,7 @@ extension AllTests.PackageCollectionTests { @Test func query_filter_urls_no_results() async throws { // Tests PackageResult.query without results has safe relationship accessors - try await withApp { app in + try await withSPIApp { app in // setup for index in (0..<3) { let pkg = try await savePackage(on: app.db, "url-\(index)".url) @@ -127,7 +127,7 @@ extension AllTests.PackageCollectionTests { @Test func query_author() async throws { // Tests PackageResult.query with the author filter option - try await withApp { app in + try await withSPIApp { app in // setup // first package let owners = ["foo", "foo", "someone else"] @@ -169,7 +169,7 @@ extension AllTests.PackageCollectionTests { @Test func query_custom() async throws { // Tests PackageResult.query with the custom collection filter option - try await withApp { app in + try await withSPIApp { app in // setup let packages = try await (0..<3).mapAsync { index in let pkg = try await savePackage(on: app.db, "url-\(index)".url) @@ -212,7 +212,7 @@ extension AllTests.PackageCollectionTests { @Test func Version_init() async throws { // Tests PackageCollection.Version initialisation from App.Version - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(url: "1") try await p.save(on: app.db) @@ -287,7 +287,7 @@ extension AllTests.PackageCollectionTests { @Test func Package_init() async throws { // Tests PackageCollection.Package initialisation from App.Package - try await withApp { app in + try await withSPIApp { app in // setup do { let p = Package(url: "1") @@ -333,7 +333,7 @@ extension AllTests.PackageCollectionTests { } @Test func groupedByPackage() async throws { - try await withApp { app in + try await withSPIApp { app in // setup // 2 packages by the same author (which we select) with two versions // each. @@ -393,7 +393,7 @@ extension AllTests.PackageCollectionTests { try await withDependencies { $0.date.now = .init(timeIntervalSince1970: 1610112345) } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") do { @@ -425,7 +425,7 @@ extension AllTests.PackageCollectionTests { } @Test func generate_from_urls_noResults() async throws { - try await withApp { app in + try await withSPIApp { app in // MUT do { _ = try await PackageCollection.generate(db: app.db, @@ -447,7 +447,7 @@ extension AllTests.PackageCollectionTests { try await withDependencies { $0.date.now = .init(timeIntervalSince1970: 1610112345) } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // first package let p1 = try await savePackage(on: app.db, "https://github.com/foo/1") @@ -529,7 +529,7 @@ extension AllTests.PackageCollectionTests { @Test func generate_for_owner_noResults() async throws { // Ensure we return noResults when no packages are found - try await withApp { app in + try await withSPIApp { app in // MUT do { _ = try await PackageCollection.generate(db: app.db, @@ -548,7 +548,7 @@ extension AllTests.PackageCollectionTests { @Test func includes_significant_versions_only() async throws { // Ensure we only export significant versions // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/1147 - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "https://github.com/foo/1") try await Repository(package: p, @@ -639,7 +639,7 @@ extension AllTests.PackageCollectionTests { @Test func require_products() async throws { // Ensure we don't include versions without products (by ensuring // init? returns nil, which will be compact mapped away) - try await withApp { app in + try await withSPIApp { app in let p = Package(url: "1".asGithubUrl.url) try await p.save(on: app.db) let v = try Version(package: p, @@ -657,7 +657,7 @@ extension AllTests.PackageCollectionTests { @Test func require_versions() async throws { // Ensure we don't include packages without versions (by ensuring // init? returns nil, which will be compact mapped away) - try await withApp { app in + try await withSPIApp { app in do { // no versions at all // setup let pkg = Package(url: "1") @@ -694,7 +694,7 @@ extension AllTests.PackageCollectionTests { } @Test func case_insensitive_owner_matching() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "https://github.com/foo/1") do { @@ -733,7 +733,7 @@ extension AllTests.PackageCollectionTests { @Test func generate_ownerName() async throws { // Ensure ownerName is used in collectionName and overview - try await withApp { app in + try await withSPIApp { app in // setup // first package let p1 = try await savePackage(on: app.db, "https://github.com/foo/1") @@ -805,7 +805,7 @@ extension AllTests.PackageCollectionTests { } @Test func authorLabel() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = Package(url: "1") try await p.save(on: app.db) diff --git a/Tests/AppTests/PackageContributorsTests.swift b/Tests/AppTests/PackageContributorsTests.swift index 2c0abab85..d1c373b1d 100644 --- a/Tests/AppTests/PackageContributorsTests.swift +++ b/Tests/AppTests/PackageContributorsTests.swift @@ -84,7 +84,7 @@ extension AllTests.PackageContributorsTests { """ } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url) diff --git a/Tests/AppTests/PackageController+BuildsRouteTests.swift b/Tests/AppTests/PackageController+BuildsRouteTests.swift index b6ce93068..a2bb5c4c3 100644 --- a/Tests/AppTests/PackageController+BuildsRouteTests.swift +++ b/Tests/AppTests/PackageController+BuildsRouteTests.swift @@ -23,7 +23,7 @@ extension AllTests.PackageController_BuildsRouteTests { typealias BuildDetails = (id: Build.Id, reference: Reference, platform: Build.Platform, swiftVersion: SwiftVersion, status: Build.Status, docStatus: DocUpload.Status?) @Test func BuildInfo_query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { let pkg = try await savePackage(on: app.db, "1".url) @@ -87,7 +87,7 @@ extension AllTests.PackageController_BuildsRouteTests { } @Test func query() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -123,7 +123,7 @@ extension AllTests.PackageController_BuildsRouteTests { } @Test func query_no_builds() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, diff --git a/Tests/AppTests/PackageController+routesTests.swift b/Tests/AppTests/PackageController+routesTests.swift index 2e21b6fed..ddfde32df 100644 --- a/Tests/AppTests/PackageController+routesTests.swift +++ b/Tests/AppTests/PackageController+routesTests.swift @@ -29,7 +29,7 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.environment.processingBuildBacklog = { false } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -37,7 +37,7 @@ extension AllTests.PackageController_routesTests { try await Version(package: pkg, latest: .defaultBranch).save(on: app.db) // MUT - try await app.test(.GET, "/owner/package") { res async in + try await app.testing().test(.GET, "/owner/package") { res async in #expect(res.status == .ok) } } @@ -49,9 +49,9 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.httpClient.fetchHTTPStatusCode = { @Sendable _ in .notFound } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "/unknown/package") { res async in + try await app.testing().test(.GET, "/unknown/package") { res async in #expect(res.status == .notFound) } } @@ -63,9 +63,9 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.httpClient.fetchHTTPStatusCode = { @Sendable _ in .ok } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "/unknown/package") { res async in + try await app.testing().test(.GET, "/unknown/package") { res async in #expect(res.status == .notFound) } } @@ -79,9 +79,9 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.httpClient.fetchHTTPStatusCode = { @Sendable _ in throw FetchError() } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "/unknown/package") { res async in + try await app.testing().test(.GET, "/unknown/package") { res async in #expect(res.status == .notFound) } } @@ -89,7 +89,7 @@ extension AllTests.PackageController_routesTests { } @Test func ShowModel_packageAvailable() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -114,7 +114,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.httpClient.fetchHTTPStatusCode = { @Sendable _ in .ok } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT let model = try await PackageController.ShowModel(db: app.db, owner: "owner", repository: "package") @@ -133,7 +133,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.httpClient.fetchHTTPStatusCode = { @Sendable _ in .notFound } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT let model = try await PackageController.ShowModel(db: app.db, owner: "owner", repository: "package") @@ -152,7 +152,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.httpClient.fetchHTTPStatusCode = { @Sendable _ in throw FetchError() } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT let model = try await PackageController.ShowModel(db: app.db, owner: "owner", repository: "package") @@ -169,7 +169,7 @@ extension AllTests.PackageController_routesTests { @Test func readme_route() async throws { // Test that readme route is set up - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -177,7 +177,7 @@ extension AllTests.PackageController_routesTests { try await Version(package: pkg, latest: .defaultBranch).save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/readme") { res async in + try await app.testing().test(.GET, "/owner/package/readme") { res async in #expect(res.status == .ok) } } @@ -190,7 +190,7 @@ extension AllTests.PackageController_routesTests { #"
readme content
"# } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, defaultBranch: "main", name: "package", owner: "owner", readmeHtmlUrl: "html url") @@ -219,7 +219,7 @@ extension AllTests.PackageController_routesTests { return "" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner", readmeHtmlUrl: nil) @@ -250,7 +250,7 @@ extension AllTests.PackageController_routesTests { throw Error() } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, @@ -283,7 +283,7 @@ extension AllTests.PackageController_routesTests { } @Test func releases() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -291,7 +291,7 @@ extension AllTests.PackageController_routesTests { try await Version(package: pkg, latest: .defaultBranch).save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/releases") { res async in + try await app.testing().test(.GET, "/owner/package/releases") { res async in #expect(res.status == .ok) } } @@ -301,7 +301,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -309,7 +309,7 @@ extension AllTests.PackageController_routesTests { try await Version(package: pkg, latest: .defaultBranch).save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/builds") { res async in + try await app.testing().test(.GET, "/owner/package/builds") { res async in #expect(res.status == .ok) } } @@ -320,7 +320,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -329,7 +329,7 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/information-for-package-maintainers") { res async in + try await app.testing().test(.GET, "/owner/package/information-for-package-maintainers") { res async in #expect(res.status == .ok) } } @@ -341,7 +341,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -350,7 +350,7 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/information-for-package-maintainers") { res async in + try await app.testing().test(.GET, "/owner/package/information-for-package-maintainers") { res async in #expect(res.status == .ok) } } @@ -498,23 +498,23 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = { @Sendable _ in .ok } } operation: { - try await withApp { app in - try await app.test(.GET, "/owner/package/main/images/foo/bar.jpeg") { res async in + try await withSPIApp { app in + try await app.testing().test(.GET, "/owner/package/main/images/foo/bar.jpeg") { res async in #expect(res.headers.contentType == .init(type: "application", subType: "octet-stream")) } - try await app.test(.GET, "/owner/package/main/images/foo/bar.svg") { res async in + try await app.testing().test(.GET, "/owner/package/main/images/foo/bar.svg") { res async in #expect(res.headers.contentType == .init(type: "image", subType: "svg+xml")) } - try await app.test(.GET, "/owner/package/main/images/foo/bar.SVG") { res async in + try await app.testing().test(.GET, "/owner/package/main/images/foo/bar.SVG") { res async in #expect(res.headers.contentType == .init(type: "image", subType: "svg+xml")) } - try await app.test(.GET, "/owner/package/main/img/foo/bar.jpeg") { res async in + try await app.testing().test(.GET, "/owner/package/main/img/foo/bar.jpeg") { res async in #expect(res.headers.contentType == .init(type: "application", subType: "octet-stream")) } - try await app.test(.GET, "/owner/package/main/img/foo/bar.svg") { res async in + try await app.testing().test(.GET, "/owner/package/main/img/foo/bar.svg") { res async in #expect(res.headers.contentType == .init(type: "image", subType: "svg+xml")) } - try await app.test(.GET, "/owner/package/main/img/foo/bar.SVG") { res async in + try await app.testing().test(.GET, "/owner/package/main/img/foo/bar.SVG") { res async in #expect(res.headers.contentType == .init(type: "image", subType: "svg+xml")) } } @@ -524,7 +524,7 @@ extension AllTests.PackageController_routesTests { @Test func documentation_routes_redirect() async throws { // Test the redirect documentation routes without any reference: // /owner/package/documentation + various path elements - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -547,11 +547,11 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/documentation") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/target") } - try await app.test(.GET, "/owner/package/documentation/target/symbol") { res async in + try await app.testing().test(.GET, "/owner/package/documentation/target/symbol") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/target/symbol") } @@ -560,19 +560,19 @@ extension AllTests.PackageController_routesTests { // generated docs (i.e. `target` in this test) as that would prevent them from // cross-target linking. // Effectively, all we're doing is inserting the correct `ref` before `documentation`. - try await app.test(.GET, "/owner/package/documentation/foo") { res async in + try await app.testing().test(.GET, "/owner/package/documentation/foo") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/foo") } - try await app.test(.GET, "/owner/package/documentation/foo#anchor") { res async in + try await app.testing().test(.GET, "/owner/package/documentation/foo#anchor") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/foo#anchor") } - try await app.test(.GET, "/owner/package/documentation/FOO") { res async in + try await app.testing().test(.GET, "/owner/package/documentation/FOO") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/foo") } - try await app.test(.GET, "/owner/package/tutorials/foo") { res async in + try await app.testing().test(.GET, "/owner/package/tutorials/foo") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/tutorials/foo") } @@ -588,7 +588,7 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML()) } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -613,13 +613,13 @@ extension AllTests.PackageController_routesTests { // MUT // test partially qualified route (no archive) - try await app.test(.GET, "/owner/package/~/documentation") { @Sendable res async in + try await app.testing().test(.GET, "/owner/package/~/documentation") { @Sendable res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/target") } // test fully qualified route - try await app.test(.GET, "/owner/package/~/documentation/target") { res async in + try await app.testing().test(.GET, "/owner/package/~/documentation/target") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -632,7 +632,7 @@ extension AllTests.PackageController_routesTests { } // test catchall - try await app.test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { res async in + try await app.testing().test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -646,7 +646,7 @@ extension AllTests.PackageController_routesTests { } // Test case insensitive path. - try await app.test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { res async in + try await app.testing().test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -671,7 +671,7 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML(baseURL: "/owner/package/1.0.0")) } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -696,7 +696,7 @@ extension AllTests.PackageController_routesTests { // MUT // test fully qualified route - try await app.test(.GET, "/owner/package/~/documentation/target") { res async in + try await app.testing().test(.GET, "/owner/package/~/documentation/target") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -709,7 +709,7 @@ extension AllTests.PackageController_routesTests { } // test catchall - try await app.test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { res async in + try await app.testing().test(.GET, "/owner/package/~/documentation/target/a/b#anchor") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -722,7 +722,7 @@ extension AllTests.PackageController_routesTests { } // Test case insensitive path. - try await app.test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { res async in + try await app.testing().test(.GET, "/Owner/Package/~/documentation/target/A/b#anchor") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -745,7 +745,7 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML()) } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -770,13 +770,13 @@ extension AllTests.PackageController_routesTests { // MUT // test partially qualified route (no archive) - try await app.test(.GET, "/owner/package/1.2.3/documentation") { @Sendable res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation") { @Sendable res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.2.3/documentation/target") } // test fully qualified route - try await app.test(.GET, "/owner/package/1.2.3/documentation/target") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation/target") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -789,7 +789,7 @@ extension AllTests.PackageController_routesTests { } // test catchall - try await app.test(.GET, "/owner/package/1.2.3/documentation/target/a/b#anchor") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation/target/a/b#anchor") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -802,7 +802,7 @@ extension AllTests.PackageController_routesTests { } // Test case insensitive path. - try await app.test(.GET, "/Owner/Package/1.2.3/documentation/target/A/b#Anchor") { res async in + try await app.testing().test(.GET, "/Owner/Package/1.2.3/documentation/target/A/b#Anchor") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -823,7 +823,7 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML()) } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -846,15 +846,15 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/main/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/main/documentation") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/main/documentation/target") } - try await app.test(.GET, "/owner/package/1.0.0/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/1.0.0/documentation") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/target") } - try await app.test(.GET, "/owner/package/~/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/~/documentation") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.0.0/documentation/target") } @@ -867,7 +867,7 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.httpClient.fetchDocumentation = { @Sendable _ in .notFound } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -890,10 +890,10 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/main/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/main/documentation") { res async in #expect(res.status == .notFound) } - try await app.test(.GET, "/owner/package/1.0.0/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/1.0.0/documentation") { res async in #expect(res.status == .notFound) } } @@ -907,7 +907,7 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.httpClient.fetchDocumentation = { @Sendable uri in .badRequest } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -917,12 +917,12 @@ extension AllTests.PackageController_routesTests { // MUT // test base url - try await app.test(.GET, "/owner/package/1.2.3/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation") { res async in #expect(res.status == .notFound) } // test path a/b - try await app.test(.GET, "/owner/package/1.2.3/documentation/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation/a/b") { res async in #expect(res.status == .notFound) } } @@ -937,7 +937,7 @@ extension AllTests.PackageController_routesTests { $0.environment.dbId = { nil } $0.httpClient.fetchDocumentation = { @Sendable _ in throw SomeError() } } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") .save(on: app.db) @@ -951,11 +951,11 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/1.2.3/documentation") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation") { res async in #expect(res.status == .seeOther) #expect(res.headers.location == "/owner/package/1.2.3/documentation/foo") } - try await app.test(.GET, "/owner/package/1.2.3/documentation/foo") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation/foo") { res async in // hits Current.fetchDocumentation which throws, converted to notFound // Regression test for https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2015 #expect(res.status == .notFound) @@ -970,7 +970,7 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -983,14 +983,14 @@ extension AllTests.PackageController_routesTests { // MUT // test base url - try await app.test(.GET, "/owner/package/~/css/a") { res async in + try await app.testing().test(.GET, "/owner/package/~/css/a") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/css") #expect(res.body.asString() == "/owner/package/main/css/a") } // test path a/b - try await app.test(.GET, "/owner/package/~/css/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/~/css/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/css") #expect(res.body.asString() == "/owner/package/main/css/a/b") @@ -1004,17 +1004,17 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT // test base url - try await app.test(.GET, "/owner/package/1.2.3/css/a") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/css/a") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/css") #expect(res.body.asString() == "/owner/package/1.2.3/css/a") } // test path a/b - try await app.test(.GET, "/owner/package/1.2.3/css/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/css/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/css") #expect(res.body.asString() == "/owner/package/1.2.3/css/a/b") @@ -1029,7 +1029,7 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -1042,14 +1042,14 @@ extension AllTests.PackageController_routesTests { // MUT // test base url - try await app.test(.GET, "/owner/package/~/js/a") { res async in + try await app.testing().test(.GET, "/owner/package/~/js/a") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/javascript") #expect(res.body.asString() == "/owner/package/main/js/a") } // test path a/b - try await app.test(.GET, "/owner/package/~/js/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/~/js/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/javascript") #expect(res.body.asString() == "/owner/package/main/js/a/b") @@ -1063,17 +1063,17 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT // test base url - try await app.test(.GET, "/owner/package/1.2.3/js/a") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/js/a") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/javascript") #expect(res.body.asString() == "/owner/package/1.2.3/js/a") } // test path a/b - try await app.test(.GET, "/owner/package/1.2.3/js/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/js/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/javascript") #expect(res.body.asString() == "/owner/package/1.2.3/js/a/b") @@ -1088,7 +1088,7 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -1101,14 +1101,14 @@ extension AllTests.PackageController_routesTests { // MUT // test base url - try await app.test(.GET, "/owner/package/~/data/a") { res async in + try await app.testing().test(.GET, "/owner/package/~/data/a") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/main/data/a") } // test path a/b - try await app.test(.GET, "/owner/package/~/data/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/~/data/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/main/data/a/b") @@ -1116,7 +1116,7 @@ extension AllTests.PackageController_routesTests { // test case-insensitivity // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2168 - try await app.test(.GET, "/owner/package/~/data/documentation/Foo.json") { res async in + try await app.testing().test(.GET, "/owner/package/~/data/documentation/Foo.json") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/main/data/documentation/foo.json") @@ -1130,17 +1130,17 @@ extension AllTests.PackageController_routesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT // test base url - try await app.test(.GET, "/owner/package/1.2.3/data/a") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/data/a") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/1.2.3/data/a") } // test path a/b - try await app.test(.GET, "/owner/package/1.2.3/data/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/data/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/1.2.3/data/a/b") @@ -1148,7 +1148,7 @@ extension AllTests.PackageController_routesTests { // test case-insensitivity // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2168 - try await app.test(.GET, "/apple/swift-nio/main/data/documentation/NIOCore.json") { res async in + try await app.testing().test(.GET, "/apple/swift-nio/main/data/documentation/NIOCore.json") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/apple/swift-nio/main/data/documentation/niocore.json") @@ -1165,7 +1165,7 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "Package", owner: "Owner") .save(on: app.db) @@ -1178,7 +1178,7 @@ extension AllTests.PackageController_routesTests { reference: .tag(1, 2, 3)) .save(on: app.db) - try await app.test(.GET, "/owner/package/1.2.3/documentation/a/b") { res async throws in + try await app.testing().test(.GET, "/owner/package/1.2.3/documentation/a/b") { res async throws in let document = try SwiftSoup.parse(res.body.string) let linkElements = try document.select("link[rel='canonical']") #expect(linkElements.count == 1) @@ -1199,7 +1199,7 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML()) } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -1216,7 +1216,7 @@ extension AllTests.PackageController_routesTests { // MUT // test default path - try await app.test(.GET, "/owner/package/~/documentation/target") { res async in + try await app.testing().test(.GET, "/owner/package/~/documentation/target") { res async in #expect(res.status == .ok) let body = String(buffer: res.body) assertSnapshot(of: body, as: .html, named: "current-index") @@ -1229,7 +1229,7 @@ extension AllTests.PackageController_routesTests { } // test reference root path - try await app.test(.GET, "/owner/package/feature-1.2.3/documentation/target") { res async in + try await app.testing().test(.GET, "/owner/package/feature-1.2.3/documentation/target") { res async in #expect(res.status == .ok) let body = String(buffer: res.body) assertSnapshot(of: body, as: .html, named: "ref-index") @@ -1241,7 +1241,7 @@ extension AllTests.PackageController_routesTests { } // test path a/b - try await app.test(.GET, "/owner/package/feature-1.2.3/documentation/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/feature-1.2.3/documentation/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") let body = String(buffer: res.body) @@ -1264,7 +1264,7 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = { @Sendable _ in .ok(body: .mockIndexHTML()) } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -1287,16 +1287,16 @@ extension AllTests.PackageController_routesTests { .save(on: app.db) // MUT - try await app.test(.GET, "/owner/package/~/tutorials") { res async in + try await app.testing().test(.GET, "/owner/package/~/tutorials") { res async in #expect(res.status == .notFound) } - try await app.test(.GET, "/owner/package/~/tutorials/foo") { res async in + try await app.testing().test(.GET, "/owner/package/~/tutorials/foo") { res async in #expect(res.status == .ok) let body = String(buffer: res.body) assertSnapshot(of: body, as: .html, named: "index") #expect(body.contains(#"var baseUrl = "/owner/package/~/""#)) } - try await app.test(.GET, "/owner/package/~/tutorials/foo#anchor") { res async in + try await app.testing().test(.GET, "/owner/package/~/tutorials/foo#anchor") { res async in #expect(res.status == .ok) let body = String(buffer: res.body) assertSnapshot(of: body, as: .html, named: "index") @@ -1313,15 +1313,15 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = App.HTTPClient .echoURL(headers: ["content-type": "application/octet-stream"]) } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "/owner/package/1.2.3/favicon.ico") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/favicon.ico") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/1.2.3/favicon.ico") } - try await app.test(.GET, "/owner/package/1.2.3/favicon.svg") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/favicon.svg") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/owner/package/1.2.3/favicon.svg") @@ -1336,9 +1336,9 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = App.HTTPClient .echoURL(headers: ["content-type": "application/json"]) } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "/owner/package/1.2.3/theme-settings.json") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/theme-settings.json") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/json") #expect(res.body.asString() == "/owner/package/1.2.3/theme-settings.json") @@ -1353,9 +1353,9 @@ extension AllTests.PackageController_routesTests { $0.httpClient.fetchDocumentation = App.HTTPClient .echoURL(headers: ["content-type": "application/json"]) } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "/owner/package/1.2.3/linkable-paths.json") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/linkable-paths.json") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/json") #expect(res.body.asString() == "/owner/package/1.2.3/linkable-paths.json") @@ -1373,7 +1373,7 @@ extension AllTests.PackageController_routesTests { } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, name: "package", owner: "owner") @@ -1389,7 +1389,7 @@ extension AllTests.PackageController_routesTests { // MUT // test path a/b - try await app.test(.GET, "/owner/package/1.2.3/tutorials/a/b") { res async in + try await app.testing().test(.GET, "/owner/package/1.2.3/tutorials/a/b") { res async in #expect(res.status == .ok) #expect(res.content.contentType?.description == "text/html; charset=utf-8") #expect( @@ -1402,7 +1402,7 @@ extension AllTests.PackageController_routesTests { } // Test case insensitive path. - try await app.test(.GET, "/Owner/Package/1.2.3/tutorials/a/b") { res async in + try await app.testing().test(.GET, "/Owner/Package/1.2.3/tutorials/a/b") { res async in #expect(res.status == .ok) } } @@ -1470,7 +1470,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.environment.current = { .production } } operation: { - try await withApp(environment: .production) { prodApp in + try await withSPIApp(environment: .production) { prodApp in // setup let package = Package(url: URL(stringLiteral: "https://example.com/owner/repo0")) try await package.save(on: prodApp.db) @@ -1481,7 +1481,7 @@ extension AllTests.PackageController_routesTests { reference: .branch("default")).save(on: prodApp.db) // MUT - try await prodApp.test(.GET, "/owner/repo0/sitemap.xml") { res async in + try await prodApp.testing().test(.GET, "/owner/repo0/sitemap.xml") { res async in #expect(res.status == .ok) } } @@ -1493,7 +1493,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp(environment: .development) { devApp in + try await withSPIApp(environment: .development) { devApp in // setup let package = Package(url: URL(stringLiteral: "https://example.com/owner/repo0")) try await package.save(on: devApp.db) @@ -1504,7 +1504,7 @@ extension AllTests.PackageController_routesTests { reference: .branch("default")).save(on: devApp.db) // MUT - try await devApp.test(.GET, "/owner/repo0/sitemap.xml") { res async in + try await devApp.testing().test(.GET, "/owner/repo0/sitemap.xml") { res async in #expect(res.status == .notFound) } } @@ -1539,7 +1539,7 @@ extension AllTests.PackageController_routesTests { } $0.timeZone = .utc } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "https://github.com/foo/bar".url, processingStage: .ingestion) try await Repository(package: pkg, defaultBranch: "main", name: "bar", owner: "foo") @@ -1557,7 +1557,7 @@ extension AllTests.PackageController_routesTests { $0.date.now = .t1 + Constants.branchVersionRefreshDelay + 1 } operation: { // Ensure documentation is resolved - try await app.test(.GET, "/foo/bar/~/documentation/target") { res async in + try await app.testing().test(.GET, "/foo/bar/~/documentation/target") { res async in #expect(res.status == .ok) assertSnapshot(of: String(buffer: res.body), as: .html, named: "index") } @@ -1570,7 +1570,7 @@ extension AllTests.PackageController_routesTests { #expect(commit == ["new-commit"]) // Ensure documentation is still being resolved - try await app.test(.GET, "/foo/bar/~/documentation/target") { res async in + try await app.testing().test(.GET, "/foo/bar/~/documentation/target") { res async in #expect(res.status == .ok) assertSnapshot(of: String(buffer: res.body), as: .html, named: "index") } @@ -1581,7 +1581,7 @@ extension AllTests.PackageController_routesTests { @Test func getDocRoute_documentation() async throws { // owner/repo/1.2.3/documentation/archive - try await withApp { app in + try await withSPIApp { app in let req = Request(application: app, url: "", on: app.eventLoopGroup.next()) req.parameters.set("owner", to: "owner") req.parameters.set("repository", to: "repo") @@ -1598,7 +1598,7 @@ extension AllTests.PackageController_routesTests { try await withDependencies { $0.currentReferenceCache = .inMemory } operation: { - try await withApp { app in + try await withSPIApp { app in let req = Request(application: app, url: "", on: app.eventLoopGroup.next()) req.parameters.set("owner", to: "owner") req.parameters.set("repository", to: "repo") @@ -1626,7 +1626,7 @@ extension AllTests.PackageController_routesTests { } @Test func getDocRoute_missing_reference() async throws { - try await withApp { app in + try await withSPIApp { app in do { let req = Request(application: app, on: app.eventLoopGroup.next()) req.parameters.set("owner", to: "owner") @@ -1643,7 +1643,7 @@ extension AllTests.PackageController_routesTests { @Test func getDocRoute_missing_archive() async throws { // reference but no archive - try await withApp { app in + try await withSPIApp { app in do { let req = Request(application: app, on: app.eventLoopGroup.next()) req.parameters.set("owner", to: "owner") diff --git a/Tests/AppTests/PackageInfoTests.swift b/Tests/AppTests/PackageInfoTests.swift index 3b53ca598..f8e698377 100644 --- a/Tests/AppTests/PackageInfoTests.swift +++ b/Tests/AppTests/PackageInfoTests.swift @@ -21,7 +21,7 @@ extension AllTests.PackageInfoTests { @Test func title_package_name() async throws { // Ensure title is populated from package.name() - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p, name: "repo name", owner: "owner") @@ -42,7 +42,7 @@ extension AllTests.PackageInfoTests { @Test func title_repo_name() async throws { // Ensure title is populated from repoName if package.name() is nil - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") try await Repository(package: p, name: "repo name", owner: "owner") diff --git a/Tests/AppTests/PackageReleasesModelTests.swift b/Tests/AppTests/PackageReleasesModelTests.swift index 13f0cbb00..23b48e3dd 100644 --- a/Tests/AppTests/PackageReleasesModelTests.swift +++ b/Tests/AppTests/PackageReleasesModelTests.swift @@ -38,7 +38,7 @@ extension AllTests.PackageReleasesModelTests { try await withDependencies { $0.date.now = .spiBirthday } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(id: UUID(), url: "1".asGithubUrl.url) try await pkg.save(on: app.db) diff --git a/Tests/AppTests/PackageResultTests.swift b/Tests/AppTests/PackageResultTests.swift index 4a2da4b85..c67370fcf 100644 --- a/Tests/AppTests/PackageResultTests.swift +++ b/Tests/AppTests/PackageResultTests.swift @@ -22,7 +22,7 @@ extension AllTests.PackageResultTests { typealias PackageResult = PackageController.PackageResult @Test func joined5() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, defaultBranch: "main", @@ -56,7 +56,7 @@ extension AllTests.PackageResultTests { } @Test func joined5_no_preRelease() async throws { - try await withApp { app in + try await withSPIApp { app in do { let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -106,7 +106,7 @@ extension AllTests.PackageResultTests { } @Test func joined5_defaultBranch_only() async throws { - try await withApp { app in + try await withSPIApp { app in do { let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -152,7 +152,7 @@ extension AllTests.PackageResultTests { } @Test func query_owner_repository() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -179,7 +179,7 @@ extension AllTests.PackageResultTests { } @Test func query_owner_repository_case_insensitivity() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".url) try await Repository(package: pkg, @@ -205,7 +205,7 @@ extension AllTests.PackageResultTests { } @Test func activity() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "https://github.com/Alamofire/Alamofire") try await Repository(package: pkg, @@ -232,7 +232,7 @@ extension AllTests.PackageResultTests { } @Test func canonicalDocumentationTarget() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { // first package has docs diff --git a/Tests/AppTests/PackageTests.swift b/Tests/AppTests/PackageTests.swift index 7d4e5dd5a..dca150b53 100644 --- a/Tests/AppTests/PackageTests.swift +++ b/Tests/AppTests/PackageTests.swift @@ -56,7 +56,7 @@ extension AllTests.PackageTests { } @Test func save_status() async throws { - try await withApp { app in + try await withSPIApp { app in do { // default status let pkg = Package() // avoid using init with default argument in order to test db default pkg.url = "1" @@ -76,7 +76,7 @@ extension AllTests.PackageTests { try await withDependencies { $0.date.now = .now } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "1") let scoreDetails = Score.Details.mock pkg.scoreDetails = scoreDetails @@ -118,7 +118,7 @@ extension AllTests.PackageTests { } @Test func unique_url() async throws { - try await withApp { app in + try await withSPIApp { app in try await Package(url: "p1").save(on: app.db) do { try await Package(url: "p1").save(on: app.db) @@ -128,7 +128,7 @@ extension AllTests.PackageTests { } @Test func filter_by_url() async throws { - try await withApp { app in + try await withSPIApp { app in for url in ["https://foo.com/1", "https://foo.com/2"] { try await Package(url: url.url).save(on: app.db) } @@ -138,7 +138,7 @@ extension AllTests.PackageTests { } @Test func filter_by_urls() async throws { - try await withApp { app in + try await withSPIApp { app in for url in ["https://foo.com/1.git", "https://foo.com/2.git", "https://foo.com/a.git", "https://foo.com/A.git"] { try await Package(url: url.url).save(on: app.db) } @@ -160,7 +160,7 @@ extension AllTests.PackageTests { } @Test func repository() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") do { let pkg = try #require(try await Package.query(on: app.db).with(\.$repositories).first()) @@ -176,7 +176,7 @@ extension AllTests.PackageTests { } @Test func versions() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "1") let versions = [ try Version(package: pkg, reference: .branch("branch")), @@ -192,7 +192,7 @@ extension AllTests.PackageTests { } @Test func findBranchVersion() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, defaultBranch: "default").create(on: app.db) @@ -218,7 +218,7 @@ extension AllTests.PackageTests { } @Test func findRelease() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let versions: [Version] = [ @@ -234,7 +234,7 @@ extension AllTests.PackageTests { } @Test func findPreRelease() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") func t(_ seconds: TimeInterval) -> Date { Date(timeIntervalSince1970: seconds) } @@ -265,7 +265,7 @@ extension AllTests.PackageTests { // Test pre-release sorting of betas with double digit build numbers, // e.g. 2.0.0-b11 should come after 2.0.0-b9 // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/706 - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") func t(_ seconds: TimeInterval) -> Date { Date(timeIntervalSince1970: seconds) } @@ -284,7 +284,7 @@ extension AllTests.PackageTests { @Test func findSignificantReleases_old_beta() async throws { // Test to ensure outdated betas aren't picked up as latest versions - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: UUID(), url: "1") try await pkg.save(on: app.db) @@ -345,7 +345,7 @@ extension AllTests.PackageTests { return "" } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let db = app.db // run reconcile to ingest package @@ -413,7 +413,7 @@ extension AllTests.PackageTests { } @Test func save_platformCompatibility_save() async throws { - try await withApp { app in + try await withSPIApp { app in try await Package(url: "1".url, platformCompatibility: [.iOS, .macOS, .iOS]) .save(on: app.db) let readBack = try #require(try await Package.query(on: app.db).first()) @@ -426,7 +426,7 @@ extension AllTests.PackageTests { // occuring but we can't enforce a set at the DDL level so it's // technically possible and we want to ensure it doesn't cause // errors) - try await withApp { app in + try await withSPIApp { app in try await Package(url: "1".url).save(on: app.db) try await (app.db as! SQLDatabase).raw( "update packages set platform_compatibility = '{ios,ios}'" @@ -437,7 +437,7 @@ extension AllTests.PackageTests { } @Test func updatePlatformCompatibility() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let p = try await savePackage(on: app.db, "1") let v = try Version(package: p, latest: .defaultBranch) diff --git a/Tests/AppTests/PipelineTests.swift b/Tests/AppTests/PipelineTests.swift index 984bc352c..1cec3d866 100644 --- a/Tests/AppTests/PipelineTests.swift +++ b/Tests/AppTests/PipelineTests.swift @@ -28,7 +28,7 @@ extension AllTests.PipelineTests { @Test func fetchCandidates_ingestion_fifo() async throws { // oldest first - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .ok, processingStage: .reconciliation), Package(url: "2", status: .ok, processingStage: .reconciliation), @@ -45,7 +45,7 @@ extension AllTests.PipelineTests { } @Test func fetchCandidates_ingestion_limit() async throws { - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .ok, processingStage: .reconciliation), Package(url: "2", status: .ok, processingStage: .reconciliation), @@ -63,7 +63,7 @@ extension AllTests.PipelineTests { @Test func fetchCandidates_ingestion_correct_stage() async throws { // only pick up from reconciliation stage - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .ok, processingStage: nil), Package(url: "2", status: .ok, processingStage: .reconciliation), @@ -81,7 +81,7 @@ extension AllTests.PipelineTests { @Test func fetchCandidates_ingestion_prefer_new() async throws { // make sure records with status = new come first, then least recent - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .notFound, processingStage: .reconciliation), Package(url: "2", status: .new, processingStage: .reconciliation), @@ -101,7 +101,7 @@ extension AllTests.PipelineTests { @Test func fetchCandidates_ingestion_eventual_refresh() async throws { // Make sure packages in .analysis stage get re-ingested after a while to // check for upstream package changes - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .ok, processingStage: .analysis), Package(url: "2", status: .ok, processingStage: .analysis), @@ -127,7 +127,7 @@ extension AllTests.PipelineTests { // // *) in addition to the .reconciliation ones, which we always pick up, regardless of // ingestion dead time. - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .new, processingStage: .reconciliation), Package(url: "2", status: .new, processingStage: .ingestion), @@ -146,7 +146,7 @@ extension AllTests.PipelineTests { @Test func fetchCandidates_analysis_correct_stage() async throws { // only pick up from ingestion stage - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .ok, processingStage: nil), Package(url: "2", status: .ok, processingStage: .reconciliation), @@ -160,7 +160,7 @@ extension AllTests.PipelineTests { @Test func fetchCandidates_analysis_prefer_new() async throws { // Test pick up from ingestion stage with status = new first, then FIFO - try await withApp { app in + try await withSPIApp { app in try await [ Package(url: "1", status: .notFound, processingStage: .ingestion), Package(url: "2", status: .ok, processingStage: .ingestion), @@ -205,7 +205,7 @@ extension AllTests.PipelineTests { return "" } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - first stage try await reconcile(client: app.client, database: app.db) diff --git a/Tests/AppTests/ProductTests.swift b/Tests/AppTests/ProductTests.swift index 0b0d57900..e910c788d 100644 --- a/Tests/AppTests/ProductTests.swift +++ b/Tests/AppTests/ProductTests.swift @@ -55,7 +55,7 @@ extension AllTests.ProductTests { } @Test func Product_save() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(id: UUID(), url: "1") let ver = try Version(id: UUID(), package: pkg) let prod = try Product(id: UUID(), @@ -78,7 +78,7 @@ extension AllTests.ProductTests { @Test func delete_cascade() async throws { // delete version must delete products - try await withApp { app in + try await withSPIApp { app in let pkg = Package(id: UUID(), url: "1") let ver = try Version(id: UUID(), package: pkg) let prod = try Product(id: UUID(), version: ver, type: .library(.automatic), name: "p1") diff --git a/Tests/AppTests/RSSTests.swift b/Tests/AppTests/RSSTests.swift index 51ea9b297..210733bbd 100644 --- a/Tests/AppTests/RSSTests.swift +++ b/Tests/AppTests/RSSTests.swift @@ -68,7 +68,7 @@ extension AllTests.RSSTests { } @Test func recentPackages() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for idx in 1...10 { let pkg = Package(id: UUID(), url: "\(idx)".asGithubUrl.url) @@ -106,7 +106,7 @@ extension AllTests.RSSTests { } @Test func recentReleases() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for idx in 1...10 { let pkg = Package(id: UUID(), url: "\(idx)".asGithubUrl.url) @@ -141,8 +141,8 @@ extension AllTests.RSSTests { try await withDependencies { $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in - try await app.test(.GET, "packages.rss", afterResponse: { res async in + try await withSPIApp { app in + try await app.testing().test(.GET, "packages.rss", afterResponse: { res async in #expect(res.status == .ok) #expect(res.content.contentType == .some(.init(type: "application", subType: "rss+xml"))) }) @@ -155,7 +155,7 @@ extension AllTests.RSSTests { try await withDependencies { $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // see RecentViewsTests.test_recentReleases_filter for filter results for idx in 1...10 { @@ -180,7 +180,7 @@ extension AllTests.RSSTests { try await RecentRelease.refresh(on: app.db) // MUT - try await app.test(.GET, "releases.rss", afterResponse: { @MainActor res async in + try await app.testing().test(.GET, "releases.rss", afterResponse: { @MainActor res async in #expect(res.status == .ok) #expect(res.content.contentType == .some(.init(type: "application", subType: "rss+xml"))) // validation @@ -196,7 +196,7 @@ extension AllTests.RSSTests { try await withDependencies { $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // see RecentViewsTests.test_recentReleases_filter for filter results for idx in 1...10 { @@ -221,7 +221,7 @@ extension AllTests.RSSTests { try await RecentRelease.refresh(on: app.db) // MUT - try await app.test(.GET, "releases.rss?major=true", afterResponse: { @MainActor res async in + try await app.testing().test(.GET, "releases.rss?major=true", afterResponse: { @MainActor res async in #expect(res.status == .ok) #expect(res.content.contentType == .some(.init(type: "application", subType: "rss+xml"))) // validation @@ -237,7 +237,7 @@ extension AllTests.RSSTests { try await withDependencies { $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // see RecentViewsTests.test_recentReleases_filter for filter results for idx in 1...10 { @@ -262,7 +262,7 @@ extension AllTests.RSSTests { try await RecentRelease.refresh(on: app.db) // MUT - try await app.test(.GET, "releases.rss?major=true&minor=true", afterResponse: { @MainActor res async in + try await app.testing().test(.GET, "releases.rss?major=true&minor=true", afterResponse: { @MainActor res async in #expect(res.status == .ok) #expect(res.content.contentType == .some(.init(type: "application", subType: "rss+xml"))) // validation @@ -278,7 +278,7 @@ extension AllTests.RSSTests { try await withDependencies { $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // see RecentViewsTests.test_recentReleases_filter for filter results for idx in 1...12 { @@ -304,7 +304,7 @@ extension AllTests.RSSTests { try await RecentRelease.refresh(on: app.db) // MUT - try await app.test(.GET, "releases.rss?pre=true", afterResponse: { @MainActor res async in + try await app.testing().test(.GET, "releases.rss?pre=true", afterResponse: { @MainActor res async in #expect(res.status == .ok) #expect(res.content.contentType == .some(.init(type: "application", subType: "rss+xml"))) // validation diff --git a/Tests/AppTests/ReAnalyzeVersionsTests.swift b/Tests/AppTests/ReAnalyzeVersionsTests.swift index 303f40948..f51abdd72 100644 --- a/Tests/AppTests/ReAnalyzeVersionsTests.swift +++ b/Tests/AppTests/ReAnalyzeVersionsTests.swift @@ -43,7 +43,7 @@ extension AllTests.ReAnalyzeVersionsTests { } $0.httpClient.mastodonPost = { @Sendable _ in } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup // - package dump does not include toolsVersion, targets to simulate an "old version" // - run analysis to create existing version @@ -152,7 +152,7 @@ extension AllTests.ReAnalyzeVersionsTests { // 1) both versions updated before cutoff -> candidate // 2) one version update before cutoff, one after -> candidate // 3) both version updated after cutoff -> not a candidate - try await withApp { app in + try await withSPIApp { app in let cutoff = Date(timeIntervalSince1970: 2) do { let p = Package(url: "1") @@ -216,7 +216,7 @@ extension AllTests.ReAnalyzeVersionsTests { return "" } } operation: { - try await withApp { app in + try await withSPIApp { app in let pkg = try await savePackage(on: app.db, "https://github.com/foo/1".url, processingStage: .ingestion) diff --git a/Tests/AppTests/RecentViewsTests.swift b/Tests/AppTests/RecentViewsTests.swift index 049879d4a..2f4120749 100644 --- a/Tests/AppTests/RecentViewsTests.swift +++ b/Tests/AppTests/RecentViewsTests.swift @@ -22,7 +22,7 @@ import Testing extension AllTests.RecentViewsTests { @Test func recentPackages() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { // 1st package is eligible let pkg = Package(id: UUID(), url: "1") @@ -64,7 +64,7 @@ extension AllTests.RecentViewsTests { } @Test func recentReleases() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { // 1st package is eligible let pkg = Package(id: UUID(), url: "1") @@ -189,7 +189,7 @@ extension AllTests.RecentViewsTests { @Test func recentPackages_dedupe_issue() async throws { // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/315 - try await withApp { app in + try await withSPIApp { app in // setup // Package with two eligible versions that differ in package name let pkg = Package(id: UUID(), url: "1") @@ -217,7 +217,7 @@ extension AllTests.RecentViewsTests { @Test func recentReleases_dedupe_issue() async throws { // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/315 - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: UUID(), url: "1") try await pkg.save(on: app.db) diff --git a/Tests/AppTests/ReconcilerTests.swift b/Tests/AppTests/ReconcilerTests.swift index 3daa8080b..c16fa0cb3 100644 --- a/Tests/AppTests/ReconcilerTests.swift +++ b/Tests/AppTests/ReconcilerTests.swift @@ -22,7 +22,7 @@ import Vapor extension AllTests.ReconcilerTests { @Test func fetchCurrentPackageList() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for url in ["1", "2", "3"].asURLs { try await Package(url: url).save(on: app.db) @@ -37,7 +37,7 @@ extension AllTests.ReconcilerTests { } @Test func reconcileMainPackageList() async throws { - try await withApp { app in + try await withSPIApp { app in let urls = ["1", "2", "3"] try await withDependencies { $0.packageListRepository.fetchPackageList = { @Sendable _ in urls.asURLs } @@ -61,7 +61,7 @@ extension AllTests.ReconcilerTests { } @Test func reconcileMainPackageList_adds_and_deletes() async throws { - try await withApp { app in + try await withSPIApp { app in // save intial set of packages 1, 2, 3 for url in ["1", "2", "3"].asURLs { try await Package(url: url).save(on: app.db) @@ -85,7 +85,7 @@ extension AllTests.ReconcilerTests { } @Test func reconcileMainPackageList_packageDenyList() async throws { - try await withApp { app in + try await withSPIApp { app in // Save the intial set of packages for url in ["1", "2", "3"].asURLs { try await Package(url: url).save(on: app.db) @@ -112,7 +112,7 @@ extension AllTests.ReconcilerTests { } @Test func reconcileMainPackageList_packageDenyList_caseSensitivity() async throws { - try await withApp { app in + try await withSPIApp { app in // Save the intial set of packages for url in ["https://example.com/one/one", "https://example.com/two/two"].asURLs { try await Package(url: url).save(on: app.db) @@ -140,7 +140,7 @@ extension AllTests.ReconcilerTests { @Test func reconcileCustomCollections() async throws { // Test single custom collection reconciliation - try await withApp { app in + try await withSPIApp { app in // setup var fullPackageList = [URL("https://github.com/a.git"), URL("https://github.com/b.git"), URL("https://github.com/c.git")] for url in fullPackageList { try await Package(url: url).save(on: app.db) } @@ -205,7 +205,7 @@ extension AllTests.ReconcilerTests { @Test func reconcileCustomCollections_limit() async throws { // Test custom collection reconciliation size limit - try await withApp { app in + try await withSPIApp { app in // setup let fullPackageList = (1...60).map { URL(string: "https://github.com/\($0).git")! } for url in fullPackageList { try await Package(url: url).save(on: app.db) } @@ -249,7 +249,7 @@ extension AllTests.ReconcilerTests { [.init(key: "list", name: "List", url: "collectionURL")] } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT _ = try await App.reconcile(client: app.client, database: app.db) diff --git a/Tests/AppTests/RepositoryTests.swift b/Tests/AppTests/RepositoryTests.swift index 61a517c04..947556ec2 100644 --- a/Tests/AppTests/RepositoryTests.swift +++ b/Tests/AppTests/RepositoryTests.swift @@ -23,7 +23,7 @@ import Testing extension AllTests.RepositoryTests { @Test func save() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(id: UUID(), url: "1") try await pkg.save(on: app.db) let repo = try Repository(id: UUID(), @@ -94,7 +94,7 @@ extension AllTests.RepositoryTests { } @Test func generated_lastActivityAt_lastCommitDate() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "p1") try await pkg.save(on: app.db) @@ -113,7 +113,7 @@ extension AllTests.RepositoryTests { } @Test func generated_lastActivityAt_lastIssueClosedAt() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "p1") try await pkg.save(on: app.db) @@ -132,7 +132,7 @@ extension AllTests.RepositoryTests { } @Test func generated_lastActivityAt_lastPullRequestClosedAt() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "p1") try await pkg.save(on: app.db) @@ -151,7 +151,7 @@ extension AllTests.RepositoryTests { } @Test func generated_lastActivityAt_nullValues() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "p1") try await pkg.save(on: app.db) @@ -169,7 +169,7 @@ extension AllTests.RepositoryTests { } @Test func package_relationship() async throws { - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "p1") try await pkg.save(on: app.db) let repo = try Repository(package: pkg) @@ -193,7 +193,7 @@ extension AllTests.RepositoryTests { @Test func delete_cascade() async throws { // delete package must delete repository - try await withApp { app in + try await withSPIApp { app in let pkg = Package(id: UUID(), url: "1") let repo = try Repository(id: UUID(), package: pkg) try await pkg.save(on: app.db) @@ -215,7 +215,7 @@ extension AllTests.RepositoryTests { @Test func uniqueOwnerRepository() async throws { // Ensure owner/repository is unique, testing various combinations with // matching/non-matching case - try await withApp { app in + try await withSPIApp { app in let p1 = try await savePackage(on: app.db, "1") try await Repository(id: UUID(), package: p1, name: "bar", owner: "foo").save(on: app.db) let p2 = try await savePackage(on: app.db, "2") @@ -260,7 +260,7 @@ extension AllTests.RepositoryTests { } @Test func name_index() async throws { - try await withApp { app in + try await withSPIApp { app in let db = try #require(app.db as? SQLDatabase) // Quick way to check index exists - this will throw // "server: index "idx_repositories_name" does not exist (DropErrorMsgNonExistent)" diff --git a/Tests/AppTests/RoutesTests.swift b/Tests/AppTests/RoutesTests.swift index cf8b62028..763e4b42f 100644 --- a/Tests/AppTests/RoutesTests.swift +++ b/Tests/AppTests/RoutesTests.swift @@ -27,15 +27,15 @@ extension AllTests.RoutesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = App.HTTPClient.echoURL() } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "foo/bar/1.2.3/images/baz.png") { res async in + try await app.testing().test(.GET, "foo/bar/1.2.3/images/baz.png") { res async in // validation #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") #expect(res.body.asString() == "/foo/bar/1.2.3/images/baz.png") } - try await app.test(.GET, "foo/bar/1.2.3/images/BAZ.png") { res async in + try await app.testing().test(.GET, "foo/bar/1.2.3/images/BAZ.png") { res async in // validation #expect(res.status == .ok) #expect(res.content.contentType?.description == "application/octet-stream") @@ -50,9 +50,9 @@ extension AllTests.RoutesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = { @Sendable _ in .ok } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "foo/bar/1.2.3/img/baz.png") { res async in + try await app.testing().test(.GET, "foo/bar/1.2.3/img/baz.png") { res async in // validation #expect(res.status == .ok) } @@ -65,9 +65,9 @@ extension AllTests.RoutesTests { $0.environment.awsDocsBucket = { "docs-bucket" } $0.httpClient.fetchDocumentation = { @Sendable _ in .ok } } operation: { - try await withApp { app in + try await withSPIApp { app in // MUT - try await app.test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in + try await app.testing().test(.GET, "foo/bar/1.2.3/videos/baz.mov") { res async in // validation #expect(res.status == .ok) } @@ -80,8 +80,8 @@ extension AllTests.RoutesTests { $0.environment.dbId = { nil } $0.environment.maintenanceMessage = { "MAINTENANCE_MESSAGE" } } operation: { - try await withApp { app in - try await app.test(.GET, "/") { res async in + try await withSPIApp { app in + try await app.testing().test(.GET, "/") { res async in #expect(res.body.string.contains("MAINTENANCE_MESSAGE")) } } diff --git a/Tests/AppTests/SQLKitExtensionTests.swift b/Tests/AppTests/SQLKitExtensionTests.swift index 1c54a5ae8..fc614b418 100644 --- a/Tests/AppTests/SQLKitExtensionTests.swift +++ b/Tests/AppTests/SQLKitExtensionTests.swift @@ -21,7 +21,7 @@ import Testing extension AllTests.SQLKitExtensionTests { @Test func OrderByGroup() async throws { - try await withApp { app in + try await withSPIApp { app in let b = SQLOrderBy(SQLIdentifier("id"), .ascending) .then(SQLIdentifier("foo"), .descending) #expect(app.db.renderSQL(b) == #""id" ASC, "foo" DESC"#) @@ -29,7 +29,7 @@ extension AllTests.SQLKitExtensionTests { } @Test func OrderByGroup_complex() async throws { - try await withApp { app in + try await withSPIApp { app in let packageName = SQLIdentifier("package_name") let mergedTerms = SQLBind("a b") let score = SQLIdentifier("score") diff --git a/Tests/AppTests/ScoreTests.swift b/Tests/AppTests/ScoreTests.swift index ae5339afa..7e1a2f9ca 100644 --- a/Tests/AppTests/ScoreTests.swift +++ b/Tests/AppTests/ScoreTests.swift @@ -216,7 +216,7 @@ extension AllTests.ScoreTests { @Test(.dependency(\.date.now, .now)) func computeDetails() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, defaultBranch: "default", stars: 10_000).save(on: app.db) @@ -251,7 +251,7 @@ extension AllTests.ScoreTests { @Test(.dependency(\.date.now, .now)) func computeDetails_unknown_resolvedDependencies() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") try await Repository(package: pkg, defaultBranch: "default", stars: 10_000).save(on: app.db) diff --git a/Tests/AppTests/SearchFilterTests.swift b/Tests/AppTests/SearchFilterTests.swift index a388e96b8..061efe909 100644 --- a/Tests/AppTests/SearchFilterTests.swift +++ b/Tests/AppTests/SearchFilterTests.swift @@ -79,7 +79,7 @@ extension AllTests.SearchFilterTests { // MARK: Filters @Test func authorFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try AuthorSearchFilter(expression: .init(operator: .is, value: "sherlouk")) #expect(filter.key == .author) @@ -105,7 +105,7 @@ extension AllTests.SearchFilterTests { } @Test func keywordFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try KeywordSearchFilter(expression: .init(operator: .is, value: "cache")) #expect(filter.key == .keyword) @@ -132,7 +132,7 @@ extension AllTests.SearchFilterTests { } @Test func lastActivityFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LastActivitySearchFilter(expression: .init(operator: .is, value: "1970-01-01")) #expect(filter.key == .lastActivity) @@ -158,7 +158,7 @@ extension AllTests.SearchFilterTests { } @Test func lastCommitFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LastCommitSearchFilter(expression: .init(operator: .is, value: "1970-01-01")) #expect(filter.key == .lastCommit) @@ -184,7 +184,7 @@ extension AllTests.SearchFilterTests { } @Test func licenseFilter_compatible() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LicenseSearchFilter(expression: .init(operator: .is, value: "compatible")) #expect(filter.key == .license) @@ -203,7 +203,7 @@ extension AllTests.SearchFilterTests { } @Test func licenseFilter_single() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LicenseSearchFilter(expression: .init(operator: .is, value: "mit")) #expect(filter.key == .license) @@ -240,7 +240,7 @@ extension AllTests.SearchFilterTests { } @Test func licenseFilter_incompatible() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LicenseSearchFilter(expression: .init(operator: .is, value: "incompatible")) #expect(filter.key == .license) @@ -259,7 +259,7 @@ extension AllTests.SearchFilterTests { } @Test func licenseFilter_none() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LicenseSearchFilter(expression: .init(operator: .is, value: "none")) #expect(filter.key == .license) #expect(filter.predicate == .init(operator: .in, @@ -277,7 +277,7 @@ extension AllTests.SearchFilterTests { } @Test func licenseFilter_other() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try LicenseSearchFilter(expression: .init(operator: .is, value: "other")) #expect(filter.key == .license) #expect(filter.predicate == .init(operator: .in, @@ -304,7 +304,7 @@ extension AllTests.SearchFilterTests { @Test func platformFilter_single_value() async throws { // test single value happy path - try await withApp { app in + try await withSPIApp { app in let filter = try PlatformSearchFilter(expression: .init(operator: .is, value: "ios")) #expect(filter.key == .platform) @@ -390,7 +390,7 @@ extension AllTests.SearchFilterTests { } @Test func starsFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let filter = try StarsSearchFilter(expression: .init(operator: .is, value: "1234")) #expect(filter.key == .stars) #expect(filter.predicate == .init(operator: .equal, @@ -415,7 +415,7 @@ extension AllTests.SearchFilterTests { } @Test func productTypeFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // test single value happy path let filter = try ProductTypeSearchFilter(expression: .init(operator: .is, value: "executable")) @@ -435,7 +435,7 @@ extension AllTests.SearchFilterTests { } @Test func productTypeFilter_macro() async throws { - try await withApp { app in + try await withSPIApp { app in // Test "virtual" macro product filter let filter = try ProductTypeSearchFilter(expression: .init(operator: .is, value: "macro")) #expect(filter.key == .productType) diff --git a/Tests/AppTests/SearchShowModelAppTests.swift b/Tests/AppTests/SearchShowModelAppTests.swift index d7f2dfd88..51ea6662d 100644 --- a/Tests/AppTests/SearchShowModelAppTests.swift +++ b/Tests/AppTests/SearchShowModelAppTests.swift @@ -26,7 +26,7 @@ extension AllTests.SearchShowModelAppTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp { app in + try await withSPIApp { app in let request = Vapor.Request(application: app, url: "search?query=alamo&page=2&utm_campaign=test&utm_source=email", on: app.eventLoopGroup.next()) diff --git a/Tests/AppTests/SearchTests.swift b/Tests/AppTests/SearchTests.swift index f2ef02d12..faa64a3cf 100644 --- a/Tests/AppTests/SearchTests.swift +++ b/Tests/AppTests/SearchTests.swift @@ -37,7 +37,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_single_term() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder(on: app.db, terms: ["a"], filters: []) #expect(app.db.renderSQL(b) == #"SELECT 'package' AS "match_type", NULL AS "keyword", "package_id", "package_name", "repo_name", "repo_owner", "score", "summary", "stars", "license", "last_commit_date", "last_activity_at", "keywords", "has_docs", NULL::INT AS "levenshtein_dist", ts_rank("tsvector", "tsquery") >= 0.05 AS "has_exact_word_matches" FROM "search", plainto_tsquery($1) AS "tsquery" WHERE CONCAT_WS(' ', "package_name", COALESCE("summary", ''), "repo_name", "repo_owner", ARRAY_TO_STRING("keywords", ' '), ARRAY_TO_STRING("product_names", ' ')) ~* $2 AND "repo_owner" IS NOT NULL AND "repo_name" IS NOT NULL ORDER BY LOWER(COALESCE("package_name", '')) = $3 DESC, "has_exact_word_matches" DESC, "score" DESC, "stars" DESC, "package_name" ASC"#) #expect(app.db.binds(b) == ["a", "a", "a"]) @@ -45,7 +45,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_multiple_terms() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder(on: app.db, terms: ["a", "b"], filters: []) #expect(app.db.renderSQL(b) == #"SELECT 'package' AS "match_type", NULL AS "keyword", "package_id", "package_name", "repo_name", "repo_owner", "score", "summary", "stars", "license", "last_commit_date", "last_activity_at", "keywords", "has_docs", NULL::INT AS "levenshtein_dist", ts_rank("tsvector", "tsquery") >= 0.05 AS "has_exact_word_matches" FROM "search", plainto_tsquery($1) AS "tsquery" WHERE CONCAT_WS(' ', "package_name", COALESCE("summary", ''), "repo_name", "repo_owner", ARRAY_TO_STRING("keywords", ' '), ARRAY_TO_STRING("product_names", ' ')) ~* $2 AND CONCAT_WS(' ', "package_name", COALESCE("summary", ''), "repo_name", "repo_owner", ARRAY_TO_STRING("keywords", ' '), ARRAY_TO_STRING("product_names", ' ')) ~* $3 AND "repo_owner" IS NOT NULL AND "repo_name" IS NOT NULL ORDER BY LOWER(COALESCE("package_name", '')) = $4 DESC, "has_exact_word_matches" DESC, "score" DESC, "stars" DESC, "package_name" ASC"#) #expect(app.db.binds(b) == ["a b", "a", "b", "a b"]) @@ -53,7 +53,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_AuthorSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try AuthorSearchFilter(expression: .init(operator: .is, value: "foo"))] @@ -67,7 +67,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_KeywordSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try KeywordSearchFilter(expression: .init(operator: .is, @@ -82,7 +82,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_LastActivitySearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try LastActivitySearchFilter(expression: .init(operator: .greaterThan, @@ -97,7 +97,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_LastCommitSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try LastCommitSearchFilter(expression: .init(operator: .greaterThan, @@ -112,7 +112,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_LicenseSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try LicenseSearchFilter(expression: .init(operator: .is, value: "mit"))] @@ -126,7 +126,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_PlatformSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try PlatformSearchFilter(expression: .init(operator: .is, value: "ios,macos"))] @@ -140,7 +140,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_ProductTypeSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in for type in ProductTypeSearchFilter.ProductType.allCases { let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], @@ -157,7 +157,7 @@ extension AllTests.SearchTests { } @Test func packageMatchQuery_StarsSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.packageMatchQueryBuilder( on: app.db, terms: ["a"], filters: [try StarsSearchFilter(expression: .init(operator: .greaterThan, @@ -171,7 +171,7 @@ extension AllTests.SearchTests { } @Test func keywordMatchQuery_single_term() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.keywordMatchQueryBuilder(on: app.db, terms: ["a"]) #expect(app.db.renderSQL(b) == #"SELECT DISTINCT 'keyword' AS "match_type", "keyword", NULL::UUID AS "package_id", NULL AS "package_name", NULL AS "repo_name", NULL AS "repo_owner", NULL::INT AS "score", NULL AS "summary", NULL::INT AS "stars", NULL AS "license", NULL::TIMESTAMP AS "last_commit_date", NULL::TIMESTAMP AS "last_activity_at", NULL::TEXT[] AS "keywords", NULL::BOOL AS "has_docs", NULL::INT AS "levenshtein_dist", NULL::BOOL AS "has_exact_word_matches" FROM "search", UNNEST("keywords") AS "keyword" WHERE "keyword" ILIKE $1 LIMIT 50"#) #expect(app.db.binds(b) == ["%a%"]) @@ -179,7 +179,7 @@ extension AllTests.SearchTests { } @Test func keywordMatchQuery_multiple_terms() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.keywordMatchQueryBuilder(on: app.db, terms: ["a", "b"]) #expect(app.db.renderSQL(b) == #"SELECT DISTINCT 'keyword' AS "match_type", "keyword", NULL::UUID AS "package_id", NULL AS "package_name", NULL AS "repo_name", NULL AS "repo_owner", NULL::INT AS "score", NULL AS "summary", NULL::INT AS "stars", NULL AS "license", NULL::TIMESTAMP AS "last_commit_date", NULL::TIMESTAMP AS "last_activity_at", NULL::TEXT[] AS "keywords", NULL::BOOL AS "has_docs", NULL::INT AS "levenshtein_dist", NULL::BOOL AS "has_exact_word_matches" FROM "search", UNNEST("keywords") AS "keyword" WHERE "keyword" ILIKE $1 LIMIT 50"#) #expect(app.db.binds(b) == ["%a b%"]) @@ -187,7 +187,7 @@ extension AllTests.SearchTests { } @Test func authorMatchQuery_single_term() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.authorMatchQueryBuilder(on: app.db, terms: ["a"]) #expect(app.db.renderSQL(b) == #"SELECT DISTINCT 'author' AS "match_type", NULL AS "keyword", NULL::UUID AS "package_id", NULL AS "package_name", NULL AS "repo_name", "repo_owner", NULL::INT AS "score", NULL AS "summary", NULL::INT AS "stars", NULL AS "license", NULL::TIMESTAMP AS "last_commit_date", NULL::TIMESTAMP AS "last_activity_at", NULL::TEXT[] AS "keywords", NULL::BOOL AS "has_docs", LEVENSHTEIN("repo_owner", $1) AS "levenshtein_dist", NULL::BOOL AS "has_exact_word_matches" FROM "search" WHERE "repo_owner" ILIKE $2 ORDER BY "levenshtein_dist" LIMIT 50"#) #expect(app.db.binds(b) == ["a", "%a%"]) @@ -195,7 +195,7 @@ extension AllTests.SearchTests { } @Test func authorMatchQuery_multiple_term() async throws { - try await withApp { app in + try await withSPIApp { app in let b = Search.authorMatchQueryBuilder(on: app.db, terms: ["a", "b"]) #expect(app.db.renderSQL(b) == #"SELECT DISTINCT 'author' AS "match_type", NULL AS "keyword", NULL::UUID AS "package_id", NULL AS "package_name", NULL AS "repo_name", "repo_owner", NULL::INT AS "score", NULL AS "summary", NULL::INT AS "stars", NULL AS "license", NULL::TIMESTAMP AS "last_commit_date", NULL::TIMESTAMP AS "last_activity_at", NULL::TEXT[] AS "keywords", NULL::BOOL AS "has_docs", LEVENSHTEIN("repo_owner", $1) AS "levenshtein_dist", NULL::BOOL AS "has_exact_word_matches" FROM "search" WHERE "repo_owner" ILIKE $2 ORDER BY "levenshtein_dist" LIMIT 50"#) #expect(app.db.binds(b) == ["a b", "%a b%"]) @@ -204,7 +204,7 @@ extension AllTests.SearchTests { @Test func query_sql() async throws { // Test to confirm shape of rendered search SQL - try await withApp { app in + try await withSPIApp { app in // MUT let query = try #require(Search.query(app.db, ["test"], page: 1, pageSize: 20)) // validate @@ -217,7 +217,7 @@ extension AllTests.SearchTests { @Test func fetch_single() async throws { // Test search with a single term - try await withApp { app in + try await withSPIApp { app in // setup let p1 = try await savePackage(on: app.db, id: .id1, "1") let p2 = try await savePackage(on: app.db, id: .id2, "2") @@ -262,7 +262,7 @@ extension AllTests.SearchTests { @Test func fetch_multiple() async throws { // Test search with multiple terms ("and") - try await withApp { app in + try await withSPIApp { app in // setup let p1 = try await savePackage(on: app.db, id: .id1, "1") let p2 = try await savePackage(on: app.db, id: .id2, "2") @@ -309,7 +309,7 @@ extension AllTests.SearchTests { @Test func fetch_distinct() async throws { // Ensure we de-duplicate results - try await withApp { app in + try await withSPIApp { app in // setup let p = Package.init(id: .id0, url: "bar".url) try await p.save(on: app.db) @@ -334,7 +334,7 @@ extension AllTests.SearchTests { @Test func quoting() async throws { // Test searching for a `'` - try await withApp { app in + try await withSPIApp { app in // setup let p1 = try await savePackage(on: app.db, id: .id1, "1") let p2 = try await savePackage(on: app.db, id: .id2, "2") @@ -382,7 +382,7 @@ extension AllTests.SearchTests { @Test func search_pagination() async throws { // setup - try await withApp { app in + try await withSPIApp { app in let packages = (0..<9).map { idx in Package(url: "\(idx)".url, score: 15 - idx) } @@ -428,7 +428,7 @@ extension AllTests.SearchTests { @Test func search_pagination_with_author_keyword_results() async throws { // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/1198 - try await withApp { app in + try await withSPIApp { app in // setup let packages = (0..<9).map { idx in Package(url: "\(idx)".url, score: 15 - idx) @@ -468,7 +468,7 @@ extension AllTests.SearchTests { @Test func search_pagination_invalid_input() async throws { // Test invalid pagination inputs - try await withApp { app in + try await withSPIApp { app in // setup let packages = (0..<9).map { idx in Package(url: "\(idx)".url, score: 15 - idx) @@ -504,7 +504,7 @@ extension AllTests.SearchTests { } @Test func order_by_score() async throws { - try await withApp { app in + try await withSPIApp { app in // setup for idx in (0..<10).shuffled() { let p = Package(id: UUID(), url: "\(idx)".url, score: idx) @@ -529,7 +529,7 @@ extension AllTests.SearchTests { @Test func exact_name_match() async throws { // Ensure exact name matches are boosted - try await withApp { app in + try await withSPIApp { app in // setup // We have three packages that all match in some way: // 1: exact package name match - we want this one to be at the top @@ -571,7 +571,7 @@ extension AllTests.SearchTests { @Test func exact_name_match_whitespace() async throws { // Ensure exact name matches are boosted, for package name with whitespace - try await withApp { app in + try await withSPIApp { app in // setup // We have three packages that all match in some way: // 1: exact package name match - we want this one to be at the top @@ -614,7 +614,7 @@ extension AllTests.SearchTests { @Test func exact_name_null_packageName() async throws { // Ensure null packageName value aren't boosted // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2072 - try await withApp { app in + try await withSPIApp { app in // setup // We have three packages that match the search term "bar" via their summary. // The third package has no package name. This test ensure it's not boosted @@ -655,7 +655,7 @@ extension AllTests.SearchTests { @Test func exclude_null_fields() async throws { // Ensure excluding results with NULL fields - try await withApp { app in + try await withSPIApp { app in // setup: // Packages that all match but each having one NULL for a required field let p1 = Package(id: UUID(), url: "1", score: 10) @@ -687,7 +687,7 @@ extension AllTests.SearchTests { @Test func include_null_package_name() async throws { // Ensure that packages that somehow have a NULL package name do *not* get excluded from search results. - try await withApp { app in + try await withSPIApp { app in let p1 = Package(id: .id0, url: "1", score: 10) try await p1.save(on: app.db) @@ -717,7 +717,7 @@ extension AllTests.SearchTests { @Test func exact_word_match() async throws { // Ensure exact word matches are boosted // See also https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2072 - try await withApp { app in + try await withSPIApp { app in // setup // We have three packages that all match the search term "ping". This test // ensures the one with the whole word match is boosted to the front @@ -763,7 +763,7 @@ extension AllTests.SearchTests { // We have two packages that both match the search term "syntax". This test // ensures the one where the match is only in the repository name gets still // ranked first due to its higher score. - try await withApp { app in + try await withSPIApp { app in let p1 = Package(id: UUID(), url: "foo/bar", score: 10) let p2 = Package(id: UUID(), url: "foo/swift-syntax", score: 20) try await [p1, p2].save(on: app.db) @@ -806,7 +806,7 @@ extension AllTests.SearchTests { // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/1402 // Ensure we don't raise a 500 for certain characters // "server: invalid regular expression: quantifier operand invalid" - try await withApp { app in + try await withSPIApp { app in do { // MUT let res = try await Search.fetch(app.db, ["*"], page: 1, pageSize: 20) @@ -830,7 +830,7 @@ extension AllTests.SearchTests { // setup // p1: decoy // p2: match - try await withApp { app in + try await withSPIApp { app in let pkgs = (0..<2).map { Package(id: UUID(), url: "\($0)".url) } try await pkgs.save(on: app.db) try await [ @@ -862,7 +862,7 @@ extension AllTests.SearchTests { // setup // p1: decoy // p2: match - try await withApp { app in + try await withSPIApp { app in let pkgs = (0..<4).map { Package(id: UUID(), url: "\($0)".url, score: $0) } try await pkgs.save(on: app.db) let keywords = [ @@ -899,7 +899,7 @@ extension AllTests.SearchTests { // setup // p1: decoy // p2: match - try await withApp { app in + try await withSPIApp { app in let pkgs = (0..<4).map { Package(id: UUID(), url: "\($0)".url, score: $0) } @@ -935,7 +935,7 @@ extension AllTests.SearchTests { // setup // p1: decoy // p2: match - try await withApp { app in + try await withSPIApp { app in let p1 = Package(id: .id1, url: "1", score: 10) let p2 = Package(id: .id2, url: "2", score: 20) try await [p1, p2].save(on: app.db) @@ -982,7 +982,7 @@ extension AllTests.SearchTests { // setup // p1: decoy // p2: match - try await withApp { app in + try await withSPIApp { app in let p1 = Package(id: .id1, url: "1", score: 10) let p2 = Package(id: .id2, url: "2", score: 20) try await [p1, p2].save(on: app.db) @@ -1015,7 +1015,7 @@ extension AllTests.SearchTests { } @Test func search_withoutTerms() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(id: .id1, url: "1", score: 10) let p2 = Package(id: .id2, url: "2", score: 20) @@ -1048,7 +1048,7 @@ extension AllTests.SearchTests { } @Test func search_withFilter_stars() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(id: .id1, url: "1", score: 10) let p2 = Package(id: .id2, url: "2", score: 20) @@ -1104,7 +1104,7 @@ extension AllTests.SearchTests { } @Test func onlyPackageResults_whenFiltersApplied() async throws { - try await withApp { app in + try await withSPIApp { app in do { // with filter let query = try #require(Search.query(app.db, ["a", "stars:500"], page: 1, pageSize: 5)) let sql = app.db.renderSQL(query) @@ -1124,7 +1124,7 @@ extension AllTests.SearchTests { } @Test func authorSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1166,7 +1166,7 @@ extension AllTests.SearchTests { } @Test func keywordSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1210,7 +1210,7 @@ extension AllTests.SearchTests { } @Test func lastActivitySearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1254,7 +1254,7 @@ extension AllTests.SearchTests { } @Test func lastCommitSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1298,7 +1298,7 @@ extension AllTests.SearchTests { } @Test func licenseSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1350,7 +1350,7 @@ extension AllTests.SearchTests { } @Test func platformSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1392,7 +1392,7 @@ extension AllTests.SearchTests { } @Test func starsSearchFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1435,7 +1435,7 @@ extension AllTests.SearchTests { } @Test func productTypeFilter() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { let p1 = Package.init(id: .id0, url: "1".url) @@ -1489,7 +1489,7 @@ extension AllTests.SearchTests { } @Test func productTypeFilter_macro() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { let p1 = Package.init(id: .id0, url: "1".url) @@ -1544,7 +1544,7 @@ extension AllTests.SearchTests { @Test func SearchFilter_error() async throws { // Test error handling in case of an invalid filter - try await withApp { app in + try await withSPIApp { app in // Setup let p1 = Package(url: "1", platformCompatibility: [.iOS]) let p2 = Package(url: "2", platformCompatibility: [.macOS]) @@ -1578,7 +1578,7 @@ extension AllTests.SearchTests { @Test func hasDocs_external_docs() async throws { // Ensure external docs as listed as having docs // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2702 - try await withApp { app in + try await withSPIApp { app in let pkg = Package(url: "1") try await pkg.save(on: app.db) try await Repository(package: pkg, diff --git a/Tests/AppTests/SitemapTests.swift b/Tests/AppTests/SitemapTests.swift index 5bed26dd8..635b529b4 100644 --- a/Tests/AppTests/SitemapTests.swift +++ b/Tests/AppTests/SitemapTests.swift @@ -27,7 +27,7 @@ extension AllTests.SitemapTests { @Test(.dependency(\.date.now, .t0)) func siteMapIndex() async throws { - try await withApp { app in + try await withSPIApp { app in // Setup let packages = (0..<3).map { Package(url: "\($0)".url) } try await packages.save(on: app.db) @@ -56,9 +56,9 @@ extension AllTests.SitemapTests { $0.environment.current = { .production } $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp(environment: .production) { app in + try await withSPIApp(environment: .production) { app in // MUT - try await app.test(.GET, "/sitemap.xml") { res async in + try await app.testing().test(.GET, "/sitemap.xml") { res async in // Validation #expect(res.status == .ok) } @@ -71,9 +71,9 @@ extension AllTests.SitemapTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp(environment: .development) { app in + try await withSPIApp(environment: .development) { app in // MUT - try await app.test(.GET, "/sitemap.xml") { res async in + try await app.testing().test(.GET, "/sitemap.xml") { res async in // Validation #expect(res.status == .notFound) } @@ -82,7 +82,7 @@ extension AllTests.SitemapTests { } @Test func siteMapStaticPages() async throws { - try await withApp { app in + try await withSPIApp { app in let req = Request(application: app, on: app.eventLoopGroup.next()) // MUT @@ -100,9 +100,9 @@ extension AllTests.SitemapTests { $0.environment.current = { .production } $0.httpClient.postPlausibleEvent = App.HTTPClient.noop } operation: { - try await withApp(environment: .production) { app in + try await withSPIApp(environment: .production) { app in // MUT - try await app.test(.GET, "/sitemap-static-pages.xml") { res async in + try await app.testing().test(.GET, "/sitemap-static-pages.xml") { res async in // Validation #expect(res.status == .ok) } @@ -115,9 +115,9 @@ extension AllTests.SitemapTests { try await withDependencies { $0.environment.dbId = { nil } } operation: { - try await withApp(environment: .development) { app in + try await withSPIApp(environment: .development) { app in // MUT - try await app.test(.GET, "/sitemap-static-pages.xml") { res async in + try await app.testing().test(.GET, "/sitemap-static-pages.xml") { res async in // Validation #expect(res.status == .notFound) } @@ -139,7 +139,7 @@ extension AllTests.SitemapTests { """) } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let package = Package(url: URL(stringLiteral: "https://example.com/owner/repo0")) try await package.save(on: app.db) @@ -184,7 +184,7 @@ extension AllTests.SitemapTests { """) } } operation: { - try await withApp { app in + try await withSPIApp { app in // setup let package = Package(url: URL(stringLiteral: "https://example.com/owner/repo0")) try await package.save(on: app.db) @@ -214,7 +214,7 @@ extension AllTests.SitemapTests { } @Test func siteMapForPackage_noDocs() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let package = Package(url: URL(stringLiteral: "https://example.com/owner/repo0")) try await package.save(on: app.db) @@ -239,7 +239,7 @@ extension AllTests.SitemapTests { } @Test func siteMapForPackage_withDocs() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let package = Package(url: URL(stringLiteral: "https://example.com/owner/repo0")) try await package.save(on: app.db) diff --git a/Tests/AppTests/SocialTests.swift b/Tests/AppTests/SocialTests.swift index 9bc68a4bd..ac61f0078 100644 --- a/Tests/AppTests/SocialTests.swift +++ b/Tests/AppTests/SocialTests.swift @@ -121,7 +121,7 @@ extension AllTests.SocialTests { } @Test func firehoseMessage_new_version() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1".asGithubUrl.url, status: .ok) try await pkg.save(on: app.db) @@ -148,7 +148,7 @@ extension AllTests.SocialTests { } @Test func firehoseMessage_new_package() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1".asGithubUrl.url, status: .new) try await pkg.save(on: app.db) @@ -176,7 +176,7 @@ extension AllTests.SocialTests { @Test func postToFirehose_only_release_and_preRelease() async throws { // ensure we only post about releases and pre-releases - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1".asGithubUrl.url) try await pkg.save(on: app.db) @@ -214,7 +214,7 @@ extension AllTests.SocialTests { @Test func postToFirehose_only_latest() async throws { // ensure we only post about latest versions - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1".asGithubUrl.url, status: .ok) try await pkg.save(on: app.db) diff --git a/Tests/AppTests/StatsTests.swift b/Tests/AppTests/StatsTests.swift index a72758d9a..8fec48c64 100644 --- a/Tests/AppTests/StatsTests.swift +++ b/Tests/AppTests/StatsTests.swift @@ -22,7 +22,7 @@ import Testing extension AllTests.StatsTests { @Test func fetch() async throws { - try await withApp { app in + try await withSPIApp { app in // setup do { let pkg = Package(id: UUID(), url: "1") diff --git a/Tests/AppTests/TargetTests.swift b/Tests/AppTests/TargetTests.swift index 88820ad2f..714bb0b9a 100644 --- a/Tests/AppTests/TargetTests.swift +++ b/Tests/AppTests/TargetTests.swift @@ -22,7 +22,7 @@ import Vapor extension AllTests.TargetTests { @Test func save() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let v = Version() v.commit = "" // required field @@ -45,7 +45,7 @@ extension AllTests.TargetTests { } @Test func delete_cascade() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let v = Version() v.commit = "" // required field diff --git a/Tests/AppTests/VersionDiffTests.swift b/Tests/AppTests/VersionDiffTests.swift index 3fdb4a5f6..3ab60fd81 100644 --- a/Tests/AppTests/VersionDiffTests.swift +++ b/Tests/AppTests/VersionDiffTests.swift @@ -132,7 +132,7 @@ extension AllTests.VersionDiffTests { @Test func Version_diff_1() async throws { // Test [Version] based diff (higher level interface) // Just run an integration scenario, the details are covered in the test above - try await withApp { app in + try await withSPIApp { app in // Branch changes commit hash // setup let pkg = try await savePackage(on: app.db, "1") diff --git a/Tests/AppTests/VersionTests.swift b/Tests/AppTests/VersionTests.swift index da7761ac4..d1be59314 100644 --- a/Tests/AppTests/VersionTests.swift +++ b/Tests/AppTests/VersionTests.swift @@ -23,7 +23,7 @@ import Testing extension AllTests.VersionTests { @Test func save() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url) let v = try Version(package: pkg) @@ -68,7 +68,7 @@ extension AllTests.VersionTests { } @Test func save_not_null_constraints() async throws { - try await withApp { app in + try await withSPIApp { app in do { // commit unset let v = Version() v.commitDate = .distantPast @@ -108,7 +108,7 @@ extension AllTests.VersionTests { // Test for // invalid field: swift_versions type: Array error: Unexpected data type: JSONB[]. Expected array. // Fix is .sql(.default("{}")) - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1") let v = try Version(package: pkg) @@ -123,7 +123,7 @@ extension AllTests.VersionTests { @Test func delete_cascade() async throws { // delete package must delete version - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(id: UUID(), url: "1") let ver = try Version(id: UUID(), package: pkg) @@ -143,7 +143,7 @@ extension AllTests.VersionTests { } @Test func isBranch() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url) let v1 = try Version(package: pkg, reference: .branch("main")) @@ -156,7 +156,7 @@ extension AllTests.VersionTests { } @Test func latestBranchVersion() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url) let vid = UUID() @@ -184,7 +184,7 @@ extension AllTests.VersionTests { } @Test func defaults() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url) let v = try Version(package: pkg) diff --git a/Tests/AppTests/ViewUtilsTests.swift b/Tests/AppTests/ViewUtilsTests.swift index 8152b8d17..b74449d82 100644 --- a/Tests/AppTests/ViewUtilsTests.swift +++ b/Tests/AppTests/ViewUtilsTests.swift @@ -35,7 +35,7 @@ extension AllTests.ViewUtilsTests { } @Test func test_makeLink() async throws { - try await withApp { app in + try await withSPIApp { app in // setup let pkg = Package(url: "1") try await pkg.save(on: app.db)