mirror of
https://github.com/mas-cli/mas
synced 2024-11-25 13:00:23 +00:00
e6e2ccab0d
swiftformat Sources Tests
33 lines
848 B
Swift
33 lines
848 B
Swift
//
|
|
// NetworkSessionMock
|
|
// MasKitTests
|
|
//
|
|
// Created by Ben Chatelain on 11/13/18.
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import PromiseKit
|
|
|
|
@testable import MasKit
|
|
|
|
/// Mock NetworkSession for testing.
|
|
class NetworkSessionMock: NetworkSession {
|
|
// Properties that enable us to set exactly what data or error
|
|
// we want our mocked URLSession to return for any request.
|
|
var data: Data?
|
|
var error: Error?
|
|
|
|
/// Immediately passes data and error to completion handler.
|
|
///
|
|
/// - Parameters:
|
|
/// - url: unused
|
|
/// - completionHandler: Closure which is delivered either data or an error.
|
|
func loadData(from _: URL) -> Promise<Data> {
|
|
guard let data else {
|
|
return Promise(error: error ?? MASError.noData)
|
|
}
|
|
|
|
return .value(data)
|
|
}
|
|
}
|