diff --git a/.travis.yml b/.travis.yml index 633b870..d145f58 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,32 +9,29 @@ matrix: before_install: - wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import - - cd .. - - export SWIFT_VERSION=swift-3.0.2-RELEASE - - wget https://swift.org/builds/swift-3.0.2-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz + - export SWIFT_VERSION=swift-3.1-RELEASE + - wget https://swift.org/builds/swift-3.1-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz - tar xzf $SWIFT_VERSION-ubuntu14.04.tar.gz - export PATH="${PWD}/${SWIFT_VERSION}-ubuntu14.04/usr/bin:${PATH}" - cd DBNetworkStack script: - swift test --verbose - os: osx - osx_image: xcode8.2 + osx_image: xcode8.3 language: objective-c env: "macOS" script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=OS X' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty - os: osx - osx_image: xcode8.2 + osx_image: xcode8.3 language: objective-c env: "iOS" - before_install: - - export SNAPSHOT_FORCE_DELETE=1 - - fastlane snapshot reset_simulators script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=iOS Simulator,name=iPhone SE,OS=latest' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage YES | xcpretty after_success: - bash <(curl -s https://codecov.io/bash) - os: osx - osx_image: xcode8.2 + osx_image: xcode8.3 language: objective-c env: "watchOS" before_install: @@ -43,17 +40,14 @@ matrix: script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=watchOS Simulator,name=Apple Watch - 38mm,OS=latest' build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO | xcpretty - os: osx - osx_image: xcode8.2 + osx_image: xcode8.3 language: objective-c env: "tvOS" - before_install: - - export SNAPSHOT_FORCE_DELETE=1 - - fastlane snapshot reset_simulators script: - set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=tvOS Simulator,name=Apple TV 1080p,OS=latest' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty - os: osx - osx_image: xcode8.2 + osx_image: xcode8.3 language: objective-c env: "Swift Package Manager" script: - - swift build --clean && swift test \ No newline at end of file + - swift build --clean && swift test diff --git a/Source/DBNetworkStackError.swift b/Source/DBNetworkStackError.swift index e38fab3..44a289b 100644 --- a/Source/DBNetworkStackError.swift +++ b/Source/DBNetworkStackError.swift @@ -89,7 +89,11 @@ extension DBNetworkStackError : CustomDebugStringConvertible { case .requestError(let error): return "Request error: \(error)" case .serverError(let response, let data): - return "Server error: \(response), response: ".appendingContentsOf(data: data) + if let response = response { + return "Server error: \(String(describing: response)), response: ".appendingContentsOf(data: data) + } else { + return "Server error: nil, response: ".appendingContentsOf(data: data) + } case .missingBaseURL: return "Missing base url error" } diff --git a/Source/HTTPMethod.swift b/Source/HTTPMethod.swift index 2e22cf0..2befe8e 100644 --- a/Source/HTTPMethod.swift +++ b/Source/HTTPMethod.swift @@ -26,6 +26,8 @@ // import Foundation + +// swiftlint:disable identifier_name /** HTTP Methods diff --git a/Source/ModifyRequestNetworkService.swift b/Source/ModifyRequestNetworkService.swift index 83b7c03..0a8249e 100644 --- a/Source/ModifyRequestNetworkService.swift +++ b/Source/ModifyRequestNetworkService.swift @@ -27,6 +27,7 @@ // import Foundation +import Dispatch /// `ModifyRequestNetworkService` can be composed with a networkService to modify all outgoing requests. /// One could add auth tokens or API keys for specifics URLs. diff --git a/Source/NetworkService.swift b/Source/NetworkService.swift index c6146e6..c582dc1 100644 --- a/Source/NetworkService.swift +++ b/Source/NetworkService.swift @@ -26,6 +26,7 @@ // import Foundation +import Dispatch /** `NetworkService` handles network request for resources by using a given `NetworkAccessProviding` diff --git a/Source/NetworkTaskMock.swift b/Source/NetworkTaskMock.swift index 63080d9..86e6361 100644 --- a/Source/NetworkTaskMock.swift +++ b/Source/NetworkTaskMock.swift @@ -49,6 +49,6 @@ public class NetworkTaskMock: NetworkTaskRepresenting { } public var progress: Progress { - return Progress() + return Progress(totalUnitCount: 0) } } diff --git a/Source/URLSessionNetworkAccess.swift b/Source/URLSessionNetworkAccess.swift index 3924d0e..b6231ba 100644 --- a/Source/URLSessionNetworkAccess.swift +++ b/Source/URLSessionNetworkAccess.swift @@ -34,7 +34,12 @@ extension URLSession: URLSessionProtocol {} extension URLSessionDataTask: NetworkTaskRepresenting { public var progress: Progress { - let totalBytesExpected = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown + #if os(Linux) + let SessionTransferSizeUnknown = URLSessionTransferSizeUnknown + #else + let SessionTransferSizeUnknown = NSURLSessionTransferSizeUnknown + #endif + let totalBytesExpected = response?.expectedContentLength ?? SessionTransferSizeUnknown let progress = Progress(totalUnitCount: totalBytesExpected) progress.totalUnitCount = totalBytesExpected progress.completedUnitCount = countOfBytesReceived diff --git a/Tests/DBNetworkStackTests/DBNetworkStackErrorTest.swift b/Tests/DBNetworkStackTests/DBNetworkStackErrorTest.swift index 2c67859..4826794 100644 --- a/Tests/DBNetworkStackTests/DBNetworkStackErrorTest.swift +++ b/Tests/DBNetworkStackTests/DBNetworkStackErrorTest.swift @@ -140,7 +140,7 @@ class DBNetworkStackErrorTest: XCTestCase { func testUnknownError_unauthorized_description() { //Given - let response = HTTPURLResponse() + let response: HTTPURLResponse! = HTTPURLResponse(url: url, statusCode: 0, httpVersion: "1.1", headerFields: nil) let data = "dataString".data(using: .utf8) let error: DBNetworkStackError = .unauthorized(response: response, data: data) @@ -149,12 +149,12 @@ class DBNetworkStackErrorTest: XCTestCase { //Then XCTAssert(debugDescription.hasPrefix("Authorization error: { URL: (null) } { status code: 0, headers {\n} }, response: dataString")) + XCTAssert(debugDescription.hasSuffix("> { URL: https://bahn.de } { status code: 0, headers {\n} }, response: dataString")) } func testUnknownError_clientError_description() { //Given - let response = HTTPURLResponse() + let response: HTTPURLResponse! = HTTPURLResponse(url: url, statusCode: 0, httpVersion: "1.1", headerFields: nil) let data = "dataString".data(using: .utf8) let error: DBNetworkStackError = .clientError(response: response, data: data) @@ -163,7 +163,7 @@ class DBNetworkStackErrorTest: XCTestCase { //Then XCTAssert(debugDescription.hasPrefix("Client error: { URL: (null) } { status code: 0, headers {\n} }, response: dataString")) + XCTAssert(debugDescription.hasSuffix("> { URL: https://bahn.de } { status code: 0, headers {\n} }, response: dataString")) } func testUnknownError_serializationError_description() { diff --git a/Tests/DBNetworkStackTests/JSONArrayResourceTest.swift b/Tests/DBNetworkStackTests/JSONArrayResourceTest.swift index 3baa2d1..9cb4db7 100644 --- a/Tests/DBNetworkStackTests/JSONArrayResourceTest.swift +++ b/Tests/DBNetworkStackTests/JSONArrayResourceTest.swift @@ -50,7 +50,7 @@ class JSONArrayResourceTest: XCTestCase { func testResource_WithInvalidData() { //When do { - let _ = try resource.parse(Train.invalidJSONData) + _ = try resource.parse(Train.invalidJSONData) XCTFail() } catch { @@ -60,7 +60,7 @@ class JSONArrayResourceTest: XCTestCase { func testResource_WithInvalidContainer() { //When do { - let _ = try resource.parse(Train.validJSONData) + _ = try resource.parse(Train.validJSONData) XCTFail() } catch { } diff --git a/Tests/DBNetworkStackTests/NetworkRequestTest.swift b/Tests/DBNetworkStackTests/NetworkRequestTest.swift index 0c6e90e..1bd0d57 100644 --- a/Tests/DBNetworkStackTests/NetworkRequestTest.swift +++ b/Tests/DBNetworkStackTests/NetworkRequestTest.swift @@ -54,7 +54,11 @@ class NetworkRequestTest: XCTestCase { //Then let urlRequest = request.urlRequest(with: baseURL) - XCTAssertEqual(urlRequest.url?.absoluteString, "https://www.bahn.de/index.html?test1=1&test2=2") + let reuqestURL: URL! = urlRequest.url + let query = URLComponents(url: reuqestURL, resolvingAgainstBaseURL: true)?.queryItems + XCTAssertEqual(query?.count, 2) + XCTAssert(query?.contains(where: { $0.name == "test1" && $0.value == "1" }) ?? false) + XCTAssert(query?.contains(where: { $0.name == "test2" && $0.value == "2" }) ?? false) XCTAssertEqual(urlRequest.httpMethod, httpMethod.rawValue) XCTAssertEqual(urlRequest.httpBody, body) XCTAssertEqual(urlRequest.allHTTPHeaderFields ?? [:], headerFields) diff --git a/Tests/DBNetworkStackTests/RetryNetworkserviceTest.swift b/Tests/DBNetworkStackTests/RetryNetworkserviceTest.swift index 5d1e02a..a001afd 100644 --- a/Tests/DBNetworkStackTests/RetryNetworkserviceTest.swift +++ b/Tests/DBNetworkStackTests/RetryNetworkserviceTest.swift @@ -91,7 +91,7 @@ class RetryNetworkserviceTest: XCTestCase { func testRetryRequest_shouldNotRetry() { //Given let shoudlRetry = false - var error: DBNetworkStackError? + var capturedError: DBNetworkStackError? //When weak var task: NetworkTaskRepresenting? @@ -102,13 +102,13 @@ class RetryNetworkserviceTest: XCTestCase { block() }).request(resource, onCompletion: { _ in XCTFail() - }, onError: { err in - error = err + }, onError: { error in + capturedError = error }) networkServiceMock.returnError(with: .unknownError, count: 3) //Then XCTAssertNil(task) - XCTAssertNotNil(error) + XCTAssertNotNil(capturedError) } } diff --git a/Tests/DBNetworkStackTests/RetryTaskTest.swift b/Tests/DBNetworkStackTests/RetryTaskTest.swift index 7ddd48d..598d2e6 100644 --- a/Tests/DBNetworkStackTests/RetryTaskTest.swift +++ b/Tests/DBNetworkStackTests/RetryTaskTest.swift @@ -51,9 +51,9 @@ class RetryTaskTest: XCTestCase { //Given var successValue: Int? var task: RetryNetworkTask? = RetryNetworkTask(maxmimumNumberOfRetries: 1, idleTimeInterval: 1, - shouldRetry: { err in return true}, onSuccess: { (t: Int) in - successValue = t - }, onError: { err in + shouldRetry: { _ in return true}, onSuccess: { (value: Int) in + successValue = value + }, onError: { _ in }, retryAction: {sucess, _ in sucess(0) return NetworkTaskMock() @@ -112,12 +112,12 @@ class RetryTaskTest: XCTestCase { var task: RetryNetworkTask? = RetryNetworkTask(maxmimumNumberOfRetries: 3, idleTimeInterval: 0.3, shouldRetry: { _ in return true}, onSuccess: { (_: Int) in }, onError: { _ in - }, retryAction: {a, b in + }, retryAction: { onSucess, onError in numerOfRertrys += 1 if numerOfRertrys == 3 { - a(0) + onSucess(0) } else { - b(self.mockError) + onError(self.mockError) } return NetworkTaskMock() @@ -139,12 +139,12 @@ class RetryTaskTest: XCTestCase { } func testShouldNotRetry() { - var error: DBNetworkStackError? + var capturedError: DBNetworkStackError? var task: RetryNetworkTask? = RetryNetworkTask(maxmimumNumberOfRetries: 3, idleTimeInterval: 0.3, - shouldRetry: { err in return false}, onSuccess: { _ in + shouldRetry: { _ in return false}, onSuccess: { _ in - }, onError: { err in - error = err + }, onError: { error in + capturedError = error }, retryAction: { _, _ in XCTFail() return NetworkTaskMock() @@ -161,6 +161,6 @@ class RetryTaskTest: XCTestCase { onError = nil XCTAssertNil(weakTask) - XCTAssertNotNil(error) + XCTAssertNotNil(capturedError) } } diff --git a/Tests/DBNetworkStackTests/URLSessionNetworkAccessTest.swift b/Tests/DBNetworkStackTests/URLSessionNetworkAccessTest.swift index 7dda4db..3767357 100644 --- a/Tests/DBNetworkStackTests/URLSessionNetworkAccessTest.swift +++ b/Tests/DBNetworkStackTests/URLSessionNetworkAccessTest.swift @@ -57,7 +57,7 @@ class URLSessionNetworkAccessTest: XCTestCase { } func testURLSession_MatchesTypeOfNetworkAccess() { - let _: NetworkAccessProviding = URLSession(configuration: .default) + _ = URLSession(configuration: .default) as NetworkAccessProviding } func test_URLSessionCreatsDataTask() {