Skip to content

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfett committed Aug 19, 2021
1 parent 23944a3 commit f16b170
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ class CodableLambdaTest: XCTestCase {
XCTAssertNil(outputBuffer)
}

func testCodableEventLoopFutureHandler() {
let request = Request(requestId: UUID().uuidString)
var inputBuffer: ByteBuffer?
var outputBuffer: ByteBuffer?
var response: Response?

struct Handler: EventLoopLambdaHandler {
typealias In = Request
typealias Out = Response

let expected: Request

func handle(context: Lambda.Context, event: Request) -> EventLoopFuture<Response> {
XCTAssertEqual(event, self.expected)
return context.eventLoop.makeSucceededFuture(Response(requestId: event.requestId))
}
}

let handler = Handler(expected: request)

XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
XCTAssertNoThrow(outputBuffer = try handler.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
XCTAssertEqual(response?.requestId, request.requestId)
}

#if swift(>=5.5)
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
func testCodableVoidHandler() {
struct Handler: LambdaHandler {
Expand Down Expand Up @@ -84,33 +111,7 @@ class CodableLambdaTest: XCTestCase {
XCTAssertNil(outputBuffer)
}
}

func testCodableEventLoopFutureHandler() {
let request = Request(requestId: UUID().uuidString)
var inputBuffer: ByteBuffer?
var outputBuffer: ByteBuffer?
var response: Response?

struct Handler: EventLoopLambdaHandler {
typealias In = Request
typealias Out = Response

let expected: Request

func handle(context: Lambda.Context, event: Request) -> EventLoopFuture<Response> {
XCTAssertEqual(event, self.expected)
return context.eventLoop.makeSucceededFuture(Response(requestId: event.requestId))
}
}

let handler = Handler(expected: request)

XCTAssertNoThrow(inputBuffer = try JSONEncoder().encode(request, using: self.allocator))
XCTAssertNoThrow(outputBuffer = try handler.handle(context: self.newContext(), event: XCTUnwrap(inputBuffer)).wait())
XCTAssertNoThrow(response = try JSONDecoder().decode(Response.self, from: XCTUnwrap(outputBuffer)))
XCTAssertEqual(response?.requestId, request.requestId)
}


@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
func testCodableHandler() {
struct Handler: LambdaHandler {
Expand Down Expand Up @@ -142,6 +143,7 @@ class CodableLambdaTest: XCTestCase {
XCTAssertEqual(response?.requestId, request.requestId)
}
}
#endif

// convencience method
func newContext() -> Lambda.Context {
Expand Down Expand Up @@ -177,6 +179,9 @@ private struct Response: Codable, Equatable {
}
}

#if swift(>=5.5)
// NOTE: workaround until we have async test support on linux
// https://github.com/apple/swift-corelibs-xctest/pull/326
extension XCTestCase {
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
public func XCTAsyncTest(
Expand All @@ -198,3 +203,4 @@ extension XCTestCase {
self.wait(for: [expectation], timeout: timeout)
}
}
#endif

0 comments on commit f16b170

Please sign in to comment.