Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Testing
import Vapor


@Suite struct API_PackageController_GetRoute_ModelTests {
extension AllTests.API_PackageController_GetRoute_ModelTests {
typealias PackageResult = PackageController.PackageResult

@Test func init_no_packageName() async throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/API+PackageController+GetRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Testing


@Suite struct API_PackageController_GetRouteTests {
extension AllTests.API_PackageController_GetRouteTests {

typealias PackageResult = PackageController.PackageResult

Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/API+PackageControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Testing
import Vapor


@Suite struct API_PackageControllerTests {
extension AllTests.API_PackageControllerTests {

typealias BuildDetails = (reference: Reference, platform: Build.Platform, swiftVersion: SwiftVersion, status: Build.Status)

Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/API+PackageSchemaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
import Testing


@Suite struct API_PackageSchemaTests {
extension AllTests.API_PackageSchemaTests {

@Test func PackageSchema_init() throws {
let schema = API.PackageSchema(
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/API_DependencyControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Testing
import Vapor


@Suite struct API_DependencyControllerTests {
extension AllTests.API_DependencyControllerTests {

@Test func query() async throws {
try await withApp { app in
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/AlertingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Dependencies
import Testing


@Suite struct AlertingTests {
extension AllTests.AlertingTests {

@Test func validatePlatformsPresent() throws {
let all = Build.Platform.allCases.map {
Expand Down
121 changes: 121 additions & 0 deletions Tests/AppTests/AllTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Testing
import Dependencies


@Suite(.dependency(\.date.now, .t0)) struct AllTests { }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to be able to bring up a number of test dbs at the start of the app tests and tear them down afterwards, all the tests need to belong to a single suite. The easiest way to do this is to nest all existing tests under a new top level suite.

This suite will then later gain the trait

- @Suite(.dependency(\.date.now, .t0)) struct AllTests { }
+ @Suite(.setupDatabasePool, .dependency(\.date.now, .t0)) struct AllTests { }

NB: AllTests isn't an ideal name I've just realised, because we have a couple of other test suites that aren't nested. I'll rename this to AllAppTests after all is done. It'd be too much rebasing for little gain at this point.



extension AllTests {
@Suite struct AlertingTests { }
@Suite struct AnalyzerTests { }
@Suite struct AnalyzerVersionThrottlingTests { }
@Suite struct API_DependencyControllerTests { }
@Suite struct API_PackageController_GetRoute_ModelTests { }
@Suite struct API_PackageController_GetRouteTests { }
@Suite struct API_PackageControllerTests { }
@Suite struct API_PackageSchemaTests { }
@Suite struct ApiTests { }
@Suite struct AppEnvironmentTests { }
@Suite struct AppTests { }
@Suite struct ArrayExtensionTests { }
@Suite struct ArrayStringExtensionTests { }
@Suite struct ArrayVersionExtensionTests { }
@Suite struct AuthorControllerTests { }
@Suite struct BadgeTests { }
@Suite struct BlogActionsModelTests { }
@Suite struct BuildIndexModelTests { }
@Suite struct BuildMonitorControllerTests { }
@Suite struct BuildMonitorIndexModelTests { }
@Suite struct BuildResultTests { }
@Suite struct BuildShowModelTests { }
@Suite struct BuildTests { }
@Suite struct BuildTriggerTests { }
@Suite struct CustomCollectionControllerTests { }
@Suite struct CustomCollectionTests { }
@Suite struct DefaultStringInterpolationTests { }
@Suite struct DocUploadTests { }
@Suite struct DocumentationPageProcessorTests { }
@Suite struct DocumentationTargetTests { }
@Suite struct EmojiTests { }
@Suite struct ErrorMiddlewareTests { }
@Suite struct ErrorPageModelTests { }
@Suite struct ErrorReportingTests { }
@Suite struct FundingLinkTests { }
@Suite struct GitLiveTests { }
@Suite struct GitTests { }
@Suite struct GithubTests { }
@Suite struct GitlabBuilderTests { }
@Suite struct LiveGitlabBuilderTests { }
@Suite struct HomeIndexModelTests { }
@Suite struct IngestionTests { }
@Suite struct IntExtTests { }
@Suite struct Joined3Tests { }
@Suite struct JoinedQueryBuilderTests { }
@Suite struct JoinedTests { }
@Suite struct KeywordControllerTests { }
@Suite struct LicenseTests { }
@Suite struct LiveTests { }
@Suite struct MaintainerInfoIndexModelTests { }
@Suite struct MaintainerInfoIndexViewTests { }
@Suite struct ManifestTests { }
@Suite struct MastodonTests { }
@Suite struct MetricsTests { }
@Suite struct MiscTests { }
@Suite struct PackageCollectionControllerTests { }
@Suite struct PackageCollectionTests { }
@Suite struct PackageContributorsTests { }
@Suite struct PackageController_BuildsRoute_BuildInfoTests { }
@Suite struct PackageController_BuildsRouteTests { }
@Suite struct PackageController_routesTests { }
@Suite struct PackageInfoTests { }
@Suite struct PackageReadmeModelTests { }
@Suite struct PackageReleasesModelTests { }
@Suite struct PackageResultTests { }
@Suite struct PackageTests { }
@Suite struct PipelineTests { }
@Suite struct PlausibleTests { }
@Suite struct ProductTests { }
@Suite struct QueryPlanTests { }
@Suite struct RSSTests { }
@Suite struct ReAnalyzeVersionsTests { }
@Suite struct RecentViewsTests { }
@Suite struct ReconcilerTests { }
@Suite struct ReferenceTests { }
@Suite struct RepositoryTests { }
@Suite struct ResourceReloadIdentifierTests { }
@Suite struct RoutesTests { }
@Suite struct S3StoreExtensionTests { }
@Suite struct SQLKitExtensionTests { }
@Suite struct ScoreTests { }
@Suite struct SearchFilterTests { }
@Suite struct SearchShowModelAppTests { }
@Suite struct SearchShowModelTests { }
@Suite struct SearchTests { }
@Suite struct ShellOutCommandExtensionTests { }
@Suite struct SignificantBuildsTests { }
@Suite struct SiteURLTests { }
@Suite struct SitemapTests { }
@Suite struct SocialTests { }
@Suite struct StatsTests { }
@Suite struct StringExtTests { }
@Suite struct SwiftVersionTests { }
@Suite struct TargetTests { }
@Suite struct ValidateSPIManifestControllerTests { }
@Suite struct VersionDiffTests { }
@Suite struct VersionTests { }
@Suite struct ViewUtilsTests { }
}
37 changes: 24 additions & 13 deletions Tests/AppTests/AnalyzeErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ import Testing
import Vapor


extension AllTests {
@Suite struct AnalyzeErrorTests {
let socialPosts = LockIsolated<[String]>([])
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the nested @Suites can't be defined in AllTests.swift, because they hold properties (which can't be declared in extensions).



// Test analysis error handling.
//
// This suite of tests ensures that errors in batch analysis do not impact processing
// of later packages.
//
// We analyze two packages where the first package is set up to encounter
// various error states and ensure the second package is successfully processed.
@Suite struct AnalyzeErrorTests {

let badPackageID: Package.Id = .id0
let goodPackageID: Package.Id = .id1

let capturingLogger = CapturingLogger()
let socialPosts = LockIsolated<[String]>([])
extension AllTests.AnalyzeErrorTests {
var badPackageID: Package.Id { .id0 }
var goodPackageID: Package.Id { .id1 }

struct SimulatedError: Error { }

Expand All @@ -58,10 +61,12 @@ import Vapor
}

@Test func analyze_refreshCheckout_failed() async throws {
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
let capturingLogger = CapturingLogger()
try await withApp(setup, defaultDependencies) { app in
try await withDependencies {
$0.environment.loadSPIManifest = { _ in nil }
$0.fileManager.fileExists = { @Sendable _ in true }
$0.logger.set(to: capturingLogger)
$0.shell.run = { @Sendable cmd, path in
switch cmd {
case _ where cmd.description.contains("git clone https://github.com/foo/1"):
Expand Down Expand Up @@ -90,10 +95,12 @@ import Vapor
}

@Test func analyze_updateRepository_invalidPackageCachePath() async throws {
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
let capturingLogger = CapturingLogger()
try await withApp(setup, defaultDependencies) { app in
try await withDependencies {
$0.environment.loadSPIManifest = { _ in nil }
$0.fileManager.fileExists = { @Sendable _ in true }
$0.logger.set(to: capturingLogger)
} operation: {
// setup
let pkg = try await Package.find(badPackageID, on: app.db).unwrap()
Expand All @@ -118,10 +125,12 @@ import Vapor
}

@Test func analyze_getPackageInfo_gitCheckout_error() async throws {
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
let capturingLogger = CapturingLogger()
try await withApp(setup, defaultDependencies) { app in
try await withDependencies {
$0.environment.loadSPIManifest = { _ in nil }
$0.fileManager.fileExists = { @Sendable _ in true }
$0.logger.set(to: capturingLogger)
$0.shell.run = { @Sendable cmd, path in
switch cmd {
case .gitCheckout(branch: "main", quiet: true) where path.hasSuffix("foo-1"):
Expand All @@ -147,7 +156,8 @@ import Vapor
}

@Test func analyze_dumpPackage_missing_manifest() async throws {
try await withApp(setup, defaultDependencies, logHandler: capturingLogger) { app in
let capturingLogger = CapturingLogger()
try await withApp(setup, defaultDependencies) { app in
try await withDependencies {
$0.environment.loadSPIManifest = { _ in nil }
$0.fileManager.fileExists = { @Sendable path in
Expand All @@ -156,6 +166,7 @@ import Vapor
}
return true
}
$0.logger.set(to: capturingLogger)
} operation: {
// MUT
try await Analyze.analyze(client: app.client,
Expand All @@ -176,7 +187,7 @@ import Vapor
}


extension AnalyzeErrorTests {
extension AllTests.AnalyzeErrorTests {
#if compiler(>=6.1)
#warning("Move this into a trait on @Test")
// See https://forums.swift.org/t/converting-xctest-invoketest-to-swift-testing/77692/4 for details
Expand All @@ -193,7 +204,7 @@ extension AnalyzeErrorTests {
}


extension AnalyzeErrorTests {
extension AllTests.AnalyzeErrorTests {
func defaultValidation(_ app: Application) async throws {
let versions = try await Version.query(on: app.db)
.filter(\.$package.$id == goodPackageID)
Expand Down
5 changes: 3 additions & 2 deletions Tests/AppTests/AnalyzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import Vapor
@preconcurrency import ShellOut


@Suite struct AnalyzerTests {
extension AllTests.AnalyzerTests {

@Test func analyze() async throws {
// End-to-end test, where we mock at the shell command level (i.e. we
Expand Down Expand Up @@ -1441,7 +1441,7 @@ import Vapor
// Ensure `latest` remains set in case of AppError.noValidVersions
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2571
let capturingLogger = CapturingLogger()
try await withApp(logHandler: capturingLogger) { app in
try await withApp { app in
try await withDependencies {
$0.date.now = .now
$0.fileManager.fileExists = { @Sendable _ in true }
Expand All @@ -1456,6 +1456,7 @@ import Vapor
1\tPerson 2
"""
}
$0.logger.set(to: capturingLogger)
$0.shell.run = { @Sendable _, _ in return "" }
} operation: {
let pkgId = UUID()
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/AnalyzerVersionThrottlingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Dependencies
import Testing


@Suite struct AnalyzerVersionThrottlingTests {
extension AllTests.AnalyzerVersionThrottlingTests {

@Test func throttle_keep_old() async throws {
// Test keeping old when within throttling window
Expand Down
4 changes: 2 additions & 2 deletions Tests/AppTests/ApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Testing
import XCTVapor


@Suite struct ApiTests {
extension AllTests.ApiTests {

@Test func version() async throws {
try await withApp { app in
Expand Down Expand Up @@ -1181,7 +1181,7 @@ private extension HTTPHeaders {
}


extension ApiTests {
extension AllTests.ApiTests {
struct TestEvent: Equatable {
var kind: Plausible.Event.Kind
var path: Plausible.Path
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/AppEnvironmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Testing
import Vapor


@Suite struct AppEnvironmentTests {
extension AllTests.AppEnvironmentTests {

@Test func Filemanager_checkoutsDirectory() throws {
withDependencies {
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/AppTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Vapor
import Testing


@Suite struct AppTests {
extension AllTests.AppTests {

@Test func migrations() async throws {
try await withApp { app in
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/ArrayExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SPIManifest
import Testing


@Suite struct ArrayExtensionTests {
extension AllTests.ArrayExtensionTests {

@Test func defaultBranchVersion() throws {
#expect(
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/ArrayStringExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Testing


@Suite struct ArrayStringExtensionTests {
extension AllTests.ArrayStringExtensionTests {

@Test func pluralised() throws {
#expect([String]().pluralized() == "None")
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/ArrayVersionExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SemanticVersion
import Testing


@Suite struct ArrayVersionExtensionTests {
extension AllTests.ArrayVersionExtensionTests {

@Test func Array_canonicalDocumentationTarget() async throws {
try await withApp { app in
Expand Down
2 changes: 1 addition & 1 deletion Tests/AppTests/AuthorControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Testing
import Vapor


@Suite struct AuthorControllerTests {
extension AllTests.AuthorControllerTests {

@Test func query() async throws {
try await withApp { app in
Expand Down
Loading
Loading