Skip to content

Commit 51161bd

Browse files
Merge pull request #37 from dbsystel/swift3.1-linux
Swift3.1 linux
2 parents a2ecf13 + 7bbd2e5 commit 51161bd

13 files changed

+51
-40
lines changed

.travis.yml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,29 @@ matrix:
99
before_install:
1010
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
1111
- cd ..
12-
- export SWIFT_VERSION=swift-3.0.2-RELEASE
13-
- wget https://swift.org/builds/swift-3.0.2-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz
12+
- export SWIFT_VERSION=swift-3.1-RELEASE
13+
- wget https://swift.org/builds/swift-3.1-release/ubuntu1404/$SWIFT_VERSION/$SWIFT_VERSION-ubuntu14.04.tar.gz
1414
- tar xzf $SWIFT_VERSION-ubuntu14.04.tar.gz
1515
- export PATH="${PWD}/${SWIFT_VERSION}-ubuntu14.04/usr/bin:${PATH}"
1616
- cd DBNetworkStack
1717
script:
1818
- swift test --verbose
1919
- os: osx
20-
osx_image: xcode8.2
20+
osx_image: xcode8.3
2121
language: objective-c
2222
env: "macOS"
2323
script:
2424
- set -o pipefail && xcodebuild -scheme DBNetworkStack -destination 'platform=OS X' test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -enableCodeCoverage NO | xcpretty
2525
- os: osx
26-
osx_image: xcode8.2
26+
osx_image: xcode8.3
2727
language: objective-c
2828
env: "iOS"
29-
before_install:
30-
- export SNAPSHOT_FORCE_DELETE=1
31-
- fastlane snapshot reset_simulators
3229
script:
3330
- 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
3431
after_success:
3532
- bash <(curl -s https://codecov.io/bash)
3633
- os: osx
37-
osx_image: xcode8.2
34+
osx_image: xcode8.3
3835
language: objective-c
3936
env: "watchOS"
4037
before_install:
@@ -43,17 +40,14 @@ matrix:
4340
script:
4441
- 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
4542
- os: osx
46-
osx_image: xcode8.2
43+
osx_image: xcode8.3
4744
language: objective-c
4845
env: "tvOS"
49-
before_install:
50-
- export SNAPSHOT_FORCE_DELETE=1
51-
- fastlane snapshot reset_simulators
5246
script:
5347
- 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
5448
- os: osx
55-
osx_image: xcode8.2
49+
osx_image: xcode8.3
5650
language: objective-c
5751
env: "Swift Package Manager"
5852
script:
59-
- swift build --clean && swift test
53+
- swift build --clean && swift test

Source/DBNetworkStackError.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ extension DBNetworkStackError : CustomDebugStringConvertible {
8989
case .requestError(let error):
9090
return "Request error: \(error)"
9191
case .serverError(let response, let data):
92-
return "Server error: \(response), response: ".appendingContentsOf(data: data)
92+
if let response = response {
93+
return "Server error: \(String(describing: response)), response: ".appendingContentsOf(data: data)
94+
} else {
95+
return "Server error: nil, response: ".appendingContentsOf(data: data)
96+
}
9397
case .missingBaseURL:
9498
return "Missing base url error"
9599
}

Source/HTTPMethod.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
//
2727

2828
import Foundation
29+
30+
// swiftlint:disable identifier_name
2931
/**
3032
HTTP Methods
3133

Source/ModifyRequestNetworkService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//
2828

2929
import Foundation
30+
import Dispatch
3031

3132
/// `ModifyRequestNetworkService` can be composed with a networkService to modify all outgoing requests.
3233
/// One could add auth tokens or API keys for specifics URLs.

Source/NetworkService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
//
2727

2828
import Foundation
29+
import Dispatch
2930

3031
/**
3132
`NetworkService` handles network request for resources by using a given `NetworkAccessProviding`

Source/NetworkTaskMock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public class NetworkTaskMock: NetworkTaskRepresenting {
4949
}
5050

5151
public var progress: Progress {
52-
return Progress()
52+
return Progress(totalUnitCount: 0)
5353
}
5454
}

Source/URLSessionNetworkAccess.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ extension URLSession: URLSessionProtocol {}
3434

3535
extension URLSessionDataTask: NetworkTaskRepresenting {
3636
public var progress: Progress {
37-
let totalBytesExpected = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown
37+
#if os(Linux)
38+
let SessionTransferSizeUnknown = URLSessionTransferSizeUnknown
39+
#else
40+
let SessionTransferSizeUnknown = NSURLSessionTransferSizeUnknown
41+
#endif
42+
let totalBytesExpected = response?.expectedContentLength ?? SessionTransferSizeUnknown
3843
let progress = Progress(totalUnitCount: totalBytesExpected)
3944
progress.totalUnitCount = totalBytesExpected
4045
progress.completedUnitCount = countOfBytesReceived

Tests/DBNetworkStackTests/DBNetworkStackErrorTest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class DBNetworkStackErrorTest: XCTestCase {
140140

141141
func testUnknownError_unauthorized_description() {
142142
//Given
143-
let response = HTTPURLResponse()
143+
let response: HTTPURLResponse! = HTTPURLResponse(url: url, statusCode: 0, httpVersion: "1.1", headerFields: nil)
144144
let data = "dataString".data(using: .utf8)
145145
let error: DBNetworkStackError = .unauthorized(response: response, data: data)
146146

@@ -149,12 +149,12 @@ class DBNetworkStackErrorTest: XCTestCase {
149149

150150
//Then
151151
XCTAssert(debugDescription.hasPrefix("Authorization error: <NSHTTPURLResponse: "))
152-
XCTAssert(debugDescription.hasSuffix("> { URL: (null) } { status code: 0, headers {\n} }, response: dataString"))
152+
XCTAssert(debugDescription.hasSuffix("> { URL: https://bahn.de } { status code: 0, headers {\n} }, response: dataString"))
153153
}
154154

155155
func testUnknownError_clientError_description() {
156156
//Given
157-
let response = HTTPURLResponse()
157+
let response: HTTPURLResponse! = HTTPURLResponse(url: url, statusCode: 0, httpVersion: "1.1", headerFields: nil)
158158
let data = "dataString".data(using: .utf8)
159159
let error: DBNetworkStackError = .clientError(response: response, data: data)
160160

@@ -163,7 +163,7 @@ class DBNetworkStackErrorTest: XCTestCase {
163163

164164
//Then
165165
XCTAssert(debugDescription.hasPrefix("Client error: <NSHTTPURLResponse: "))
166-
XCTAssert(debugDescription.hasSuffix("> { URL: (null) } { status code: 0, headers {\n} }, response: dataString"))
166+
XCTAssert(debugDescription.hasSuffix("> { URL: https://bahn.de } { status code: 0, headers {\n} }, response: dataString"))
167167
}
168168

169169
func testUnknownError_serializationError_description() {

Tests/DBNetworkStackTests/JSONArrayResourceTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class JSONArrayResourceTest: XCTestCase {
5050
func testResource_WithInvalidData() {
5151
//When
5252
do {
53-
let _ = try resource.parse(Train.invalidJSONData)
53+
_ = try resource.parse(Train.invalidJSONData)
5454
XCTFail()
5555
} catch {
5656

@@ -60,7 +60,7 @@ class JSONArrayResourceTest: XCTestCase {
6060
func testResource_WithInvalidContainer() {
6161
//When
6262
do {
63-
let _ = try resource.parse(Train.validJSONData)
63+
_ = try resource.parse(Train.validJSONData)
6464
XCTFail()
6565
} catch {
6666
}

Tests/DBNetworkStackTests/NetworkRequestTest.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ class NetworkRequestTest: XCTestCase {
5454
//Then
5555
let urlRequest = request.urlRequest(with: baseURL)
5656

57-
XCTAssertEqual(urlRequest.url?.absoluteString, "https://www.bahn.de/index.html?test1=1&test2=2")
57+
let reuqestURL: URL! = urlRequest.url
58+
let query = URLComponents(url: reuqestURL, resolvingAgainstBaseURL: true)?.queryItems
59+
XCTAssertEqual(query?.count, 2)
60+
XCTAssert(query?.contains(where: { $0.name == "test1" && $0.value == "1" }) ?? false)
61+
XCTAssert(query?.contains(where: { $0.name == "test2" && $0.value == "2" }) ?? false)
5862
XCTAssertEqual(urlRequest.httpMethod, httpMethod.rawValue)
5963
XCTAssertEqual(urlRequest.httpBody, body)
6064
XCTAssertEqual(urlRequest.allHTTPHeaderFields ?? [:], headerFields)

0 commit comments

Comments
 (0)