-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interceptor): Make public rescue API async (#22)
- Loading branch information
Showing
5 changed files
with
51 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
Tests/SimpleHTTPTests/Interceptor/CompositeInterceptorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import XCTest | ||
import SimpleHTTP | ||
|
||
class CompositeInterceptorTests: XCTestCase { | ||
func test_shouldRescue_moreThanOneInterceptorRescue_callFirstOneOnly() async throws { | ||
let interceptors: CompositeInterceptor = [ | ||
InterceptorStub(shouldRequestMock: { _ in false }), | ||
InterceptorStub(shouldRequestMock: { _ in true }), | ||
InterceptorStub(shouldRequestMock: { _ in | ||
XCTFail("should not be called because request was already rescued") | ||
return true | ||
}) | ||
] | ||
|
||
let result = try await interceptors | ||
.shouldRescueRequest(Request<Void>.get("/test"), error: HTTPError(statusCode: 888)) | ||
|
||
XCTAssertTrue(result) | ||
} | ||
} | ||
|
||
private struct InterceptorStub: Interceptor { | ||
var shouldRequestMock: (Error) throws -> Bool = { _ in false } | ||
|
||
func shouldRescueRequest<Output>(_ request: Request<Output>, error: Error) async throws -> Bool { | ||
try shouldRequestMock(error) | ||
} | ||
|
||
func adaptRequest<Output>(_ request: Request<Output>) -> Request<Output> { | ||
request | ||
} | ||
|
||
func adaptOutput<Output>(_ output: Output, for request: Request<Output>) throws -> Output { | ||
output | ||
} | ||
|
||
func receivedResponse<Output>(_ result: Result<Output, Error>, for request: Request<Output>) { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters