From c1e733d5c98f2087198448651260380e1dd312e7 Mon Sep 17 00:00:00 2001 From: Brian Michel Date: Thu, 18 Jan 2024 11:24:03 -0500 Subject: [PATCH] Adjust test for session creation swapping --- Package.resolved | 4 ++-- Package.swift | 2 +- Tests/LDSwiftEventSourceTests.swift | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Package.resolved b/Package.resolved index a262adc..0e78e34 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "package": "swift-anyurlsession", "repositoryURL": "https://github.com/thebrowsercompany/AnyURLSession", "state": { - "branch": "2542851", - "revision": "25428518a4bdc044c20bef370225a83b745f6426", + "branch": "9b8e39b", + "revision": "9b8e39b95f8290909b976619eb00dc8c9ba472bf", "version": null } } diff --git a/Package.swift b/Package.swift index 9b007ce..175528d 100644 --- a/Package.swift +++ b/Package.swift @@ -14,7 +14,7 @@ let package = Package( .library(name: "LDSwiftEventSource", targets: ["LDSwiftEventSource"]), ], dependencies: [ - .package(url: "https://github.com/thebrowsercompany/AnyURLSession", revision: "2542851") + .package(url: "https://github.com/thebrowsercompany/AnyURLSession", revision: "9b8e39b") ], targets: [ .target( diff --git a/Tests/LDSwiftEventSourceTests.swift b/Tests/LDSwiftEventSourceTests.swift index e66b889..fd65be7 100644 --- a/Tests/LDSwiftEventSourceTests.swift +++ b/Tests/LDSwiftEventSourceTests.swift @@ -3,6 +3,7 @@ import XCTest #if os(Linux) || os(Windows) import FoundationNetworking +import AnyURLSession #endif final class LDSwiftEventSourceTests: XCTestCase { @@ -103,6 +104,28 @@ final class LDSwiftEventSourceTests: XCTestCase { } func testCreatedSession() { + #if os(Linux) || os(Windows) + final class TestURLSessionGuts: URLSessionGuts { + var configuration: URLSessionConfiguration + + init(configuration: URLSessionConfiguration, delegate: (any AnyURLSession.URLSessionDelegate)?, delegateQueue queue: OperationQueue?) { + self.configuration = configuration + } + + func uploadTask(with request: URLRequest, fromFile file: URL, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> AnyURLSession.URLSessionUploadTask { AnyURLSession.URLSessionUploadTask() } + func dataTask(with request: URLRequest) -> AnyURLSession.URLSessionDataTask { AnyURLSession.URLSessionDataTask() } + func dataTask(with request: URLRequest, completionHandler: @escaping @Sendable (Data?, URLResponse?, (any Error)?) -> Void) -> AnyURLSession.URLSessionDataTask { AnyURLSession.URLSessionDataTask() } + func invalidateAndCancel() {} + func finishTasksAndInvalidate() {} + } + + AnyURLSession.Dependencies.current.setValue( + Dependencies(gutsFactory: { (config, delegate, queue) in + TestURLSessionGuts(configuration: config, delegate: delegate, delegateQueue: queue) + }) + ) + + #endif let config = EventSource.Config(handler: mockHandler, url: URL(string: "abc")!) let session = EventSourceDelegate(config: config).createSession() XCTAssertEqual(session.configuration.timeoutIntervalForRequest, config.idleTimeout)