Skip to content

Commit 715ac57

Browse files
authored
Merge pull request #11 from mattpolzin/ephemeral-request-cache
give the session for test requests an ephemeral (in memory) cache.
2 parents 6addb7d + 1290241 commit 715ac57

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Sources/JSONAPISwiftGen/Swift Generators/Test Generators/APIRequestTestSwiftGen.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ public struct APIRequestTestSwiftGen: SwiftGenerator {
241241

242242
private let makeTestRequestFunc = #"""
243243
244+
/// A session stored globally that does not cache responses on disk.
245+
let session = URLSession(
246+
configuration: .ephemeral
247+
)
248+
244249
/// Log warning after test case logs
245250
func XCTWarn(_ message: String, at url: URL) {
246251
print("[\(url.absoluteString)] : warning - \(message)")
@@ -401,7 +406,7 @@ func makeTestRequest<RequestBody>(
401406
completionExpectation.fulfill()
402407
}
403408
404-
let task = URLSession.shared.dataTask(with: request, completionHandler: taskCompletion)
409+
let task = session.dataTask(with: request, completionHandler: taskCompletion)
405410
task.resume()
406411
407412
XCTWaiter().wait(for: [completionExpectation], timeout: 5)

Tests/JSONAPISwiftGenTests/APIRequestTestSwiftGenTests.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ final class APIRequestTestSwiftGenTests: XCTestCase {
1818
}
1919

2020
// MARK: - START - Function written to generated test suites
21+
/// A session stored globally that does not cache responses on disk.
22+
let session = URLSession(
23+
configuration: .ephemeral
24+
)
25+
2126
/// Log warning after test case logs
2227
func XCTWarn(_ message: String, at url: URL) {
2328
print("[\(url.absoluteString)] : warning - \(message)")
@@ -178,7 +183,7 @@ func makeTestRequest<RequestBody>(
178183
completionExpectation.fulfill()
179184
}
180185

181-
let task = URLSession.shared.dataTask(with: request, completionHandler: taskCompletion)
186+
let task = session.dataTask(with: request, completionHandler: taskCompletion)
182187
task.resume()
183188

184189
XCTWaiter().wait(for: [completionExpectation], timeout: 5)

0 commit comments

Comments
 (0)