Skip to content

Commit 5b98c46

Browse files
committed
Convert GitlabBuilderTests
1 parent 5200543 commit 5b98c46

File tree

1 file changed

+34
-39
lines changed

1 file changed

+34
-39
lines changed

Tests/AppTests/GitlabBuilderTests.swift

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,26 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import XCTest
16-
1715
@testable import App
1816

1917
import Dependencies
18+
import Testing
2019
import Vapor
2120

2221

23-
class GitlabBuilderTests: AppTestCase {
22+
@Suite struct GitlabBuilderTests {
2423

25-
func test_SwiftVersion_rendering() throws {
26-
XCTAssertEqual("\(SwiftVersion.v4)", "6.0.0")
27-
XCTAssertEqual(SwiftVersion.v4.description(droppingZeroes: .none), "6.0.0")
28-
XCTAssertEqual(SwiftVersion.v4.description(droppingZeroes: .patch), "6.0")
29-
XCTAssertEqual(SwiftVersion.v4.description(droppingZeroes: .all), "6")
24+
@Test func SwiftVersion_rendering() throws {
25+
#expect("\(SwiftVersion.v4)" == "6.0.0")
26+
#expect(SwiftVersion.v4.description(droppingZeroes: .none) == "6.0.0")
27+
#expect(SwiftVersion.v4.description(droppingZeroes: .patch) == "6.0")
28+
#expect(SwiftVersion.v4.description(droppingZeroes: .all) == "6")
3029
}
3130

32-
func test_variables_encoding() async throws {
31+
@Test func variables_encoding() async throws {
3332
// Ensure the POST variables are encoded correctly
3433
// setup
35-
let app = try await setup(.testing)
36-
37-
try await App.run {
34+
try await withApp { app in
3835
let req = Request(application: app, on: app.eventLoopGroup.next())
3936
let dto = Gitlab.Builder.PostDTO(token: "token",
4037
ref: "ref",
@@ -46,14 +43,11 @@ class GitlabBuilderTests: AppTestCase {
4643
// validate
4744
// Gitlab accepts both `variables[FOO]=bar` and `variables%5BFOO%5D=bar` for the [] encoding.
4845
// Since Vapor 4.92.1 this is now encoded as `variables%5BFOO%5D=bar`.
49-
XCTAssertEqual(req.url.query?.split(separator: "&").sorted(),
50-
["ref=ref", "token=token", "variables%5BFOO%5D=bar"])
51-
} defer: {
52-
try await app.asyncShutdown()
46+
#expect(req.url.query?.split(separator: "&").sorted() == ["ref=ref", "token=token", "variables%5BFOO%5D=bar"])
5347
}
5448
}
5549

56-
func test_triggerBuild() async throws {
50+
@Test func triggerBuild() async throws {
5751
let buildId = UUID.id0
5852
let versionId = UUID.id1
5953
let called = QueueIsolated(false)
@@ -65,11 +59,11 @@ class GitlabBuilderTests: AppTestCase {
6559
$0.environment.siteURL = { "http://example.com" }
6660
$0.httpClient.post = { @Sendable _, _, body in
6761
called.setValue(true)
68-
let body = try XCTUnwrap(body)
62+
let body = try #require(body)
6963
// validate
70-
XCTAssertEqual(
71-
try? URLEncodedFormDecoder().decode(Gitlab.Builder.PostDTO.self, from: body),
72-
Gitlab.Builder.PostDTO(
64+
#expect(
65+
(try? URLEncodedFormDecoder().decode(Gitlab.Builder.PostDTO.self, from: body))
66+
== Gitlab.Builder.PostDTO(
7367
token: "pipeline token",
7468
ref: "main",
7569
variables: [
@@ -83,7 +77,8 @@ class GitlabBuilderTests: AppTestCase {
8377
"SWIFT_VERSION": "5.2",
8478
"TIMEOUT": "10m",
8579
"VERSION_ID": versionId.uuidString,
86-
])
80+
]
81+
)
8782
)
8883
return try .created(jsonEncode: Gitlab.Builder.Response(webUrl: "http://web_url"))
8984
}
@@ -96,11 +91,11 @@ class GitlabBuilderTests: AppTestCase {
9691
reference: .tag(.init(1, 2, 3)),
9792
swiftVersion: .init(5, 2, 4),
9893
versionID: versionId)
99-
XCTAssertTrue(called.value)
94+
#expect(called.value)
10095
}
10196
}
10297

103-
func test_issue_588() async throws {
98+
@Test func issue_588() async throws {
10499
let called = QueueIsolated(false)
105100
try await withDependencies {
106101
$0.environment.awsDocsBucket = { "docs-bucket" }
@@ -110,11 +105,11 @@ class GitlabBuilderTests: AppTestCase {
110105
$0.environment.siteURL = { "http://example.com" }
111106
$0.httpClient.post = { @Sendable _, _, body in
112107
called.setValue(true)
113-
let body = try XCTUnwrap(body)
108+
let body = try #require(body)
114109
// validate
115110
let swiftVersion = (try? URLEncodedFormDecoder().decode(Gitlab.Builder.PostDTO.self, from: body))
116111
.flatMap { $0.variables["SWIFT_VERSION"] }
117-
XCTAssertEqual(swiftVersion, "6.0")
112+
#expect(swiftVersion == "6.0")
118113
return try .created(jsonEncode: Gitlab.Builder.Response(webUrl: "http://web_url"))
119114
}
120115
} operation: {
@@ -126,26 +121,25 @@ class GitlabBuilderTests: AppTestCase {
126121
reference: .tag(.init(1, 2, 3)),
127122
swiftVersion: .v6_0,
128123
versionID: .id1)
129-
XCTAssertTrue(called.value)
124+
#expect(called.value)
130125
}
131126
}
132127

133-
func test_getStatusCount() async throws {
128+
@Test func getStatusCount() async throws {
134129
let page = QueueIsolated(1)
135130
try await withDependencies {
136131
$0.environment.gitlabApiToken = { "api token" }
137132
$0.httpClient.get = { @Sendable url, _ in
138-
XCTAssertEqual(
139-
url,
140-
"https://gitlab.com/api/v4/projects/19564054/pipelines?status=pending&page=\(page.value)&per_page=20"
133+
#expect(
134+
url == "https://gitlab.com/api/v4/projects/19564054/pipelines?status=pending&page=\(page.value)&per_page=20"
141135
)
142136
let pending = #"{"id": 1, "status": "pending"}"#
143137
defer { page.increment() }
144138
let elementsPerPage = switch page.value {
145139
case 1: 20
146140
case 2: 10
147141
default:
148-
XCTFail("unexpected page: \(page)")
142+
Issue.record("unexpected page: \(page)")
149143
throw Abort(.badRequest)
150144
}
151145
let list = Array(repeating: pending, count: elementsPerPage).joined(separator: ", ")
@@ -155,21 +149,22 @@ class GitlabBuilderTests: AppTestCase {
155149
let res = try await Gitlab.Builder.getStatusCount(status: .pending,
156150
pageSize: 20,
157151
maxPageCount: 3)
158-
XCTAssertEqual(res, 30)
152+
#expect(res == 30)
159153
}
160154
}
161155

162156
}
163157

164158

165-
class LiveGitlabBuilderTests: AppTestCase {
159+
@Suite
160+
166161

167-
func test_triggerBuild_live() async throws {
168-
try XCTSkipIf(
169-
true,
170-
"This is a live trigger test for end-to-end testing of pre-release builder versions"
171-
)
162+
struct LiveGitlabBuilderTests {
172163

164+
@Test(
165+
.disabled("This is a live trigger test for end-to-end testing of pre-release builder versions")
166+
)
167+
func triggerBuild_live() async throws {
173168
try await withDependencies {
174169
// make sure environment variables are configured for live access
175170
$0.environment.awsDocsBucket = { "spi-dev-docs" }

0 commit comments

Comments
 (0)