Skip to content

Commit

Permalink
Adjust test for session creation swapping
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmichel committed Jan 18, 2024
1 parent ec204ce commit c1e733d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"package": "swift-anyurlsession",
"repositoryURL": "https://github.com/thebrowsercompany/AnyURLSession",
"state": {
"branch": "2542851",
"revision": "25428518a4bdc044c20bef370225a83b745f6426",
"branch": "9b8e39b",
"revision": "9b8e39b95f8290909b976619eb00dc8c9ba472bf",
"version": null
}
}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 23 additions & 0 deletions Tests/LDSwiftEventSourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import XCTest

#if os(Linux) || os(Windows)
import FoundationNetworking
import AnyURLSession
#endif

final class LDSwiftEventSourceTests: XCTestCase {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1e733d

Please sign in to comment.