mirror of
https://github.com/mas-cli/mas
synced 2024-11-28 06:20:35 +00:00
d413d8cfa1
Move MasKitTests module to masTests. Rename MasKit enum as Mas. Upgrade swift-tools-version from 5.3 to 5.6.1. swift-tools-version 5.5+ is necessary to allow test code to import executable target code, to allow MasKit library code to be moved into the mas executable. Upgrade to swift-tools-version to 5.6.1 instead of to 5.5 because they support all the same macOS versions. Standardize comments. Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
33 lines
842 B
Swift
33 lines
842 B
Swift
//
|
|
// NetworkSessionMock
|
|
// masTests
|
|
//
|
|
// Created by Ben Chatelain on 11/13/18.
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import PromiseKit
|
|
|
|
@testable import mas
|
|
|
|
/// 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)
|
|
}
|
|
}
|