Skip to content

Commit a4904fc

Browse files
Add missing availability guards in tests (#719)
## Motivation Some of the test code was missing availability guards for Apple platforms, resulting in build failures for these platforms, e.g. ``` error: 'AsyncSequence' is only available in iOS 13.0 or newer ``` ## Modifications Add missing availability guards. I've tried to keep them as scoped as possible. ## Result Tests can now build for run on iOS and other Apple platforms.
1 parent d2d3566 commit a4904fc

File tree

9 files changed

+10
-61
lines changed

9 files changed

+10
-61
lines changed

Sources/AsyncHTTPClient/NIOTransportServices/TLSConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extension TLSVersion {
5757
}
5858
}
5959

60-
@available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
60+
@available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 5.0, *)
6161
extension TLSConfiguration {
6262
/// Dispatch queue used by Network framework TLS to control certificate verification
6363
static var tlsDispatchQueue = DispatchQueue(label: "TLSDispatch")

Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private func makeDefaultHTTPClient(
3333
)
3434
}
3535

36+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
3637
final class AsyncAwaitEndToEndTests: XCTestCase {
3738
var clientGroup: EventLoopGroup!
3839
var serverGroup: EventLoopGroup!
@@ -56,7 +57,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
5657
}
5758

5859
func testSimpleGet() {
59-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
6060
XCTAsyncTest {
6161
let bin = HTTPBin(.http2(compress: false))
6262
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -77,7 +77,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
7777
}
7878

7979
func testSimplePost() {
80-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
8180
XCTAsyncTest {
8281
let bin = HTTPBin(.http2(compress: false))
8382
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -98,7 +97,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
9897
}
9998

10099
func testPostWithByteBuffer() {
101-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
102100
XCTAsyncTest {
103101
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
104102
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -121,7 +119,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
121119
}
122120

123121
func testPostWithSequenceOfUInt8() {
124-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
125122
XCTAsyncTest {
126123
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
127124
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -144,7 +141,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
144141
}
145142

146143
func testPostWithCollectionOfUInt8() {
147-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
148144
XCTAsyncTest {
149145
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
150146
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -167,7 +163,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
167163
}
168164

169165
func testPostWithRandomAccessCollectionOfUInt8() {
170-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
171166
XCTAsyncTest {
172167
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
173168
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -190,7 +185,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
190185
}
191186

192187
func testPostWithAsyncSequenceOfByteBuffers() {
193-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
194188
XCTAsyncTest {
195189
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
196190
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -217,7 +211,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
217211
}
218212

219213
func testPostWithAsyncSequenceOfUInt8() {
220-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
221214
XCTAsyncTest {
222215
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
223216
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -240,7 +233,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
240233
}
241234

242235
func testPostWithFragmentedAsyncSequenceOfByteBuffers() {
243-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
244236
XCTAsyncTest {
245237
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
246238
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -280,7 +272,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
280272
}
281273

282274
func testPostWithFragmentedAsyncSequenceOfLargeByteBuffers() {
283-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
284275
XCTAsyncTest {
285276
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
286277
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -321,7 +312,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
321312
}
322313

323314
func testCanceling() {
324-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
325315
XCTAsyncTest(timeout: 5) {
326316
let bin = HTTPBin(.http2(compress: false))
327317
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -344,7 +334,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
344334
}
345335

346336
func testCancelingResponseBody() {
347-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
348337
XCTAsyncTest(timeout: 5) {
349338
let bin = HTTPBin(.http2(compress: false)) { _ in
350339
HTTPEchoHandler()
@@ -373,7 +362,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
373362
}
374363

375364
func testDeadline() {
376-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
377365
XCTAsyncTest(timeout: 5) {
378366
let bin = HTTPBin(.http2(compress: false))
379367
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -398,7 +386,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
398386
}
399387

400388
func testImmediateDeadline() {
401-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
402389
XCTAsyncTest(timeout: 5) {
403390
let bin = HTTPBin(.http2(compress: false))
404391
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -423,7 +410,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
423410
}
424411

425412
func testConnectTimeout() {
426-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
427413
XCTAsyncTest(timeout: 60) {
428414
#if os(Linux)
429415
// 198.51.100.254 is reserved for documentation only and therefore should not accept any TCP connection
@@ -480,7 +466,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
480466
}
481467

482468
func testSelfSignedCertificateIsRejectedWithCorrectErrorIfRequestDeadlineIsExceeded() {
483-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
484469
XCTAsyncTest(timeout: 5) {
485470
/// key + cert was created with the follwing command:
486471
/// openssl req -x509 -newkey rsa:4096 -keyout self_signed_key.pem -out self_signed_cert.pem -sha256 -days 99999 -nodes -subj '/CN=localhost'
@@ -526,7 +511,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
526511
}
527512

528513
func testDnsOverride() {
529-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
530514
XCTAsyncTest(timeout: 5) {
531515
/// key + cert was created with the following code (depends on swift-certificates)
532516
/// ```
@@ -584,7 +568,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
584568
}
585569

586570
func testInvalidURL() {
587-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
588571
XCTAsyncTest(timeout: 5) {
589572
let client = makeDefaultHTTPClient()
590573
defer { XCTAssertNoThrow(try client.syncShutdown()) }
@@ -598,7 +581,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
598581
}
599582

600583
func testRedirectChangesHostHeader() {
601-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
602584
XCTAsyncTest {
603585
let bin = HTTPBin(.http2(compress: false))
604586
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -625,7 +607,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
625607
}
626608

627609
func testShutdown() {
628-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
629610
XCTAsyncTest {
630611
let client = makeDefaultHTTPClient()
631612
try await client.shutdown()
@@ -637,7 +618,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
637618

638619
/// Regression test for https://github.com/swift-server/async-http-client/issues/612
639620
func testCancelingBodyDoesNotCrash() {
640-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
641621
XCTAsyncTest {
642622
let client = makeDefaultHTTPClient()
643623
defer { XCTAssertNoThrow(try client.syncShutdown()) }
@@ -654,7 +634,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
654634
}
655635

656636
func testAsyncSequenceReuse() {
657-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
658637
XCTAsyncTest {
659638
let bin = HTTPBin(.http2(compress: false)) { _ in HTTPEchoHandler() }
660639
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -698,7 +677,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
698677
}
699678

700679
private func _rejectsInvalidCharactersInHeaderFieldNames(mode: HTTPBin<HTTPBinHandler>.Mode) {
701-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
702680
XCTAsyncTest {
703681
let bin = HTTPBin(mode)
704682
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -759,7 +737,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
759737
}
760738

761739
private func _rejectsInvalidCharactersInHeaderFieldValues(mode: HTTPBin<HTTPBinHandler>.Mode) {
762-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
763740
XCTAsyncTest {
764741
let bin = HTTPBin(mode)
765742
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -818,7 +795,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
818795
}
819796

820797
func testUsingGetMethodInsteadOfWait() {
821-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
822798
XCTAsyncTest {
823799
let bin = HTTPBin(.http2(compress: false))
824800
defer { XCTAssertNoThrow(try bin.shutdown()) }
@@ -838,7 +814,6 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
838814
}
839815

840816
func testSimpleContentLengthErrorNoBody() {
841-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
842817
XCTAsyncTest {
843818
let bin = HTTPBin(.http2(compress: false))
844819
defer { XCTAssertNoThrow(try bin.shutdown()) }

Tests/AsyncHTTPClientTests/HTTPClientRequestTests.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ import Algorithms
1717
import NIOCore
1818
import XCTest
1919

20+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2021
class HTTPClientRequestTests: XCTestCase {
21-
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2222
private typealias Request = HTTPClientRequest
2323

24-
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2524
private typealias PreparedRequest = HTTPClientRequest.Prepared
2625

2726
func testCustomHeadersAreRespected() {
28-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
2927
XCTAsyncTest {
3028
var request = Request(url: "https://example.com/get")
3129
request.headers = [
@@ -60,7 +58,6 @@ class HTTPClientRequestTests: XCTestCase {
6058
}
6159

6260
func testUnixScheme() {
63-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
6461
XCTAsyncTest {
6562
var request = Request(url: "unix://%2Fexample%2Ffolder.sock/some_path")
6663
request.headers = ["custom-header": "custom-value"]
@@ -90,7 +87,6 @@ class HTTPClientRequestTests: XCTestCase {
9087
}
9188

9289
func testHTTPUnixScheme() {
93-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
9490
XCTAsyncTest {
9591
var request = Request(url: "http+unix://%2Fexample%2Ffolder.sock/some_path")
9692
request.headers = ["custom-header": "custom-value"]
@@ -120,7 +116,6 @@ class HTTPClientRequestTests: XCTestCase {
120116
}
121117

122118
func testHTTPSUnixScheme() {
123-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
124119
XCTAsyncTest {
125120
var request = Request(url: "https+unix://%2Fexample%2Ffolder.sock/some_path")
126121
request.headers = ["custom-header": "custom-value"]
@@ -150,7 +145,6 @@ class HTTPClientRequestTests: XCTestCase {
150145
}
151146

152147
func testGetWithoutBody() {
153-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
154148
XCTAsyncTest {
155149
let request = Request(url: "https://example.com/get")
156150
var preparedRequest: PreparedRequest?
@@ -179,7 +173,6 @@ class HTTPClientRequestTests: XCTestCase {
179173
}
180174

181175
func testPostWithoutBody() {
182-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
183176
XCTAsyncTest {
184177
var request = Request(url: "http://example.com/post")
185178
request.method = .POST
@@ -213,7 +206,6 @@ class HTTPClientRequestTests: XCTestCase {
213206
}
214207

215208
func testPostWithEmptyByteBuffer() {
216-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
217209
XCTAsyncTest {
218210
var request = Request(url: "http://example.com/post")
219211
request.method = .POST
@@ -248,7 +240,6 @@ class HTTPClientRequestTests: XCTestCase {
248240
}
249241

250242
func testPostWithByteBuffer() {
251-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
252243
XCTAsyncTest {
253244
var request = Request(url: "http://example.com/post")
254245
request.method = .POST
@@ -282,7 +273,6 @@ class HTTPClientRequestTests: XCTestCase {
282273
}
283274

284275
func testPostWithSequenceOfUnknownLength() {
285-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
286276
XCTAsyncTest {
287277
var request = Request(url: "http://example.com/post")
288278
request.method = .POST
@@ -317,7 +307,6 @@ class HTTPClientRequestTests: XCTestCase {
317307
}
318308

319309
func testPostWithSequenceWithFixedLength() {
320-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
321310
XCTAsyncTest {
322311
var request = Request(url: "http://example.com/post")
323312
request.method = .POST
@@ -353,7 +342,6 @@ class HTTPClientRequestTests: XCTestCase {
353342
}
354343

355344
func testPostWithRandomAccessCollection() {
356-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
357345
XCTAsyncTest {
358346
var request = Request(url: "http://example.com/post")
359347
request.method = .POST
@@ -388,7 +376,6 @@ class HTTPClientRequestTests: XCTestCase {
388376
}
389377

390378
func testPostWithAsyncSequenceOfUnknownLength() {
391-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
392379
XCTAsyncTest {
393380
var request = Request(url: "http://example.com/post")
394381
request.method = .POST
@@ -428,7 +415,6 @@ class HTTPClientRequestTests: XCTestCase {
428415
}
429416

430417
func testPostWithAsyncSequenceWithKnownLength() {
431-
guard #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) else { return }
432418
XCTAsyncTest {
433419
var request = Request(url: "http://example.com/post")
434420
request.method = .POST
@@ -602,6 +588,7 @@ class HTTPClientRequestTests: XCTestCase {
602588
}
603589
}
604590

591+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
605592
extension AsyncSequence {
606593
func collect() async throws -> [Element] {
607594
try await self.reduce(into: []) { $0 += CollectionOfOne($1) }

Tests/AsyncHTTPClientTests/HTTPClientResponseTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Logging
1717
import NIOCore
1818
import XCTest
1919

20+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2021
final class HTTPClientResponseTests: XCTestCase {
2122
func testSimpleResponse() {
2223
let response = HTTPClientResponse.expectedContentLength(requestMethod: .GET, headers: ["content-length": "1025"], status: .ok)

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3526,6 +3526,7 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
35263526
XCTAssertEqual(.ok, response.status)
35273527
}
35283528

3529+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
35293530
func testAsyncExecuteWithCustomTLS() async throws {
35303531
let httpsBin = HTTPBin(.http1_1(ssl: true))
35313532
defer {

Tests/AsyncHTTPClientTests/NWWaitingHandlerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import NIOSSL
2121
import NIOTransportServices
2222
import XCTest
2323

24-
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
24+
@available(macOS 10.14, iOS 12.0, tvOS 12.0, watchOS 5.0, *)
2525
class NWWaitingHandlerTests: XCTestCase {
2626
class MockRequester: HTTPConnectionRequester {
2727
var waitingForConnectivityCalled = false

0 commit comments

Comments
 (0)