mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-12 17:36:19 +01:00
39 lines
988 B
Swift
39 lines
988 B
Swift
//
|
|
// TestTransport.swift
|
|
// AccountTests
|
|
//
|
|
// Created by Maurice Parker on 5/4/19.
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import RSWeb
|
|
|
|
final class TestTransport: Transport {
|
|
|
|
enum TestTransportError: String, Error {
|
|
case invalidState = "The test wasn't set up correctly."
|
|
}
|
|
|
|
var testFiles = [String: String]()
|
|
|
|
func send(request: URLRequest, completion: @escaping (Result<(HTTPHeaders, Data?), Error>) -> Void) {
|
|
|
|
guard let urlString = request.url?.absoluteString else {
|
|
completion(.failure(TestTransportError.invalidState))
|
|
return
|
|
}
|
|
|
|
let testFileName = testFiles[urlString]!
|
|
let testFileURL = Bundle(for: TestTransport.self).resourceURL!.appendingPathComponent(testFileName)
|
|
let data = try! Data(contentsOf: testFileURL)
|
|
completion(.success((HTTPHeaders(), data)))
|
|
|
|
}
|
|
|
|
func send(request: URLRequest, payload: Data, completion: @escaping (Result<(HTTPHeaders, Data?), Error>) -> Void) {
|
|
|
|
}
|
|
|
|
}
|