NetNewsWire/Frameworks/Account/AccountTests/TestTransport.swift
2019-05-06 10:53:20 -05:00

39 lines
985 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, data: Data, completion: @escaping (Result<(HTTPHeaders, Data?), Error>) -> Void) {
}
}