Added tests for the Amiibo live client and ISO transcoder.
This commit is contained in:
1 parent
c031fdcc97
commit
8fa4d50734
4 files changed
+588
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the Amiibo Service open source project
|
||||
//
|
||||
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
|
||||
// Licensed under Apache license v2.0
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of Amiibo Service project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Makes a date from UTC components.
|
||||
static func utc(
|
||||
_ year: Int,
|
||||
_ month: Int,
|
||||
_ day: Int,
|
||||
_ hour: Int = 0,
|
||||
_ minute: Int = 0,
|
||||
_ second: Int = 0
|
||||
) -> Date {
|
||||
var calendar = Calendar(identifier: .gregorian)
|
||||
|
||||
calendar.timeZone = .init(secondsFromGMT: 0)!
|
||||
|
||||
return calendar.date(from: .init(
|
||||
year: year,
|
||||
month: month,
|
||||
day: day,
|
||||
hour: hour,
|
||||
minute: minute,
|
||||
second: second
|
||||
))!
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// ===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the Amiibo Service open source project
|
||||
//
|
||||
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
|
||||
// Licensed under Apache license v2.0
|
||||
//
|
||||
// See LICENSE for license information
|
||||
// See CONTRIBUTORS for the list of Amiibo Service project authors
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
// ===----------------------------------------------------------------------===
|
||||
|
||||
import Foundation
|
||||
import HTTPTypes
|
||||
import OpenAPIRuntime
|
||||
|
||||
/// A transport that answers every request with a canned response, for testing purposes.
|
||||
struct StubTransport: ClientTransport {
|
||||
|
||||
// MARK: Type aliases
|
||||
|
||||
/// A closure that builds the response for a request.
|
||||
typealias Handler = @Sendable (HTTPRequest) throws -> (HTTPResponse, HTTPBody?)
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// The handler that builds the response.
|
||||
private let handler: Handler
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
/// Initializes this transport with a response handler.
|
||||
init(handler: @escaping Handler) {
|
||||
self.handler = handler
|
||||
}
|
||||
|
||||
/// Initializes this transport with a fixed response.
|
||||
init(status: HTTPResponse.Status, json: String? = nil) {
|
||||
self.init { _ in
|
||||
Self.response(status: status, json: json)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
func send(
|
||||
_ request: HTTPRequest,
|
||||
body: HTTPBody?,
|
||||
baseURL: URL,
|
||||
operationID: String
|
||||
) async throws -> (HTTPResponse, HTTPBody?) {
|
||||
try handler(request)
|
||||
}
|
||||
|
||||
/// Builds a response with a status and an optional JSON body.
|
||||
static func response(
|
||||
status: HTTPResponse.Status,
|
||||
json: String? = nil
|
||||
) -> (HTTPResponse, HTTPBody?) {
|
||||
guard let json else {
|
||||
return (.init(status: status), nil)
|
||||
}
|
||||
|
||||
return (
|
||||
.init(status: status, headerFields: [.contentType: "application/json"]),
|
||||
.init(json)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user