Map wrapped cancellation in the Amiibo live client to the cancelled error.
This commit is contained in:
1 parent
44bfaca553
commit
51b1245ec3
4 files changed
+102
-2
No files matched your search
@@ -42,5 +42,51 @@ struct AmiiboLiveClientTests {
|
||||
// THEN
|
||||
#expect(url == expected)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Error mapping tests
|
||||
|
||||
@Test(
|
||||
"maps an error thrown by the transport to the matching service error",
|
||||
arguments: zip(
|
||||
TransportErrors.thrown,
|
||||
TransportErrors.expected
|
||||
)
|
||||
)
|
||||
func mapsTransportError(
|
||||
thrown: any Error,
|
||||
expected: AmiiboServiceError
|
||||
) async {
|
||||
// GIVEN
|
||||
let client = AmiiboLiveClient(transport: ThrowingTransport(error: thrown))
|
||||
|
||||
// WHEN
|
||||
// THEN
|
||||
await #expect(throws: expected) {
|
||||
try await client.getAmiibos(by: .init())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Arguments
|
||||
|
||||
private enum TransportErrors {
|
||||
/// Errors thrown by the transport.
|
||||
static let thrown: [any Error] = [
|
||||
CancellationError(),
|
||||
URLError(.cancelled),
|
||||
URLError(.cannotParseResponse),
|
||||
URLError(.notConnectedToInternet),
|
||||
URLError(.timedOut),
|
||||
URLError(.badURL)
|
||||
]
|
||||
/// The service error expected for each thrown error.
|
||||
static let expected: [AmiiboServiceError] = [
|
||||
.cancelled,
|
||||
.cancelled,
|
||||
.decoding,
|
||||
.notAvailable,
|
||||
.notAvailable,
|
||||
.unknown(String(describing: URLError(.badURL)))
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user