mas/Tests/masTests/Network/MockNetworkSession.swift

29 lines
640 B
Swift
Raw Permalink Normal View History

2019-01-06 19:26:08 +00:00
//
// MockNetworkSession
// masTests
2019-01-06 19:26:08 +00:00
//
// Created by Ben Chatelain on 11/13/18.
// Copyright © 2018 mas-cli. All rights reserved.
//
import Foundation
import PromiseKit
2021-05-09 20:25:20 +00:00
@testable import mas
2019-01-06 19:26:08 +00:00
/// Mock NetworkSession for testing.
class MockNetworkSession: NetworkSession {
2019-01-06 19:26:08 +00:00
// 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?
func loadData(from _: URL) -> Promise<Data> {
guard let data else {
return Promise(error: error ?? MASError.noData)
}
return .value(data)
2019-01-06 19:26:08 +00:00
}
}