Skip to content

Commit 274d78d

Browse files
Merge pull request #3684 from SwiftPackageIndex/issue-3655-swift-testing-part-9
Issue 3655 swift testing part 9
2 parents b27e120 + b484b5b commit 274d78d

File tree

3 files changed

+421
-390
lines changed

3 files changed

+421
-390
lines changed

Tests/AppTests/BuildResultTests.swift

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,32 @@
1414

1515
@testable import App
1616

17-
import XCTVapor
18-
19-
20-
class BuildResultTests: AppTestCase {
21-
22-
func test_query() async throws {
23-
// setup
24-
let pkg = try await savePackage(on: app.db, "1".url)
25-
let repo = try Repository(package: pkg)
26-
try await repo.save(on: app.db)
27-
let version = try Version(package: pkg)
28-
try await version.save(on: app.db)
29-
let build = try Build(version: version, platform: .iOS, status: .ok, swiftVersion: .init(5, 3, 0))
30-
try await build.save(on: app.db)
31-
32-
// MUT
33-
let res = try await BuildResult.query(on: app.db, buildId: build.id!)
34-
35-
// validate
36-
XCTAssertEqual(res.build.id, build.id)
37-
XCTAssertEqual(res.package.id, pkg.id)
38-
XCTAssertEqual(res.repository.id, repo.id)
39-
XCTAssertEqual(res.version.id, version.id)
17+
import Testing
18+
import Vapor
19+
20+
21+
@Suite struct BuildResultTests {
22+
23+
@Test func query() async throws {
24+
try await withApp { app in
25+
// setup
26+
let pkg = try await savePackage(on: app.db, "1".url)
27+
let repo = try Repository(package: pkg)
28+
try await repo.save(on: app.db)
29+
let version = try Version(package: pkg)
30+
try await version.save(on: app.db)
31+
let build = try Build(version: version, platform: .iOS, status: .ok, swiftVersion: .init(5, 3, 0))
32+
try await build.save(on: app.db)
33+
34+
// MUT
35+
let res = try await BuildResult.query(on: app.db, buildId: build.id!)
36+
37+
// validate
38+
#expect(res.build.id == build.id)
39+
#expect(res.package.id == pkg.id)
40+
#expect(res.repository.id == repo.id)
41+
#expect(res.version.id == version.id)
42+
}
4043
}
4144

4245
}

Tests/AppTests/BuildShowModelTests.swift

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,49 @@
1414

1515
@testable import App
1616

17-
import XCTVapor
17+
import Testing
18+
import Vapor
1819

1920

20-
class BuildShowModelTests: AppTestCase {
21+
@Suite struct BuildShowModelTests {
2122

2223
typealias Model = BuildShow.Model
2324

24-
func test_buildsURL() throws {
25-
XCTAssertEqual(Model.mock.buildsURL, "/foo/bar/builds")
25+
@Test func buildsURL() throws {
26+
#expect(Model.mock.buildsURL == "/foo/bar/builds")
2627
}
2728

28-
func test_packageURL() throws {
29-
XCTAssertEqual(Model.mock.packageURL, "/foo/bar")
29+
@Test func packageURL() throws {
30+
#expect(Model.mock.packageURL == "/foo/bar")
3031
}
3132

32-
func test_init() async throws {
33-
// setup
34-
let pkg = try await savePackage(on: app.db, "1".url)
35-
try await Repository(package: pkg,
36-
defaultBranch: "main",
37-
forks: 42,
38-
license: .mit,
39-
name: "bar",
40-
owner: "foo",
41-
stars: 17,
42-
summary: "summary").save(on: app.db)
43-
let version = try Version(id: UUID(), package: pkg, packageName: "Bar", reference: .branch("main"))
44-
try await version.save(on: app.db)
45-
let buildId = UUID()
46-
try await Build(id: buildId, version: version, platform: .iOS, status: .ok, swiftVersion: .v3)
47-
.save(on: app.db)
48-
let result = try await BuildResult.query(on: app.db, buildId: buildId)
49-
50-
// MUT
51-
let model = BuildShow.Model(result: result, logs: "logs")
52-
53-
// validate
54-
XCTAssertEqual(model?.packageName, "Bar")
55-
XCTAssertEqual(model?.versionId, version.id)
56-
XCTAssertEqual(model?.buildInfo.logs, "logs")
33+
@Test func Model_init() async throws {
34+
try await withApp { app in
35+
// setup
36+
let pkg = try await savePackage(on: app.db, "1".url)
37+
try await Repository(package: pkg,
38+
defaultBranch: "main",
39+
forks: 42,
40+
license: .mit,
41+
name: "bar",
42+
owner: "foo",
43+
stars: 17,
44+
summary: "summary").save(on: app.db)
45+
let version = try Version(id: UUID(), package: pkg, packageName: "Bar", reference: .branch("main"))
46+
try await version.save(on: app.db)
47+
let buildId = UUID()
48+
try await Build(id: buildId, version: version, platform: .iOS, status: .ok, swiftVersion: .v3)
49+
.save(on: app.db)
50+
let result = try await BuildResult.query(on: app.db, buildId: buildId)
51+
52+
// MUT
53+
let model = BuildShow.Model(result: result, logs: "logs")
54+
55+
// validate
56+
#expect(model?.packageName == "Bar")
57+
#expect(model?.versionId == version.id)
58+
#expect(model?.buildInfo.logs == "logs")
59+
}
5760
}
5861

5962
}

0 commit comments

Comments
 (0)