From 75aec63a20ea72bbb8ea92826ab669915a5728f2 Mon Sep 17 00:00:00 2001 From: Adam Young Date: Tue, 5 Nov 2024 21:55:44 +0000 Subject: [PATCH] Fix tests for Linux --- Makefile | 2 +- Sources/TMDb/Networking/TMDbAPIClient.swift | 4 ++++ .../Adapters/URLSessionHTTPClientAdapterTests.swift | 4 ++++ Tests/TMDbTests/Domain/Models/MovieTests.swift | 2 +- Tests/TMDbTests/Domain/Models/ShowTests.swift | 2 +- .../Networking/HTTPClient/MockURLProtocol.swift | 4 ++++ Tests/TMDbTests/Networking/TMDbAPIClientTests.swift | 10 +++++++++- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 534c757a..64487bbc 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ WATCHOS_DESINTATION = 'platform=watchOS Simulator,name=Apple Watch Series 9 (45m TVOS_DESTINATION = 'platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=18.0' VISIONOS_DESTINATION = 'platform=visionOS Simulator,name=Apple Vision Pro,OS=2.0' -SWIFT_CONTAINER_IMAGE = swiftlang/swift:nightly-6.0-jammy +SWIFT_CONTAINER_IMAGE = swift:6.0.2-jammy .PHONY: clean clean: diff --git a/Sources/TMDb/Networking/TMDbAPIClient.swift b/Sources/TMDb/Networking/TMDbAPIClient.swift index bda2ca15..6fa22ccc 100644 --- a/Sources/TMDb/Networking/TMDbAPIClient.swift +++ b/Sources/TMDb/Networking/TMDbAPIClient.swift @@ -19,6 +19,10 @@ import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif + final class TMDbAPIClient: APIClient, Sendable { private let apiKey: String diff --git a/Tests/TMDbTests/Adapters/URLSessionHTTPClientAdapterTests.swift b/Tests/TMDbTests/Adapters/URLSessionHTTPClientAdapterTests.swift index 20f9953e..ddd1c24c 100644 --- a/Tests/TMDbTests/Adapters/URLSessionHTTPClientAdapterTests.swift +++ b/Tests/TMDbTests/Adapters/URLSessionHTTPClientAdapterTests.swift @@ -17,6 +17,8 @@ // limitations under the License. // +#if !os(Linux) + import Foundation import Testing @testable import TMDb @@ -142,3 +144,5 @@ final class URLSessionHTTPClientAdapterTests { } } + +#endif diff --git a/Tests/TMDbTests/Domain/Models/MovieTests.swift b/Tests/TMDbTests/Domain/Models/MovieTests.swift index 8d1e3a1a..b574d59e 100644 --- a/Tests/TMDbTests/Domain/Models/MovieTests.swift +++ b/Tests/TMDbTests/Domain/Models/MovieTests.swift @@ -64,7 +64,7 @@ extension MovieTests { backdropPath: URL(string: "/fCayJrkfRaCRCTh8GqN30f8oyQF.jpg"), budget: 63_000_000, revenue: 100_853_753, - homepageURL: URL(string: ""), + homepageURL: nil, imdbID: "tt0137523", status: .released, productionCompanies: [ diff --git a/Tests/TMDbTests/Domain/Models/ShowTests.swift b/Tests/TMDbTests/Domain/Models/ShowTests.swift index 6191d2a4..9b2f1ff7 100644 --- a/Tests/TMDbTests/Domain/Models/ShowTests.swift +++ b/Tests/TMDbTests/Domain/Models/ShowTests.swift @@ -58,7 +58,7 @@ struct ShowTests { #expect(tvSeriesShow.date == expectedResult) } - @Test("JSON decoding of Movie", .tags(.decoding)) + @Test("JSON decoding of Show", .tags(.decoding)) func testDecodeReturnsMovie() throws { let result = try JSONDecoder.theMovieDatabase.decode(Show.self, fromResource: "show-movie") diff --git a/Tests/TMDbTests/Networking/HTTPClient/MockURLProtocol.swift b/Tests/TMDbTests/Networking/HTTPClient/MockURLProtocol.swift index ec3d96eb..38a42550 100644 --- a/Tests/TMDbTests/Networking/HTTPClient/MockURLProtocol.swift +++ b/Tests/TMDbTests/Networking/HTTPClient/MockURLProtocol.swift @@ -19,6 +19,10 @@ import Foundation +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif + final class MockURLProtocol: URLProtocol, @unchecked Sendable { @MainActor static var data: Data? diff --git a/Tests/TMDbTests/Networking/TMDbAPIClientTests.swift b/Tests/TMDbTests/Networking/TMDbAPIClientTests.swift index 2288b7d7..0b006016 100644 --- a/Tests/TMDbTests/Networking/TMDbAPIClientTests.swift +++ b/Tests/TMDbTests/Networking/TMDbAPIClientTests.swift @@ -21,6 +21,10 @@ import Foundation import Testing @testable import TMDb +#if canImport(FoundationNetworking) + import FoundationNetworking +#endif + @Suite(.tags(.networking)) struct TMDbAPIClientTests { @@ -59,7 +63,11 @@ struct TMDbAPIClientTests { error = err as? TMDbAPIError } - #expect(error == .invalidURL(path)) + #if canImport(FoundationNetworking) + #expect(error == .unknown) + #else + #expect(error == .invalidURL(path)) + #endif } @Test("perform has correct URL")