Skip to content

Commit

Permalink
Fix empty implementation to work across platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmichel committed Jan 7, 2024
1 parent af57e84 commit 13308fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
18 changes: 0 additions & 18 deletions Sources/_Helpers/Response.swift

This file was deleted.

15 changes: 14 additions & 1 deletion Tests/AuthTests/RequestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ final class RequestsTests: XCTestCase {
let sut = makeSUT(fetch: { request in
let authorizationHeader = request.allHTTPHeaderFields?["Authorization"]
XCTAssertEqual(authorizationHeader, "bearer accesstoken")
return (json(named: "user"), HTTPURLResponse())
return (json(named: "user"), HTTPURLResponse.empty())
})

let currentDate = Date()
Expand Down Expand Up @@ -436,3 +436,16 @@ final class RequestsTests: XCTestCase {
)
}
}

extension HTTPURLResponse {
// Windows and Linux don't have the ability to empty initialize a URLResponse like `URLResponse()` so
// We provide a function that can give us the right value on an platform.
// See https://github.com/apple/swift-corelibs-foundation/pull/4778
fileprivate static func empty() -> URLResponse {
#if os(Windows) || os(Linux)
URLResponse(url: .init(string: "https://supabase.com")!, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
#else
URLResponse()
#endif
}
}
13 changes: 10 additions & 3 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,14 @@ final class BuildURLRequestTests: XCTestCase {
}

extension URLResponse {
static func empty() -> URLResponse {
URLResponse(url: .init(string: "https://arc.net")!, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
}
// Windows and Linux don't have the ability to empty initialize a URLResponse like `URLResponse()` so
// We provide a function that can give us the right value on an platform.
// See https://github.com/apple/swift-corelibs-foundation/pull/4778
fileprivate static func empty() -> URLResponse {
#if os(Windows) || os(Linux)
URLResponse(url: .init(string: "https://supabase.com")!, mimeType: nil, expectedContentLength: 0, textEncodingName: nil)
#else
URLResponse()
#endif
}
}

0 comments on commit 13308fb

Please sign in to comment.