Skip to content

Commit 10fb306

Browse files
committed
Update tests
1 parent fc32782 commit 10fb306

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

Tests/AppTests/AnalyzerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,14 @@ class AnalyzerTests: AppTestCase {
317317
$0.git.hasBranch = { @Sendable _, _ in false } // simulate analysis error via branch mismatch
318318
$0.git.lastCommitDate = { @Sendable _ in .t1 }
319319
$0.git.shortlog = { @Sendable _ in "" }
320+
$0.shell.run = { @Sendable _, _ in "" }
320321
} operation: {
321322
// setup
322323
do {
323324
let pkg = try await savePackage(on: app.db, "https://github.com/foo/1", processingStage: .ingestion)
324325
try await Repository(package: pkg, defaultBranch: "main").save(on: app.db)
325326
}
326327

327-
328328
// Ensure candidate selection is as expected
329329
let app = self.app!
330330
try await XCTAssertEqualAsync(try await Package.fetchCandidates(app.db, for: .ingestion, limit: 10).count, 0)

Tests/AppTests/GitLiveTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import XCTest
1616

1717
@testable import App
1818

19+
import Dependencies
1920
import ShellOut
2021

2122

@@ -47,6 +48,14 @@ class GitLiveTests: XCTestCase {
4748
override func setUp() {
4849
Current.setLogger(.init(label: "test", factory: { _ in logger }))
4950
}
51+
52+
override func invokeTest() {
53+
withDependencies {
54+
$0.shell = .liveValue
55+
} operation: {
56+
super.invokeTest()
57+
}
58+
}
5059
}
5160

5261

Tests/AppTests/ReAnalyzeVersionsTests.swift

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class ReAnalyzeVersionsTests: AppTestCase {
8888
XCTAssertEqual(versions.map { $0.targets.map(\.name) } , [[], []])
8989
XCTAssertEqual(versions.map(\.releaseNotes) , [nil, nil])
9090
}
91+
9192
try await withDependencies {
9293
// Update state that would normally not be affecting existing versions, effectively simulating the situation where we only started parsing it after versions had already been created
9394
$0.shell.run = { @Sendable cmd, path in
@@ -105,42 +106,42 @@ class ReAnalyzeVersionsTests: AppTestCase {
105106
}
106107
return ""
107108
}
108-
} operation: {
109109
// also, update release notes to ensure mergeReleaseInfo is being called
110110
let r = try await Repository.find(repoId, on: app.db).unwrap()
111111
r.releases = [
112112
.mock(description: "rel 1.2.3", tagName: "1.2.3")
113113
]
114114
try await r.save(on: app.db)
115-
}
116-
do { // assert running analysis again does not update existing versions
117-
try await Analyze.analyze(client: app.client,
118-
database: app.db,
119-
mode: .limit(10))
115+
} operation: {
116+
do { // assert running analysis again does not update existing versions
117+
try await Analyze.analyze(client: app.client,
118+
database: app.db,
119+
mode: .limit(10))
120+
let versions = try await Version.query(on: app.db)
121+
.with(\.$targets)
122+
.all()
123+
XCTAssertEqual(versions.map(\.toolsVersion), [nil, nil])
124+
XCTAssertEqual(versions.map { $0.targets.map(\.name) } , [[], []])
125+
XCTAssertEqual(versions.map(\.releaseNotes) , [nil, nil])
126+
XCTAssertEqual(versions.map(\.docArchives), [nil, nil])
127+
}
128+
129+
// MUT
130+
try await ReAnalyzeVersions.reAnalyzeVersions(client: app.client,
131+
database: app.db,
132+
before: Date.now,
133+
refreshCheckouts: false,
134+
limit: 10)
135+
136+
// validate that re-analysis has now updated existing versions
120137
let versions = try await Version.query(on: app.db)
121138
.with(\.$targets)
139+
.sort(\.$createdAt)
122140
.all()
123-
XCTAssertEqual(versions.map(\.toolsVersion), [nil, nil])
124-
XCTAssertEqual(versions.map { $0.targets.map(\.name) } , [[], []])
125-
XCTAssertEqual(versions.map(\.releaseNotes) , [nil, nil])
126-
XCTAssertEqual(versions.map(\.docArchives), [nil, nil])
141+
XCTAssertEqual(versions.map(\.toolsVersion), ["5.3", "5.3"])
142+
XCTAssertEqual(versions.map { $0.targets.map(\.name) } , [["t1"], ["t1"]])
143+
XCTAssertEqual(versions.compactMap(\.releaseNotes) , ["rel 1.2.3"])
127144
}
128-
129-
// MUT
130-
try await ReAnalyzeVersions.reAnalyzeVersions(client: app.client,
131-
database: app.db,
132-
before: Date.now,
133-
refreshCheckouts: false,
134-
limit: 10)
135-
136-
// validate that re-analysis has now updated existing versions
137-
let versions = try await Version.query(on: app.db)
138-
.with(\.$targets)
139-
.sort(\.$createdAt)
140-
.all()
141-
XCTAssertEqual(versions.map(\.toolsVersion), ["5.3", "5.3"])
142-
XCTAssertEqual(versions.map { $0.targets.map(\.name) } , [["t1"], ["t1"]])
143-
XCTAssertEqual(versions.compactMap(\.releaseNotes) , ["rel 1.2.3"])
144145
}
145146
}
146147
}

0 commit comments

Comments
 (0)