Skip to content

Commit

Permalink
fix multiline_arguments_brackets and multiline_parameters_brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
417-72KI committed Oct 18, 2024
1 parent 2a017b6 commit f8490a8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ final class MultipartFormDataParserTests: XCTestCase {
let message = Data("Hello world!".utf8)

try runActivity(named: "request") {
let request = try requestWithAPIKit(genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message)
let request = try requestWithAPIKit(
genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message
)
let data = try MultipartFormData.parse(from: request)
XCTAssertEqual(data.element(forName: "genbaNeko")?.data, genbaNeko)
XCTAssertEqual(data.element(forName: "denwaNeko")?.data, denwaNeko)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ extension XCTestCase {
case let .failure(error):
if retryCount > 0 {
print("retry: \(retryCount)")
return try uploadWithMoya(genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message,
retryCount: retryCount - 1,
file: file,
line: line)
return try uploadWithMoya(
genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message,
retryCount: retryCount - 1,
file: file,
line: line
)
}
throw error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ extension XCTestCase {
return try JSONDecoder().decode(TestEntity.self, from: data)
} catch {
guard retryCount > 0 else { throw error }
return try await uploadURLSessionData(genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message,
retryCount: retryCount - 1,
file: file,
line: line)
return try await uploadURLSessionData(
genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message,
retryCount: retryCount - 1,
file: file,
line: line
)
}
}

Expand All @@ -46,21 +48,25 @@ extension XCTestCase {
var request = URLRequest(url: URL(string: "https://localhost/upload")!)
request.httpMethod = "POST"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
let requestBody = createBody(boundary: boundary,
genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message)
let requestBody = createBody(
boundary: boundary,
genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message
)
do {
let (data, _) = try await session.upload(for: request, from: requestBody)
return try JSONDecoder().decode(TestEntity.self, from: data)
} catch {
guard retryCount > 0 else { throw error }
return try await uploadURLSessionUpload(genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message,
retryCount: retryCount - 1,
file: file,
line: line)
return try await uploadURLSessionUpload(
genbaNeko: genbaNeko,
denwaNeko: denwaNeko,
message: message,
retryCount: retryCount - 1,
file: file,
line: line
)
}
}
}
Expand All @@ -87,10 +93,12 @@ extension XCTestCase {
}
}

private func createBody(boundary: String,
genbaNeko: Data,
denwaNeko: Data,
message: Data) -> Data {
private func createBody(
boundary: String,
genbaNeko: Data,
denwaNeko: Data,
message: Data
) -> Data {
[
Data("--\(boundary)\r\n".utf8),
Data("Content-Disposition: form-data; name=\"genbaNeko\"; filename=\"genbaNeko\"\r\n".utf8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ final class StubURLProtocol: URLProtocol {
guard let requestHandler = Self.requestHandler else { return }
do {
let (data, response) = try requestHandler(request)
client?.urlProtocol(self,
didReceive: response,
cacheStoragePolicy: .notAllowed)
client?.urlProtocol(
self,
didReceive: response,
cacheStoragePolicy: .notAllowed
)
if let data {
client?.urlProtocol(self, didLoad: data)
}
Expand Down
20 changes: 12 additions & 8 deletions Tests/MultipartFormDataParserTests/_Util/TestStub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ private let uploadTestStubResponse: StubURLProtocol.RequestHandler = { request i
let errorResponse = { (message: String) -> (Data?, HTTPURLResponse) in
(
Data(#"{"status": 403, "error": "\#(message)"}"#.utf8),
HTTPURLResponse(url: request.url!,
statusCode: 403,
httpVersion: "HTTP/2",
headerFields: ["Content-Type": "application/json"])!
HTTPURLResponse(
url: request.url!,
statusCode: 403,
httpVersion: "HTTP/2",
headerFields: ["Content-Type": "application/json"]
)!
)
}
do {
Expand All @@ -41,10 +43,12 @@ private let uploadTestStubResponse: StubURLProtocol.RequestHandler = { request i
guard message.string == "Hello world!" else { return errorResponse("Unexpected message: \(message)") }
return (
#"{"status": 200}"#.data(using: .utf8),
HTTPURLResponse(url: request.url!,
statusCode: 200,
httpVersion: "HTTP/2",
headerFields: ["Content-Type": "application/json"])!
HTTPURLResponse(
url: request.url!,
statusCode: 200,
httpVersion: "HTTP/2",
headerFields: ["Content-Type": "application/json"]
)!
)
} catch {
return errorResponse(error.localizedDescription)
Expand Down

0 comments on commit f8490a8

Please sign in to comment.