Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Jan 11, 2024
1 parent d7a592b commit 1b7e7b9
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 805 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AWSClientRuntime
import AwsCommonRuntimeKit
import ClientRuntime

public class MockHttpClientEngine: HttpClientEngine {
public class MockHttpClientEngine: HTTPClient {

// Public initializer
public init() {}
Expand All @@ -33,7 +33,7 @@ public class MockHttpClientEngine: HttpClientEngine {
)
}

public func execute(request: SdkHttpRequest) async throws -> HttpResponse {
public func send(request: SdkHttpRequest) async throws -> HttpResponse {
return successHttpResponse(request: request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ final class S3StreamTests: S3XCTestCase {
case .data(let dataOrNil):
let data = try XCTUnwrap(dataOrNil)
let actual = String(data: data, encoding: .utf8)
XCTAssertEqual(actual, expected)
XCTAssertEqual(expected, actual)
case .stream(let stream):
let actual = String(data: try await stream.readToEndAsync()!, encoding: .utf8)
XCTAssertEqual(actual, expected)
let actual = String(data: try await stream.readToEndAsync() ?? Data(), encoding: .utf8)
XCTAssertEqual(expected, actual)
case .noStream:
XCTFail("Expected stream")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class S3XCTestCase: XCTestCase {
let data = try XCTUnwrap(dataOrNil)
return String(data: data, encoding: .utf8)
case .stream(let stream):
return String(data: try await stream.readToEndAsync()!, encoding: .utf8)
return String(data: try await stream.readToEndAsync() ?? Data(), encoding: .utf8)
case .noStream:
return nil
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/Core/AWSClientRuntime/Errors/RestXMLError+AWS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ extension RestXMLError {
/// - Returns: A`RestXMLError` instance with an error code of "NotFound" if the response body is empty and the status code is 404. Otherwise returns a `RestXMLError` by calling ``RestXMLError.init(httpResponse: HttpResponse)``.
///
/// - Throws: An error if it fails to decode the response body.

Check warning on line 17 in Sources/Core/AWSClientRuntime/Errors/RestXMLError+AWS.swift

View workflow job for this annotation

GitHub Actions / swiftlint

A doc comment should be attached to a declaration (orphaned_doc_comment)
public static func makeError(from response: HttpResponse) async throws -> RestXMLError {
response.statusCodeIsNotFoundAndBodyIsEmpty
? .makeNotFoundError(requestID: response.requestId)
: try await .init(httpResponse: response)
}

static func makeNotFoundError(requestID: String?) -> RestXMLError {
return RestXMLError(errorCode: "NotFound", requestId: requestID)
}
// public static func makeError(from httpResponse: HttpResponse, reader: SmithyXML.Reader) async throws -> RestXMLError {
// response.statusCodeIsNotFoundAndBodyIsEmpty
// ? .makeNotFoundError(requestID: response.requestId)
// : try await .init(reader, )
// }
//
// static func makeNotFoundError(requestID: String?) -> RestXMLError {
// return RestXMLError(code: "NotFound", type: "Sender", requestID: requestID)
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public struct AWSS3ErrorWith200StatusXMLMiddleware<OperationStackOutput>: Middle
guard let data = try await response.httpResponse.body.readData() else {
return response
}
response.httpResponse.body = .data(data)

let xmlString = String(data: data, encoding: .utf8) ?? ""
if xmlString.contains("<Error>") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
import ClientRuntime

public struct Ec2QueryError {
public let errorCode: String?
public let requestId: String?
public let message: String?
public let errorCode: String? = nil
public let requestId: String? = nil
public let message: String? = nil

public init(httpResponse: HttpResponse) async throws {
guard let data = try await httpResponse.body.readData() else {
errorCode = nil
requestId = nil
message = nil
// errorCode = nil
// requestId = nil
// message = nil
return
}
let decoded: Ec2Response = try XMLDecoder().decode(responseBody: data)
self.errorCode = decoded.errors.error.code
self.message = decoded.errors.error.message
self.requestId = decoded.requestId
#warning("FIXME")
// let decoded: Ec2Response = try XMLDecoder().decode(responseBody: data)
// self.errorCode = decoded.errors.error.code
// self.message = decoded.errors.error.message
// self.requestId = decoded.requestId
}
}
48 changes: 24 additions & 24 deletions Sources/Core/AWSClientRuntime/Protocols/RestXML/RestXMLError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
// SPDX-License-Identifier: Apache-2.0
//

import ClientRuntime
import class SmithyXML.Reader

public struct RestXMLError {
public let errorCode: String?
public let requestId: String?
public let code: String
public let message: String?
public let requestID: String

public init(httpResponse: HttpResponse) async throws {
guard let data = try await httpResponse.body.readData() else {
errorCode = nil
requestId = nil
message = nil
return
}
do {
let decoded: ErrorResponseContainer<RestXMLErrorPayload>
decoded = try XMLDecoder().decode(responseBody: data)
self.errorCode = decoded.error.errorCode
self.message = decoded.error.message
self.requestId = decoded.requestId
} catch {
let decoded: RestXMLErrorNoErrorWrappingPayload = try XMLDecoder().decode(responseBody: data)
self.errorCode = decoded.errorCode
self.message = decoded.message
self.requestId = decoded.requestId
public static func errorBodyReader(responseReader: Reader, noErrorWrapping: Bool) -> Reader {
noErrorWrapping ? responseReader : responseReader["Error"]
}

public init(responseReader: Reader, noErrorWrapping: Bool) throws {
let reader = Self.errorBodyReader(responseReader: responseReader, noErrorWrapping: noErrorWrapping)
let code: String? = try reader["Code"].readIfPresent()
let message: String? = try reader["Message"].readIfPresent()
let requestID: String? = try reader["RequestId"].readIfPresent()
guard let code, let requestID else {
throw RestXMLDecodeError.missingRequiredData
}
self.code = code
self.message = message
self.requestID = requestID
}

public init(errorCode: String? = nil, requestId: String? = nil, message: String? = nil) {
self.errorCode = errorCode
self.requestId = requestId
public init(code: String, message: String?, requestID: String) {
self.code = code
self.message = message
self.requestID = requestID
}
}

public enum RestXMLDecodeError: Error {
case missingRequiredData
}
Loading

0 comments on commit 1b7e7b9

Please sign in to comment.