|
14 | 14 |
|
15 | 15 | @testable import App |
16 | 16 |
|
| 17 | +import Testing |
17 | 18 | import Vapor |
18 | | -import XCTest |
19 | 19 |
|
20 | | -class PackageController_BuildsRouteTests: AppTestCase { |
| 20 | + |
| 21 | +@Suite struct PackageController_BuildsRouteTests { |
21 | 22 |
|
22 | 23 | typealias BuildDetails = (id: Build.Id, reference: Reference, platform: Build.Platform, swiftVersion: SwiftVersion, status: Build.Status, docStatus: DocUpload.Status?) |
23 | 24 |
|
24 | | - func test_BuildInfo_query() async throws { |
25 | | - // setup |
26 | | - do { |
27 | | - let pkg = try await savePackage(on: app.db, "1".url) |
28 | | - try await Repository(package: pkg, |
29 | | - defaultBranch: "main", |
30 | | - name: "bar", |
31 | | - owner: "foo").save(on: app.db) |
32 | | - let builds: [BuildDetails] = [ |
33 | | - (.id0, .branch("main"), .iOS, .v2, .ok, .ok), |
34 | | - (.id1, .branch("main"), .tvOS, .v1, .failed, nil), |
35 | | - (.id2, .tag(1, 2, 3), .iOS, .v2, .ok, nil), |
36 | | - (.id3, .tag(2, 0, 0, "b1"), .iOS, .v2, .failed, nil), |
37 | | - ] |
38 | | - for b in builds { |
39 | | - let v = try App.Version(package: pkg, |
40 | | - latest: b.reference.kind, |
41 | | - packageName: "p1", |
42 | | - reference: b.reference) |
43 | | - try await v.save(on: app.db) |
44 | | - let build = try Build(id: b.id, version: v, platform: b.platform, status: b.status, swiftVersion: b.swiftVersion) |
45 | | - try await build.save(on: app.db) |
46 | | - if let docStatus = b.docStatus { |
47 | | - let d = DocUpload(id: .init(), status: docStatus) |
48 | | - try await d.attach(to: build, on: app.db) |
| 25 | + @Test func BuildInfo_query() async throws { |
| 26 | + try await withApp { app in |
| 27 | + // setup |
| 28 | + do { |
| 29 | + let pkg = try await savePackage(on: app.db, "1".url) |
| 30 | + try await Repository(package: pkg, |
| 31 | + defaultBranch: "main", |
| 32 | + name: "bar", |
| 33 | + owner: "foo").save(on: app.db) |
| 34 | + let builds: [BuildDetails] = [ |
| 35 | + (.id0, .branch("main"), .iOS, .v2, .ok, .ok), |
| 36 | + (.id1, .branch("main"), .tvOS, .v1, .failed, nil), |
| 37 | + (.id2, .tag(1, 2, 3), .iOS, .v2, .ok, nil), |
| 38 | + (.id3, .tag(2, 0, 0, "b1"), .iOS, .v2, .failed, nil), |
| 39 | + ] |
| 40 | + for b in builds { |
| 41 | + let v = try App.Version(package: pkg, |
| 42 | + latest: b.reference.kind, |
| 43 | + packageName: "p1", |
| 44 | + reference: b.reference) |
| 45 | + try await v.save(on: app.db) |
| 46 | + let build = try Build(id: b.id, version: v, platform: b.platform, status: b.status, swiftVersion: b.swiftVersion) |
| 47 | + try await build.save(on: app.db) |
| 48 | + if let docStatus = b.docStatus { |
| 49 | + let d = DocUpload(id: .init(), status: docStatus) |
| 50 | + try await d.attach(to: build, on: app.db) |
| 51 | + } |
49 | 52 | } |
50 | 53 | } |
51 | | - } |
52 | | - do { // unrelated package and build |
53 | | - let pkg = try await savePackage(on: app.db, "2".url) |
54 | | - try await Repository(package: pkg, |
55 | | - defaultBranch: "main", |
56 | | - name: "bar2", |
57 | | - owner: "foo").save(on: app.db) |
58 | | - let builds: [BuildDetails] = [ |
59 | | - (.id4, .branch("develop"), .iOS, .v4, .ok, nil), |
60 | | - ] |
61 | | - for b in builds { |
62 | | - let v = try App.Version(package: pkg, |
63 | | - latest: b.reference.kind, |
64 | | - packageName: "p1", |
65 | | - reference: b.reference) |
66 | | - try await v.save(on: app.db) |
67 | | - try await Build(id: b.id, version: v, platform: b.platform, status: b.status, swiftVersion: b.swiftVersion) |
68 | | - .save(on: app.db) |
| 54 | + do { // unrelated package and build |
| 55 | + let pkg = try await savePackage(on: app.db, "2".url) |
| 56 | + try await Repository(package: pkg, |
| 57 | + defaultBranch: "main", |
| 58 | + name: "bar2", |
| 59 | + owner: "foo").save(on: app.db) |
| 60 | + let builds: [BuildDetails] = [ |
| 61 | + (.id4, .branch("develop"), .iOS, .v4, .ok, nil), |
| 62 | + ] |
| 63 | + for b in builds { |
| 64 | + let v = try App.Version(package: pkg, |
| 65 | + latest: b.reference.kind, |
| 66 | + packageName: "p1", |
| 67 | + reference: b.reference) |
| 68 | + try await v.save(on: app.db) |
| 69 | + try await Build(id: b.id, version: v, platform: b.platform, status: b.status, swiftVersion: b.swiftVersion) |
| 70 | + .save(on: app.db) |
| 71 | + } |
69 | 72 | } |
70 | | - } |
71 | | - |
72 | | - // MUT |
73 | | - let builds = try await PackageController.BuildsRoute.BuildInfo.query(on: app.db, owner: "foo", repository: "bar") |
74 | 73 |
|
75 | | - // validate |
76 | | - XCTAssertEqual( |
77 | | - builds.sorted { $0.buildId.uuidString < $1.buildId.uuidString }, |
78 | | - [ |
79 | | - .init(versionKind: .defaultBranch, reference: .branch("main"), buildId: .id0, swiftVersion: .v2, platform: .iOS, status: .ok, docStatus: .ok), |
80 | | - .init(versionKind: .defaultBranch, reference: .branch("main"), buildId: .id1, swiftVersion: .v1, platform: .tvOS, status: .failed), |
81 | | - .init(versionKind: .release, reference: .tag(1, 2, 3), buildId: .id2, swiftVersion: .v2, platform: .iOS, status: .ok), |
82 | | - .init(versionKind: .preRelease, reference: .tag(2, 0, 0, "b1"), buildId: .id3, swiftVersion: .v2, platform: .iOS, status: .failed), |
83 | | - ].sorted { $0.buildId.uuidString < $1.buildId.uuidString } |
84 | | - ) |
| 74 | + // MUT |
| 75 | + let builds = try await PackageController.BuildsRoute.BuildInfo.query(on: app.db, owner: "foo", repository: "bar") |
| 76 | + |
| 77 | + // validate |
| 78 | + #expect( |
| 79 | + builds.sorted { $0.buildId.uuidString < $1.buildId.uuidString } == [ |
| 80 | + .init(versionKind: .defaultBranch, reference: .branch("main"), buildId: .id0, swiftVersion: .v2, platform: .iOS, status: .ok, docStatus: .ok), |
| 81 | + .init(versionKind: .defaultBranch, reference: .branch("main"), buildId: .id1, swiftVersion: .v1, platform: .tvOS, status: .failed), |
| 82 | + .init(versionKind: .release, reference: .tag(1, 2, 3), buildId: .id2, swiftVersion: .v2, platform: .iOS, status: .ok), |
| 83 | + .init(versionKind: .preRelease, reference: .tag(2, 0, 0, "b1"), buildId: .id3, swiftVersion: .v2, platform: .iOS, status: .failed), |
| 84 | + ].sorted { $0.buildId.uuidString < $1.buildId.uuidString } |
| 85 | + ) |
| 86 | + } |
85 | 87 | } |
86 | 88 |
|
87 | | - func test_query() async throws { |
88 | | - // setup |
89 | | - let pkg = try await savePackage(on: app.db, "1".url) |
90 | | - try await Repository(package: pkg, |
91 | | - defaultBranch: "main", |
92 | | - forks: 42, |
93 | | - license: .mit, |
94 | | - name: "bar", |
95 | | - owner: "foo", |
96 | | - stars: 17, |
97 | | - summary: "summary").save(on: app.db) |
98 | | - let v = try Version(package: pkg, latest: .defaultBranch, packageName: "pkg", reference: .branch("main")) |
99 | | - try await v.save(on: app.db) |
100 | | - try await Build(id: .id0, version: v, platform: .iOS, status: .ok, swiftVersion: .v1) |
101 | | - .save(on: app.db) |
102 | | - |
103 | | - // MUT |
104 | | - let (pkgInfo, buildInfo) = try await PackageController.BuildsRoute |
105 | | - .query(on: app.db, owner: "foo", repository: "bar") |
106 | | - |
107 | | - // validate |
108 | | - XCTAssertEqual(pkgInfo, .init(packageName: "pkg", |
109 | | - repositoryOwner: "foo", |
110 | | - repositoryName: "bar")) |
111 | | - XCTAssertEqual(buildInfo, [ |
112 | | - .init(versionKind: .defaultBranch, |
113 | | - reference: .branch("main"), |
114 | | - buildId: .id0, |
115 | | - swiftVersion: .v1, |
116 | | - platform: .iOS, |
117 | | - status: .ok) |
118 | | - ]) |
| 89 | + @Test func query() async throws { |
| 90 | + try await withApp { app in |
| 91 | + // setup |
| 92 | + let pkg = try await savePackage(on: app.db, "1".url) |
| 93 | + try await Repository(package: pkg, |
| 94 | + defaultBranch: "main", |
| 95 | + forks: 42, |
| 96 | + license: .mit, |
| 97 | + name: "bar", |
| 98 | + owner: "foo", |
| 99 | + stars: 17, |
| 100 | + summary: "summary").save(on: app.db) |
| 101 | + let v = try Version(package: pkg, latest: .defaultBranch, packageName: "pkg", reference: .branch("main")) |
| 102 | + try await v.save(on: app.db) |
| 103 | + try await Build(id: .id0, version: v, platform: .iOS, status: .ok, swiftVersion: .v1) |
| 104 | + .save(on: app.db) |
| 105 | + |
| 106 | + // MUT |
| 107 | + let (pkgInfo, buildInfo) = try await PackageController.BuildsRoute |
| 108 | + .query(on: app.db, owner: "foo", repository: "bar") |
| 109 | + |
| 110 | + // validate |
| 111 | + #expect(pkgInfo == .init(packageName: "pkg", |
| 112 | + repositoryOwner: "foo", |
| 113 | + repositoryName: "bar")) |
| 114 | + #expect(buildInfo == [ |
| 115 | + .init(versionKind: .defaultBranch, |
| 116 | + reference: .branch("main"), |
| 117 | + buildId: .id0, |
| 118 | + swiftVersion: .v1, |
| 119 | + platform: .iOS, |
| 120 | + status: .ok) |
| 121 | + ]) |
| 122 | + } |
119 | 123 | } |
120 | 124 |
|
121 | | - func test_query_no_builds() async throws { |
122 | | - // setup |
123 | | - let pkg = try await savePackage(on: app.db, "1".url) |
124 | | - try await Repository(package: pkg, |
125 | | - defaultBranch: "main", |
126 | | - forks: 42, |
127 | | - license: .mit, |
128 | | - name: "bar", |
129 | | - owner: "foo", |
130 | | - stars: 17, |
131 | | - summary: "summary").save(on: app.db) |
132 | | - // no builds and also no packageName set |
133 | | - try await Version(package: pkg, latest: .defaultBranch, packageName: nil).save(on: app.db) |
134 | | - |
135 | | - // MUT |
136 | | - let (pkgInfo, buildInfo) = try await PackageController.BuildsRoute |
137 | | - .query(on: app.db, owner: "foo", repository: "bar") |
138 | | - |
139 | | - // validate |
140 | | - XCTAssertEqual(pkgInfo, .init(packageName: nil, |
141 | | - repositoryOwner: "foo", |
142 | | - repositoryName: "bar")) |
143 | | - XCTAssertEqual(buildInfo, []) |
144 | | - |
| 125 | + @Test func query_no_builds() async throws { |
| 126 | + try await withApp { app in |
| 127 | + // setup |
| 128 | + let pkg = try await savePackage(on: app.db, "1".url) |
| 129 | + try await Repository(package: pkg, |
| 130 | + defaultBranch: "main", |
| 131 | + forks: 42, |
| 132 | + license: .mit, |
| 133 | + name: "bar", |
| 134 | + owner: "foo", |
| 135 | + stars: 17, |
| 136 | + summary: "summary").save(on: app.db) |
| 137 | + // no builds and also no packageName set |
| 138 | + try await Version(package: pkg, latest: .defaultBranch, packageName: nil).save(on: app.db) |
| 139 | + |
| 140 | + // MUT |
| 141 | + let (pkgInfo, buildInfo) = try await PackageController.BuildsRoute |
| 142 | + .query(on: app.db, owner: "foo", repository: "bar") |
| 143 | + |
| 144 | + // validate |
| 145 | + #expect(pkgInfo == .init(packageName: nil, |
| 146 | + repositoryOwner: "foo", |
| 147 | + repositoryName: "bar")) |
| 148 | + #expect(buildInfo == []) |
| 149 | + } |
145 | 150 | } |
146 | 151 |
|
147 | 152 | } |
|
0 commit comments