-
-
Notifications
You must be signed in to change notification settings - Fork 50
Pull forward test changes #3727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } | ||
|
||
|
||
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 { } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,20 +21,23 @@ import Testing | |
import Vapor | ||
|
||
|
||
extension AllTests { | ||
@Suite struct AnalyzeErrorTests { | ||
let socialPosts = LockIsolated<[String]>([]) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the nested |
||
|
||
|
||
// 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 { } | ||
|
||
|
@@ -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"): | ||
|
@@ -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() | ||
|
@@ -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"): | ||
|
@@ -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 | ||
|
@@ -156,6 +166,7 @@ import Vapor | |
} | ||
return true | ||
} | ||
$0.logger.set(to: capturingLogger) | ||
} operation: { | ||
// MUT | ||
try await Analyze.analyze(client: app.client, | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
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 toAllAppTests
after all is done. It'd be too much rebasing for little gain at this point.