|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the AsyncHTTPClient open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2021 Apple Inc. and the AsyncHTTPClient project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +@testable import AsyncHTTPClient |
| 16 | +import Logging |
| 17 | +import NIO |
| 18 | +import NIOHTTP1 |
| 19 | + |
| 20 | +class MockHTTPRequestTask: HTTPRequestTask { |
| 21 | + let eventLoopPreference: HTTPClient.EventLoopPreference |
| 22 | + let logger: Logger |
| 23 | + let connectionDeadline: NIODeadline |
| 24 | + let idleReadTimeout: TimeAmount? |
| 25 | + |
| 26 | + init(eventLoop: EventLoop, |
| 27 | + logger: Logger = Logger(label: "mock"), |
| 28 | + connectionTimeout: TimeAmount = .seconds(60), |
| 29 | + idleReadTimeout: TimeAmount? = nil, |
| 30 | + requiresEventLoopForChannel: Bool = false) { |
| 31 | + self.logger = logger |
| 32 | + |
| 33 | + self.connectionDeadline = .now() + connectionTimeout |
| 34 | + self.idleReadTimeout = idleReadTimeout |
| 35 | + |
| 36 | + if requiresEventLoopForChannel { |
| 37 | + self.eventLoopPreference = .delegateAndChannel(on: eventLoop) |
| 38 | + } else { |
| 39 | + self.eventLoopPreference = .delegate(on: eventLoop) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + var eventLoop: EventLoop { |
| 44 | + switch self.eventLoopPreference.preference { |
| 45 | + case .indifferent, .testOnly_exact: |
| 46 | + preconditionFailure("Unimplemented") |
| 47 | + case .delegate(on: let eventLoop), .delegateAndChannel(on: let eventLoop): |
| 48 | + return eventLoop |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + func requestWasQueued(_: HTTP1RequestQueuer) { |
| 53 | + preconditionFailure("Unimplemented") |
| 54 | + } |
| 55 | + |
| 56 | + func willBeExecutedOnConnection(_: HTTPConnectionPool.Connection) { |
| 57 | + preconditionFailure("Unimplemented") |
| 58 | + } |
| 59 | + |
| 60 | + func willExecuteRequest(_: HTTP1RequestExecutor) -> Bool { |
| 61 | + preconditionFailure("Unimplemented") |
| 62 | + } |
| 63 | + |
| 64 | + func requestHeadSent(_: HTTPRequestHead) { |
| 65 | + preconditionFailure("Unimplemented") |
| 66 | + } |
| 67 | + |
| 68 | + func startRequestBodyStream() { |
| 69 | + preconditionFailure("Unimplemented") |
| 70 | + } |
| 71 | + |
| 72 | + func pauseRequestBodyStream() { |
| 73 | + preconditionFailure("Unimplemented") |
| 74 | + } |
| 75 | + |
| 76 | + func resumeRequestBodyStream() { |
| 77 | + preconditionFailure("Unimplemented") |
| 78 | + } |
| 79 | + |
| 80 | + var request: HTTPClient.Request { |
| 81 | + preconditionFailure("Unimplemented") |
| 82 | + } |
| 83 | + |
| 84 | + func nextRequestBodyPart(channelEL: EventLoop) -> EventLoopFuture<IOData?> { |
| 85 | + preconditionFailure("Unimplemented") |
| 86 | + } |
| 87 | + |
| 88 | + func didSendRequestHead(_: HTTPRequestHead) { |
| 89 | + preconditionFailure("Unimplemented") |
| 90 | + } |
| 91 | + |
| 92 | + func didSendRequestPart(_: IOData) { |
| 93 | + preconditionFailure("Unimplemented") |
| 94 | + } |
| 95 | + |
| 96 | + func didSendRequest() { |
| 97 | + preconditionFailure("Unimplemented") |
| 98 | + } |
| 99 | + |
| 100 | + func receiveResponseHead(_: HTTPResponseHead) { |
| 101 | + preconditionFailure("Unimplemented") |
| 102 | + } |
| 103 | + |
| 104 | + func receiveResponseBodyPart(_: ByteBuffer) { |
| 105 | + preconditionFailure("Unimplemented") |
| 106 | + } |
| 107 | + |
| 108 | + func receiveResponseEnd() { |
| 109 | + preconditionFailure("Unimplemented") |
| 110 | + } |
| 111 | + |
| 112 | + func fail(_: Error) { |
| 113 | + preconditionFailure("Unimplemented") |
| 114 | + } |
| 115 | +} |
0 commit comments