@@ -24,7 +24,7 @@ import XCTest
24
24
25
25
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
26
26
class URLSessionTransportConverterTests : XCTestCase {
27
- static override func setUp( ) { OpenAPIURLSession . debugLoggingEnabled = true }
27
+ static override func setUp( ) { OpenAPIURLSession . debugLoggingEnabled = false }
28
28
29
29
func testRequestConversion( ) async throws {
30
30
let request = HTTPRequest (
@@ -58,7 +58,7 @@ class URLSessionTransportConverterTests: XCTestCase {
58
58
class URLSessionTransportBufferedTests : XCTestCase {
59
59
var transport : ( any ClientTransport ) !
60
60
61
- static override func setUp( ) { OpenAPIURLSession . debugLoggingEnabled = true }
61
+ static override func setUp( ) { OpenAPIURLSession . debugLoggingEnabled = false }
62
62
63
63
override func setUp( ) async throws {
64
64
transport = URLSessionTransport ( configuration: . init( implementation: . buffering) )
@@ -91,7 +91,7 @@ class URLSessionTransportBufferedTests: XCTestCase {
91
91
class URLSessionTransportStreamingTests : XCTestCase {
92
92
var transport : ( any ClientTransport ) !
93
93
94
- static override func setUp( ) { OpenAPIURLSession . debugLoggingEnabled = true }
94
+ static override func setUp( ) { OpenAPIURLSession . debugLoggingEnabled = false }
95
95
96
96
override func setUpWithError( ) throws {
97
97
try XCTSkipUnless ( URLSessionTransport . Configuration. Implementation. platformSupportsStreaming)
@@ -165,43 +165,43 @@ func testHTTPRedirect(
165
165
while let requestPart = try await requestPartIterator. next ( ) {
166
166
switch requestPart {
167
167
case . head( let head) :
168
- print ( " Server received head for \( head. uri) " )
168
+ debug ( " Server received head for \( head. uri) " )
169
169
currentURI = head. uri
170
170
case . body( let buffer) :
171
171
let currentURI = try XCTUnwrap ( currentURI)
172
- print ( " Server received body bytes for \( currentURI) (numBytes: \( buffer. readableBytes) ) " )
172
+ debug ( " Server received body bytes for \( currentURI) (numBytes: \( buffer. readableBytes) ) " )
173
173
accumulatedBody. writeImmutableBuffer ( buffer)
174
174
case . end:
175
175
let currentURI = try XCTUnwrap ( currentURI)
176
- print ( " Server received end for \( currentURI) " )
176
+ debug ( " Server received end for \( currentURI) " )
177
177
XCTAssertEqual ( accumulatedBody, ByteBuffer ( string: requestBodyChunks. joined ( ) ) )
178
178
switch currentURI {
179
179
case " /old " :
180
- print ( " Server reseting body buffer " )
180
+ debug ( " Server reseting body buffer " )
181
181
accumulatedBody = ByteBuffer ( )
182
182
try await outbound. write (
183
183
. head(
184
184
. init( version: . http1_1, status: . temporaryRedirect, headers: [ " Location " : " /new " ] )
185
185
)
186
186
)
187
- print ( " Server sent head for \( currentURI) " )
187
+ debug ( " Server sent head for \( currentURI) " )
188
188
try await outbound. write ( . end( nil ) )
189
- print ( " Server sent end for \( currentURI) " )
189
+ debug ( " Server sent end for \( currentURI) " )
190
190
case " /new " :
191
191
try await outbound. write ( . head( . init( version: . http1_1, status: . ok) ) )
192
- print ( " Server sent head for \( currentURI) " )
192
+ debug ( " Server sent head for \( currentURI) " )
193
193
try await outbound. write ( . end( nil ) )
194
- print ( " Server sent end for \( currentURI) " )
194
+ debug ( " Server sent end for \( currentURI) " )
195
195
default : preconditionFailure ( )
196
196
}
197
197
}
198
198
}
199
199
}
200
200
}
201
- print ( " Server running on 127.0.0.1: \( serverPort) " )
201
+ debug ( " Server running on 127.0.0.1: \( serverPort) " )
202
202
203
203
// Send the request.
204
- print ( " Client starting request " )
204
+ debug ( " Client starting request " )
205
205
if expectFailureDueToIterationBehavior {
206
206
await XCTAssertThrowsError (
207
207
try await transport. send (
@@ -218,7 +218,7 @@ func testHTTPRedirect(
218
218
baseURL: URL ( string: " http://127.0.0.1: \( serverPort) " ) !,
219
219
operationID: " unused "
220
220
)
221
- print ( " Client received response head: \( response) " )
221
+ debug ( " Client received response head: \( response) " )
222
222
XCTAssertEqual ( response. status, . ok)
223
223
}
224
224
@@ -248,17 +248,17 @@ func testHTTPBasicGet(transport: any ClientTransport) async throws {
248
248
}
249
249
}
250
250
}
251
- print ( " Server running on 127.0.0.1: \( serverPort) " )
251
+ debug ( " Server running on 127.0.0.1: \( serverPort) " )
252
252
253
253
// Send the request.
254
- print ( " Client starting request " )
254
+ debug ( " Client starting request " )
255
255
let ( response, maybeResponseBody) = try await transport. send (
256
256
HTTPRequest ( method: . get, scheme: nil , authority: nil , path: requestPath) ,
257
257
body: nil ,
258
258
baseURL: URL ( string: " http://127.0.0.1: \( serverPort) " ) !,
259
259
operationID: " unused "
260
260
)
261
- print ( " Client received response head: \( response) " )
261
+ debug ( " Client received response head: \( response) " )
262
262
XCTAssertEqual( response. status, . ok)
263
263
let receivedMessage = try await String ( collecting: try XCTUnwrap ( maybeResponseBody) , upTo: . max)
264
264
XCTAssertEqual( receivedMessage, responseBodyMessage)
@@ -292,21 +292,46 @@ func testHTTPBasicPost(transport: any ClientTransport) async throws {
292
292
}
293
293
}
294
294
}
295
- print ( " Server running on 127.0.0.1: \( serverPort) " )
295
+ debug ( " Server running on 127.0.0.1: \( serverPort) " )
296
296
297
297
// Send the request.
298
- print ( " Client starting request " )
298
+ debug ( " Client starting request " )
299
299
let ( response, maybeResponseBody) = try await transport. send (
300
300
HTTPRequest ( method: . post, scheme: nil , authority: nil , path: requestPath) ,
301
301
body: HTTPBody ( requestBodyMessage) ,
302
302
baseURL: URL ( string: " http://127.0.0.1: \( serverPort) " ) !,
303
303
operationID: " unused "
304
304
)
305
- print ( " Client received response head: \( response) " )
305
+ debug ( " Client received response head: \( response) " )
306
306
XCTAssertEqual( response. status, . ok)
307
307
let receivedMessage = try await String ( collecting: try XCTUnwrap ( maybeResponseBody) , upTo: . max)
308
308
XCTAssertEqual( receivedMessage, responseBodyMessage)
309
309
310
310
group. cancelAll ( )
311
311
}
312
312
}
313
+
314
+ class URLSessionTransportDebugLoggingTests: XCTestCase {
315
+ func testDebugLoggingEnabled( ) async throws {
316
+ let expectation = expectation ( description: " message autoclosure evaluated " )
317
+ func message( ) -> String {
318
+ expectation. fulfill ( )
319
+ return " message "
320
+ }
321
+ OpenAPIURLSession . debugLoggingEnabled = true
322
+ debug ( message ( ) )
323
+ await fulfillment ( of: [ expectation] , timeout: 0 )
324
+ }
325
+
326
+ func testDebugLoggingDisabled( ) async throws {
327
+ let expectation = expectation ( description: " message autoclosure evaluated " )
328
+ expectation. isInverted = true
329
+ func message( ) -> String {
330
+ expectation. fulfill ( )
331
+ return " message "
332
+ }
333
+ OpenAPIURLSession . debugLoggingEnabled = false
334
+ debug ( message ( ) )
335
+ await fulfillment ( of: [ expectation] , timeout: 0 )
336
+ }
337
+ }
0 commit comments