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
10 changes: 5 additions & 5 deletions Tests/AppTests/API+PackageController+GetRoute+ModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
func test_init_no_packageName() async throws {
// Tests behaviour when we're lacking data
// setup package without package name
let pkg = try savePackage(on: app.db, "1".url)
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,
Expand All @@ -50,7 +50,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
}

func test_init_packageIdentity() async throws {
let pkg = try savePackage(on: app.db, URL(string: "https://github.com/foo/swift-bar.git")!)
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"))
try await version.save(on: app.db)
Expand All @@ -71,7 +71,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
}

func test_init_generated_documentation() async throws {
let pkg = try savePackage(on: app.db, "1".url)
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"))
version.docArchives = [.init(name: "archive1", title: "Archive One")]
Expand All @@ -93,7 +93,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {
}

func test_init_external_documentation() async throws {
let pkg = try savePackage(on: app.db, "1".url)
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"))
version.spiManifest = try .init(yml: """
Expand Down Expand Up @@ -454,7 +454,7 @@ class API_PackageController_GetRoute_ModelTests: SnapshotTestCase {

func test_languagePlatformInfo() async throws {
// setup
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg,
defaultBranch: "default",
name: "bar",
Expand Down
4 changes: 2 additions & 2 deletions Tests/AppTests/API+PackageController+GetRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class API_PackageController_GetRouteTests: AppTestCase {

func test_releaseInfo() async throws {
// setup
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg,
defaultBranch: "default",
name: "bar",
Expand Down Expand Up @@ -69,7 +69,7 @@ class API_PackageController_GetRouteTests: AppTestCase {
func test_releaseInfo_exclude_non_latest() async throws {
// Test to ensure that we don't include versions with `latest IS NULL`
// setup
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg,
defaultBranch: "default",
name: "bar",
Expand Down
12 changes: 6 additions & 6 deletions Tests/AppTests/API+PackageControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class API_PackageControllerTests: AppTestCase {
Current.date = {
Date.init(timeIntervalSince1970: 1608000588) // Dec 15, 2020
}
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg,
commitCount: 1433,
defaultBranch: "default",
Expand Down Expand Up @@ -65,7 +65,7 @@ class API_PackageControllerTests: AppTestCase {
Current.date = {
Date.init(timeIntervalSince1970: 1608000588) // Dec 15, 2020
}
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg,
commitCount: 1433,
defaultBranch: "default",
Expand Down Expand Up @@ -135,7 +135,7 @@ class API_PackageControllerTests: AppTestCase {

func test_ProductCount_query() async throws {
// setup
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg,
defaultBranch: "main",
name: "bar",
Expand Down Expand Up @@ -282,7 +282,7 @@ class API_PackageControllerTests: AppTestCase {
func test_BuildInfo_query() async throws {
// setup
do {
let pkg = try savePackage(on: app.db, "1".url)
let pkg = try await savePackage(on: app.db, "1".url)
try await Repository(package: pkg,
defaultBranch: "main",
name: "bar",
Expand All @@ -304,7 +304,7 @@ class API_PackageControllerTests: AppTestCase {
}
}
do { // unrelated package and build
let pkg = try savePackage(on: app.db, "2".url)
let pkg = try await savePackage(on: app.db, "2".url)
try await Repository(package: pkg,
defaultBranch: "main",
name: "bar2",
Expand Down Expand Up @@ -348,7 +348,7 @@ class API_PackageControllerTests: AppTestCase {
func test_GetRoute_query() async throws {
// ensure GetRoute.query is wired up correctly (detailed tests are elsewhere)
// setup
let pkg = try savePackage(on: app.db, "1")
let pkg = try await savePackage(on: app.db, "1")
try await Repository(package: pkg, name: "bar", owner: "foo")
.save(on: app.db)
try await Version(package: pkg, latest: .defaultBranch).save(on: app.db)
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 @@ -21,7 +21,7 @@ final class API_DependencyControllerTests: AppTestCase {

func test_query() async throws {
// setup
let pkg = try savePackage(on: app.db, id: .id0, "http://github.com/foo/bar")
let pkg = try await savePackage(on: app.db, id: .id0, "http://github.com/foo/bar")
try await Repository(package: pkg,
defaultBranch: "default",
name: "bar",
Expand Down
39 changes: 20 additions & 19 deletions Tests/AppTests/AnalyzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AnalyzerTests: AppTestCase {
// expected shell commands for the happy path.)
// setup
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
let pkgs = try savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
let pkgs = try await savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
try await Repository(package: pkgs[0],
defaultBranch: "main",
name: "1",
Expand Down Expand Up @@ -300,7 +300,7 @@ class AnalyzerTests: AppTestCase {
// Ensure a package that fails analysis goes back to ingesting and isn't stuck in an analysis loop
// setup
do {
let pkg = try savePackage(on: app.db, "https://github.com/foo/1", processingStage: .ingestion)
let pkg = try await savePackage(on: app.db, "https://github.com/foo/1", processingStage: .ingestion)
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
}

Expand Down Expand Up @@ -337,7 +337,7 @@ class AnalyzerTests: AppTestCase {
// Ensure packages record success/error status
// setup
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
let pkgs = try savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
let pkgs = try await savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
for p in pkgs {
try await Repository(package: p, defaultBranch: "main").save(on: app.db)
}
Expand Down Expand Up @@ -383,7 +383,7 @@ class AnalyzerTests: AppTestCase {
// Test to ensure exceptions don't interrupt processing
// setup
let urls = ["https://github.com/foo/1", "https://github.com/foo/2"]
let pkgs = try savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
let pkgs = try await savePackages(on: app.db, urls.asURLs, processingStage: .ingestion)
for p in pkgs {
try await Repository(package: p, defaultBranch: "main").save(on: app.db)
}
Expand Down Expand Up @@ -468,7 +468,7 @@ class AnalyzerTests: AppTestCase {
@MainActor
func test_refreshCheckout() async throws {
// setup
let pkg = try savePackage(on: app.db, "1".asGithubUrl.url)
let pkg = try await savePackage(on: app.db, "1".asGithubUrl.url)
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
Current.fileManager.fileExists = { @Sendable _ in true }
let commands = QueueIsolated<[String]>([])
Expand Down Expand Up @@ -631,20 +631,20 @@ class AnalyzerTests: AppTestCase {
.mock(description: "rel 2.3.0", publishedAt: 4, tagName: "2.3.0", url: "some url"),
.mock(description: nil, tagName: "2.4.0")
]).save(on: app.db)
let versions: [Version] = try [
let versions: [Version] = try await [
(Date(timeIntervalSince1970: 0), Reference.tag(1, 2, 3)),
(Date(timeIntervalSince1970: 1), Reference.tag(2, 0, 0)),
(Date(timeIntervalSince1970: 2), Reference.tag(2, 1, 0)),
(Date(timeIntervalSince1970: 3), Reference.tag(2, 2, 0)),
(Date(timeIntervalSince1970: 4), Reference.tag(2, 3, 0)),
(Date(timeIntervalSince1970: 5), Reference.tag(2, 4, 0)),
(Date(timeIntervalSince1970: 6), Reference.branch("main")),
].map { date, ref in
].mapAsync { date, ref in
let v = try Version(id: UUID(),
package: pkg,
commitDate: date,
reference: ref)
try v.save(on: app.db).wait()
try await v.save(on: app.db)
return v
}
let jpr = try await Package.fetchCandidate(app.db, id: .id0)
Expand Down Expand Up @@ -729,7 +729,7 @@ class AnalyzerTests: AppTestCase {
}
return ""
}
let pkg = try savePackage(on: app.db, "https://github.com/foo/1")
let pkg = try await savePackage(on: app.db, "https://github.com/foo/1")
try await Repository(package: pkg, name: "1", owner: "foo").save(on: app.db)
let version = try Version(id: UUID(), package: pkg, reference: .tag(.init(0, 4, 2)))
try await version.save(on: app.db)
Expand Down Expand Up @@ -829,7 +829,7 @@ class AnalyzerTests: AppTestCase {

func test_updatePackages() async throws {
// setup
let packages = try savePackages(on: app.db, ["1", "2"].asURLs)
let packages = try await savePackages(on: app.db, ["1", "2"].asURLs)
.map(Joined<Package, Repository>.init(model:))
let results: [Result<Joined<Package, Repository>, Error>] = [
// feed in one error to see it passed through
Expand Down Expand Up @@ -894,9 +894,9 @@ class AnalyzerTests: AppTestCase {
}
return ""
}
let pkgs = try savePackages(on: app.db, ["1", "2"].asGithubUrls.asURLs, processingStage: .ingestion)
try pkgs.forEach {
try Repository(package: $0, defaultBranch: "main").save(on: app.db).wait()
let pkgs = try await savePackages(on: app.db, ["1", "2"].asGithubUrls.asURLs, processingStage: .ingestion)
for pkg in pkgs {
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
}

// MUT
Expand All @@ -907,16 +907,17 @@ class AnalyzerTests: AppTestCase {
// validation
// 1 version for the default branch + 2 for the tags each = 6 versions
// 2 products per version = 12 products
XCTAssertEqual(try Version.query(on: app.db).count().wait(), 6)
XCTAssertEqual(try Product.query(on: app.db).count().wait(), 12)
let db = app.db
try await XCTAssertEqualAsync(try await Version.query(on: db).count(), 6)
try await XCTAssertEqualAsync(try await Product.query(on: db).count(), 12)
}

@MainActor
func test_issue_70() async throws {
// Certain git commands fail when index.lock exists
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/70
// setup
try savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
try await savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
let pkgs = try await Package.fetchCandidates(app.db, for: .analysis, limit: 10)

let checkoutDir = Current.fileManager.checkoutsDirectory()
Expand Down Expand Up @@ -950,7 +951,7 @@ class AnalyzerTests: AppTestCase {
// git checkout can still fail despite git reset --hard + git clean
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/498
// setup
try savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
try await savePackage(on: app.db, "1".asGithubUrl.url, processingStage: .ingestion)
let pkgs = try await Package.fetchCandidates(app.db, for: .analysis, limit: 10)

let checkoutDir = Current.fileManager.checkoutsDirectory()
Expand Down Expand Up @@ -1106,7 +1107,7 @@ class AnalyzerTests: AppTestCase {
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/693
// setup
do {
let pkg = try savePackage(on: app.db, id: .id0, "1".asGithubUrl.url)
let pkg = try await savePackage(on: app.db, id: .id0, "1".asGithubUrl.url)
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
}
let pkg = try await Package.fetchCandidate(app.db, id: .id0)
Expand Down Expand Up @@ -1455,7 +1456,7 @@ class AnalyzerTests: AppTestCase {
// Ensure we preserve dependency counts from previous default branch version
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2873
// setup
let pkg = try await savePackageAsync(on: app.db, id: .id0, "https://github.com/foo/1".url, processingStage: .ingestion)
let pkg = try await savePackage(on: app.db, id: .id0, "https://github.com/foo/1".url, processingStage: .ingestion)
try await Repository(package: pkg,
defaultBranch: "main",
name: "1",
Expand Down
Loading