From 302f922e7bcd295f7e15af38a22accb763297cd0 Mon Sep 17 00:00:00 2001 From: Jalil Date: Sat, 26 Oct 2024 15:28:20 -0600 Subject: [PATCH] Adjust Harbor tests to accept Swift 6 concurrency --- Tests/HarborTests/HarborTests.swift | 23 +++++++++++----------- Tests/HarborTests/Mocks/MocksRequest.swift | 8 ++++---- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Tests/HarborTests/HarborTests.swift b/Tests/HarborTests/HarborTests.swift index 25d1319..09a2f6e 100644 --- a/Tests/HarborTests/HarborTests.swift +++ b/Tests/HarborTests/HarborTests.swift @@ -3,36 +3,36 @@ import XCTest final class HarborTests: XCTestCase { - func testShouldAddSinglePathParameterCorrectlyToURL() throws { + func testShouldAddSinglePathParameterCorrectlyToURL() async throws { // Given let baseUrl = "https://api.github.com/users/{USER}/" let expectedURL = "https://api.github.com/users/OmarJalil/" // When - let url = HRequestManager.compositeURL(url: baseUrl, pathParameters: ["USER": "OmarJalil"], queryParameters: nil) + let url = await HRequestManager.compositeURL(url: baseUrl, pathParameters: ["USER": "OmarJalil"], queryParameters: nil) // Then XCTAssertEqual(expectedURL, url?.absoluteString) } - func testShouldAddMultiplePathParametersCorrectlyToURL() throws { + func testShouldAddMultiplePathParametersCorrectlyToURL() async throws { // Given let baseUrl = "https://api.github.com/users/{USER}/following/{FOLLOWS}/" let expectedURL = "https://api.github.com/users/OmarJalil/following/javiermanzo/" // When - let url = HRequestManager.compositeURL(url: baseUrl, pathParameters: ["FOLLOWS": "javiermanzo", "USER": "OmarJalil"], queryParameters: nil) + let url = await HRequestManager.compositeURL(url: baseUrl, pathParameters: ["FOLLOWS": "javiermanzo", "USER": "OmarJalil"], queryParameters: nil) // Then XCTAssertEqual(expectedURL, url?.absoluteString) } - func testBuildGetRequest() { + func testBuildGetRequest() async throws { // Given let service = MockGetRequestService(url: "https://example.com", queryParameters: ["id": "123", "sort": "desc"]) // When - let request = HRequestManager.buildUrlRequest(request: service) + let request = await HRequestManager.buildUrlRequest(request: service) // Then XCTAssertNotNil(request) @@ -40,27 +40,28 @@ final class HarborTests: XCTestCase { XCTAssertEqual(request?.httpMethod, "GET") } - func testBuildPostRequest() { + func testBuildPostRequest() async throws { // Given let service = MockPostRequestService(url: "https://example.com", bodyParameters: ["name": "John"]) // When - let request = HRequestManager.buildUrlRequest(request: service) + let request = await HRequestManager.buildUrlRequest(request: service) // Then XCTAssertNotNil(request) XCTAssertEqual(request?.url?.absoluteString, "https://example.com") XCTAssertEqual(request?.httpMethod, "POST") XCTAssertEqual(request?.allHTTPHeaderFields?["Content-Type"], "application/json") - XCTAssertEqual(request?.httpBody, HRequestManager.dataBody(params: ["name": "John"], type: .json)) + let httpBody = await HRequestManager.dataBody(params: ["name": "John"], type: .json) + XCTAssertEqual(request?.httpBody, httpBody) } - func testBuildInvalidRequest() { + func testBuildInvalidRequest() async throws { // Given let service = MockInvalidRequestService() // When - let request = HRequestManager.buildUrlRequest(request: service) + let request = await HRequestManager.buildUrlRequest(request: service) // Then XCTAssertNil(request) diff --git a/Tests/HarborTests/Mocks/MocksRequest.swift b/Tests/HarborTests/Mocks/MocksRequest.swift index cc738bc..a22d567 100644 --- a/Tests/HarborTests/Mocks/MocksRequest.swift +++ b/Tests/HarborTests/Mocks/MocksRequest.swift @@ -7,7 +7,7 @@ import Harbor -final class MockGetRequestService: HGetRequestProtocol { +final class MockGetRequestService: HGetRequestProtocol, @unchecked Sendable { typealias Model = String var headerParameters: [String: String]? @@ -27,7 +27,7 @@ final class MockGetRequestService: HGetRequestProtocol { } } -final class MockPostRequestService: HPostRequestProtocol { +final class MockPostRequestService: HPostRequestProtocol, @unchecked Sendable { var headerParameters: [String: String]? var needsAuth: Bool var retries: Int? @@ -48,7 +48,7 @@ final class MockPostRequestService: HPostRequestProtocol { } } -final class MockPostBodyRequestService: HPostRequestProtocol { +final class MockPostBodyRequestService: HPostRequestProtocol, @unchecked Sendable { var headerParameters: [String: String]? var needsAuth: Bool var retries: Int? @@ -68,7 +68,7 @@ final class MockPostBodyRequestService: HPostRequestProtocol { } } -final class MockInvalidRequestService: HRequestBaseRequestProtocol { +final class MockInvalidRequestService: HRequestBaseRequestProtocol, @unchecked Sendable { var headerParameters: [String: String]? var url: String var needsAuth: Bool = false