Skip to content

Commit 941b51e

Browse files
committed
Remove deprecated fetchLicense(client:owner:repository:), eliminate some deprecation warnings
1 parent a5a10f2 commit 941b51e

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

Sources/App/Core/Github.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ extension Github {
175175
return try decoder.decode(T.self, from: body)
176176
}
177177

178-
@available(*, deprecated)
179-
static func fetchLicense(client: Client, owner: String, repository: String) async -> License? {
180-
let uri = Github.apiUri(owner: owner, repository: repository, resource: .license)
181-
return try? await Github.fetchResource(Github.License.self, client: client, uri: uri)
182-
}
183-
184178
static func fetchLicense(owner: String, repository: String) async -> License? {
185179
let url = Github.apiURL(owner: owner, repository: repository, resource: .license)
186180
return try? await Github.fetchResource(Github.License.self, url: url)

Tests/AppTests/GithubTests.swift

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -261,28 +261,28 @@ class GithubTests: AppTestCase {
261261

262262
func test_isRateLimited() throws {
263263
do {
264-
let res = ClientResponse(status: .forbidden,
265-
headers: .init([("X-RateLimit-Remaining", "0")]))
264+
let res = HTTPClient.Response(status: .forbidden,
265+
headers: .init([("X-RateLimit-Remaining", "0")]))
266266
XCTAssertTrue(Github.isRateLimited(res))
267267
}
268268
do {
269-
let res = ClientResponse(status: .forbidden,
270-
headers: .init([("x-ratelimit-remaining", "0")]))
269+
let res = HTTPClient.Response(status: .forbidden,
270+
headers: .init([("x-ratelimit-remaining", "0")]))
271271
XCTAssertTrue(Github.isRateLimited(res))
272272
}
273273
do {
274-
let res = ClientResponse(status: .forbidden,
275-
headers: .init([("X-RateLimit-Remaining", "1")]))
274+
let res = HTTPClient.Response(status: .forbidden,
275+
headers: .init([("X-RateLimit-Remaining", "1")]))
276276
XCTAssertFalse(Github.isRateLimited(res))
277277
}
278278
do {
279-
let res = ClientResponse(status: .forbidden,
280-
headers: .init([("unrelated", "0")]))
279+
let res = HTTPClient.Response(status: .forbidden,
280+
headers: .init([("unrelated", "0")]))
281281
XCTAssertFalse(Github.isRateLimited(res))
282282
}
283283
do {
284-
let res = ClientResponse(status: .ok,
285-
headers: .init([("X-RateLimit-Remaining", "0")]))
284+
let res = HTTPClient.Response(status: .ok,
285+
headers: .init([("X-RateLimit-Remaining", "0")]))
286286
XCTAssertFalse(Github.isRateLimited(res))
287287
}
288288
}
@@ -318,40 +318,44 @@ class GithubTests: AppTestCase {
318318
}
319319
}
320320

321-
func test_apiUri() throws {
322-
XCTAssertEqual(Github.apiUri(owner: "foo", repository: "bar", resource: .license).string,
321+
func test_apiURL() throws {
322+
XCTAssertEqual(Github.apiURL(owner: "foo", repository: "bar", resource: .license),
323323
"https://api.github.com/repos/foo/bar/license")
324-
XCTAssertEqual(Github.apiUri(owner: "foo", repository: "bar", resource: .readme).string,
324+
XCTAssertEqual(Github.apiURL(owner: "foo", repository: "bar", resource: .readme),
325325
"https://api.github.com/repos/foo/bar/readme")
326326
}
327327

328328
func test_fetchLicense() async throws {
329329
// setup
330330
Current.githubToken = { "secr3t" }
331-
let data = try XCTUnwrap(try fixtureData(for: "github-license-response.json"))
332-
let client = MockClient { _, resp in
333-
resp.status = .ok
334-
resp.body = makeBody(data)
335-
}
336331

337-
// MUT
338-
let res = await Github.fetchLicense(client: client, owner: "PSPDFKit", repository: "PSPDFKit-SP")
332+
await withDependencies {
333+
$0.httpClient.get = { @Sendable _, _ in
334+
try .init(status: .ok, body: .fixture(named: "github-license-response.json"))
335+
}
336+
} operation: {
337+
// MUT
338+
let res = await Github.fetchLicense(owner: "PSPDFKit", repository: "PSPDFKit-SP")
339339

340-
// validate
341-
XCTAssertEqual(res?.htmlUrl, "https://github.com/PSPDFKit/PSPDFKit-SP/blob/master/LICENSE")
340+
// validate
341+
XCTAssertEqual(res?.htmlUrl, "https://github.com/PSPDFKit/PSPDFKit-SP/blob/master/LICENSE")
342+
}
342343
}
343344

344345
func test_fetchLicense_notFound() async throws {
345346
// https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/761
346347
// setup
347348
Current.githubToken = { "secr3t" }
348-
let client = MockClient { _, resp in resp.status = .notFound }
349349

350-
// MUT
351-
let res = await Github.fetchLicense(client: client, owner: "foo", repository: "bar")
350+
await withDependencies {
351+
$0.httpClient.get = { @Sendable _, _ in .notFound }
352+
} operation: {
353+
// MUT
354+
let res = await Github.fetchLicense(owner: "foo", repository: "bar")
352355

353-
// validate
354-
XCTAssertEqual(res, nil)
356+
// validate
357+
XCTAssertEqual(res, nil)
358+
}
355359
}
356360

357361
func test_fetchReadme() async throws {
@@ -488,3 +492,10 @@ class GithubTests: AppTestCase {
488492
}
489493

490494
}
495+
496+
497+
private extension ByteBuffer {
498+
static func fixture(named filename: String) throws -> Self {
499+
.init(data: try fixtureData(for: filename))
500+
}
501+
}

0 commit comments

Comments
 (0)