Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
70 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[submodule "Carthage/Checkouts/Result"] | ||
path = Carthage/Checkouts/Result | ||
url = https://github.com/antitypical/Result.git | ||
[submodule "Carthage/Checkouts/OHHTTPStubs"] | ||
path = Carthage/Checkouts/OHHTTPStubs | ||
url = https://github.com/AliSoftware/OHHTTPStubs.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
github "AliSoftware/OHHTTPStubs" "5.2.1-swift3" | ||
github "antitypical/Result" "3.0.0" |
Submodule OHHTTPStubs
deleted from
624d51
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import Foundation | ||
import APIKit | ||
import XCTest | ||
import OHHTTPStubs | ||
import Result | ||
|
||
class SessionTests: XCTestCase { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Foundation | ||
import Dispatch | ||
import Result | ||
|
||
class HTTPStub: URLProtocol { | ||
static var stubResult: Result<Data, NSError> = .success(Data()) | ||
|
||
private var isCancelled = false | ||
|
||
// MARK: URLProtocol - | ||
|
||
override class func canInit(with: URLRequest) -> Bool { | ||
return true | ||
} | ||
|
||
override class func canonicalRequest(for request: URLRequest) -> URLRequest { | ||
return request | ||
} | ||
|
||
override func startLoading() { | ||
let response = HTTPURLResponse( | ||
url: request.url!, | ||
statusCode: 200, | ||
httpVersion: "1.1", | ||
headerFields: nil) | ||
|
||
let queue = DispatchQueue.global(qos: .default) | ||
|
||
queue.asyncAfter(deadline: .now() + 0.01) { | ||
guard !self.isCancelled else { | ||
return | ||
} | ||
|
||
self.client?.urlProtocol(self, didReceive: response!, cacheStoragePolicy: .notAllowed) | ||
|
||
switch HTTPStub.stubResult { | ||
case .success(let data): | ||
self.client?.urlProtocol(self, didLoad: data) | ||
|
||
case .failure(let error): | ||
self.client?.urlProtocol(self, didFailWithError: error) | ||
} | ||
|
||
self.client?.urlProtocolDidFinishLoading(self) | ||
} | ||
} | ||
|
||
override func stopLoading() { | ||
isCancelled = true | ||
} | ||
} |