Skip to content

Commit

Permalink
Merge pull request #37 from dbsystel/swift3.1-linux
Browse files Browse the repository at this point in the history
Swift3.1 linux
  • Loading branch information
lightsprint09 authored Apr 6, 2017
2 parents a2ecf13 + 7bbd2e5 commit 51161bd
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 40 deletions.
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
- swift build --clean && swift test
6 changes: 5 additions & 1 deletion Source/DBNetworkStackError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
2 changes: 2 additions & 0 deletions Source/HTTPMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
//

import Foundation

// swiftlint:disable identifier_name
/**
HTTP Methods
Expand Down
1 change: 1 addition & 0 deletions Source/ModifyRequestNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Source/NetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//

import Foundation
import Dispatch

/**
`NetworkService` handles network request for resources by using a given `NetworkAccessProviding`
Expand Down
2 changes: 1 addition & 1 deletion Source/NetworkTaskMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public class NetworkTaskMock: NetworkTaskRepresenting {
}

public var progress: Progress {
return Progress()
return Progress(totalUnitCount: 0)
}
}
7 changes: 6 additions & 1 deletion Source/URLSessionNetworkAccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Tests/DBNetworkStackTests/DBNetworkStackErrorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -149,12 +149,12 @@ class DBNetworkStackErrorTest: XCTestCase {

//Then
XCTAssert(debugDescription.hasPrefix("Authorization error: <NSHTTPURLResponse: "))
XCTAssert(debugDescription.hasSuffix("> { 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)

Expand All @@ -163,7 +163,7 @@ class DBNetworkStackErrorTest: XCTestCase {

//Then
XCTAssert(debugDescription.hasPrefix("Client error: <NSHTTPURLResponse: "))
XCTAssert(debugDescription.hasSuffix("> { 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() {
Expand Down
4 changes: 2 additions & 2 deletions Tests/DBNetworkStackTests/JSONArrayResourceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 {
}
Expand Down
6 changes: 5 additions & 1 deletion Tests/DBNetworkStackTests/NetworkRequestTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Tests/DBNetworkStackTests/RetryNetworkserviceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)
}
}
22 changes: 11 additions & 11 deletions Tests/DBNetworkStackTests/RetryTaskTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class RetryTaskTest: XCTestCase {
//Given
var successValue: Int?
var task: RetryNetworkTask<Int>? = 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()
Expand Down Expand Up @@ -112,12 +112,12 @@ class RetryTaskTest: XCTestCase {
var task: RetryNetworkTask<Int>? = 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()
Expand All @@ -139,12 +139,12 @@ class RetryTaskTest: XCTestCase {
}

func testShouldNotRetry() {
var error: DBNetworkStackError?
var capturedError: DBNetworkStackError?
var task: RetryNetworkTask<Int>? = 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()
Expand All @@ -161,6 +161,6 @@ class RetryTaskTest: XCTestCase {
onError = nil

XCTAssertNil(weakTask)
XCTAssertNotNil(error)
XCTAssertNotNil(capturedError)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class URLSessionNetworkAccessTest: XCTestCase {
}

func testURLSession_MatchesTypeOfNetworkAccess() {
let _: NetworkAccessProviding = URLSession(configuration: .default)
_ = URLSession(configuration: .default) as NetworkAccessProviding
}

func test_URLSessionCreatsDataTask() {
Expand Down

0 comments on commit 51161bd

Please sign in to comment.