Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
finestructure committed Sep 25, 2023
1 parent bd769a6 commit 2971f9d
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions Tests/AppTests/AnalyzeErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ final class AnalyzeErrorTests: AppTestCase {
if checkoutDir.hasSuffix("foo-2") { return [.tag(1, 2, 3)] }
throw SetupError()
}
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { ref, checkoutDir in
if checkoutDir.hasSuffix("foo-1") { return .init(commit: "commit \(ref)", date: .t1) }
if checkoutDir.hasSuffix("foo-2") { return .init(commit: "commit \(ref)", date: .t1) }
Expand Down
17 changes: 15 additions & 2 deletions Tests/AppTests/AnalyzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class AnalyzerTests: AppTestCase {
// validation
let outDir = try checkoutDir.value.unwrap()
XCTAssert(outDir.hasSuffix("SPI-checkouts"), "unexpected checkout dir, was: \(outDir)")
XCTAssertEqual(commands.value.count, 34)
XCTAssertEqual(commands.value.count, 36)

// Snapshot for each package individually to avoid ordering issues when
// concurrent processing causes commands to interleave between packages.
Expand Down Expand Up @@ -251,6 +251,7 @@ class AnalyzerTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t2 }
Current.git.getTags = { _ in [.tag(1, 0, 0), .tag(1, 1, 1)] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { ref, _ in
// simulate the following scenario:
// - main branch has moved from commit0 -> commit3 (timestamp t3)
Expand Down Expand Up @@ -325,6 +326,7 @@ class AnalyzerTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t1 }
Current.git.getTags = { _ in [.tag(1, 0, 0)] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down Expand Up @@ -435,7 +437,7 @@ class AnalyzerTests: AppTestCase {
mode: .limit(10))

// validation (not in detail, this is just to ensure command count is as expected)
XCTAssertEqual(commands.value.count, 38, "was: \(dump(commands.value))")
XCTAssertEqual(commands.value.count, 40, "was: \(dump(commands.value))")
// 1 packages with 2 tags + 1 default branch each -> 3 versions (the other package fails)
let versionCount = try await Version.query(on: app.db).count()
XCTAssertEqual(versionCount, 3)
Expand Down Expand Up @@ -497,6 +499,7 @@ class AnalyzerTests: AppTestCase {
func test_getIncomingVersions() async throws {
// setup
Current.git.getTags = { _ in [.tag(1, 2, 3)] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { ref, _ in .init(commit: "sha-\(ref)", date: .t0) }
do {
let pkg = Package(id: .id0, url: "1".asGithubUrl.url)
Expand Down Expand Up @@ -553,6 +556,7 @@ class AnalyzerTests: AppTestCase {
func test_diffVersions() async throws {
//setup
Current.git.getTags = { _ in [.tag(1, 2, 3)] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { ref, _ in
if ref == .branch("main") { return . init(commit: "sha.main", date: .t0) }
if ref == .tag(1, 2, 3) { return .init(commit: "sha.1.2.3", date: .t1) }
Expand Down Expand Up @@ -877,6 +881,7 @@ class AnalyzerTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t1 }
Current.git.getTags = { _ in [.tag(1, 0, 0), .tag(2, 0, 0)] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down Expand Up @@ -1286,6 +1291,7 @@ class AnalyzerTests: AppTestCase {
Current.fileManager.fileExists = { _ in true }
Current.git.commitCount = { _ in 2 }
Current.git.firstCommitDate = { _ in .t0 }
Current.git.hasBranch = { _, _ in true }
Current.git.lastCommitDate = { _ in .t1 }
struct Error: Swift.Error { }
Current.git.shortlog = { _ in
Expand Down Expand Up @@ -1391,6 +1397,7 @@ class AnalyzerTests: AppTestCase {
Current.fileManager.fileExists = { _ in true }
Current.git.commitCount = { _ in 2 }
Current.git.firstCommitDate = { _ in .t0 }
Current.git.hasBranch = { _, _ in true }
Current.git.lastCommitDate = { _ in .t1 }
struct Error: Swift.Error { }
Current.git.shortlog = { _ in
Expand Down Expand Up @@ -1510,6 +1517,7 @@ private struct Command: CustomStringConvertible {
case firstCommitDate
case lastCommitDate
case getTags
case hasBranch(String)
case reset
case resetToBranch(String)
case shortlog
Expand Down Expand Up @@ -1539,6 +1547,9 @@ private struct Command: CustomStringConvertible {
self.kind = .fetch
case .gitFirstCommitDate:
self.kind = .firstCommitDate
case _ where command.description.starts(with: "git show-ref --verify --quiet refs/heads/"):
let branch = String(command.description.split(separator: "/").last!)
self.kind = .hasBranch(branch)
case .gitLastCommitDate:
self.kind = .lastCommitDate
case .gitListTags:
Expand Down Expand Up @@ -1573,6 +1584,8 @@ private struct Command: CustomStringConvertible {
return "\(path): checkout \(ref)"
case .clone(let url):
return "\(path): clone \(url)"
case let .hasBranch(branch):
return "\(path): hasBranch \(branch)"
case .resetToBranch(let branch):
return "\(path): reset to \(branch)"
case .revisionInfo(let ref):
Expand Down
2 changes: 2 additions & 0 deletions Tests/AppTests/AnalyzerVersionThrottlingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
var t: Date = .t0
Current.date = { t }
Current.git.getTags = { _ in [.branch("main")] }
Current.git.hasBranch = { _, _ in true }
let pkg = Package(url: "1".asGithubUrl.url)
try await pkg.save(on: app.db)
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
Expand Down Expand Up @@ -217,6 +218,7 @@ class AnalyzerVersionThrottlingTests: AppTestCase {
// Leaving tags out of it for simplicity - they are tested specifically
// in test_throttle_ignore_tags above.
Current.git.getTags = { _ in [] }
Current.git.hasBranch = { _, _ in true }

// Little helper to simulate minimal version reconciliation
func runVersionReconciliation() async throws -> VersionDelta {
Expand Down
1 change: 1 addition & 0 deletions Tests/AppTests/MastodonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class MastodonTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t2 }
Current.git.getTags = { _ in [tag] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down
1 change: 1 addition & 0 deletions Tests/AppTests/PackageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ final class PackageTests: AppTestCase {
Current.git.commitCount = { _ in 12 }
Current.git.firstCommitDate = { _ in Date(timeIntervalSince1970: 0) }
Current.git.getTags = { _ in [] }
Current.git.hasBranch = { _, _ in true }
Current.git.lastCommitDate = { _ in Date(timeIntervalSince1970: 1) }
Current.git.revisionInfo = { _, _ in
.init(commit: "sha",
Expand Down
1 change: 1 addition & 0 deletions Tests/AppTests/PipelineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class PipelineTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t1 }
Current.git.getTags = { _ in [] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down
2 changes: 2 additions & 0 deletions Tests/AppTests/ReAnalyzeVersionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ReAnalyzeVersionsTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t1 }
Current.git.getTags = { _ in [.tag(1, 2, 3)] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down Expand Up @@ -186,6 +187,7 @@ class ReAnalyzeVersionsTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t1 }
Current.git.getTags = { _ in [] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down
1 change: 1 addition & 0 deletions Tests/AppTests/TwitterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TwitterTests: AppTestCase {
Current.git.firstCommitDate = { _ in .t0 }
Current.git.lastCommitDate = { _ in .t2 }
Current.git.getTags = { _ in [tag] }
Current.git.hasBranch = { _, _ in true }
Current.git.revisionInfo = { _, _ in .init(commit: "sha", date: .t0) }
Current.git.shortlog = { _ in
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
14 elements
15 elements
- "./github.com-foo-1: commitCount"
- "./github.com-foo-1: firstCommitDate"
- "./github.com-foo-1: lastCommitDate"
- "./github.com-foo-1: shortlog"
- "./github.com-foo-1: hasBranch main"
- "./github.com-foo-1: getTags"
- "./github.com-foo-1: revisionInfo for main"
- "./github.com-foo-1: revisionInfo for 1.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
19 elements
20 elements
- "./github.com-foo-2: reset"
- "./github.com-foo-2: clean"
- "./github.com-foo-2: fetch"
Expand All @@ -8,6 +8,7 @@
- "./github.com-foo-2: firstCommitDate"
- "./github.com-foo-2: lastCommitDate"
- "./github.com-foo-2: shortlog"
- "./github.com-foo-2: hasBranch main"
- "./github.com-foo-2: getTags"
- "./github.com-foo-2: revisionInfo for main"
- "./github.com-foo-2: revisionInfo for 2.0.0"
Expand Down

0 comments on commit 2971f9d

Please sign in to comment.