2018-12-27 22:24:20 +00:00
|
|
|
//
|
2019-01-06 21:01:08 +00:00
|
|
|
// AppLibraryMock.swift
|
2018-12-27 22:24:20 +00:00
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 12/27/18.
|
|
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
@testable import MasKit
|
|
|
|
|
2019-01-06 21:01:08 +00:00
|
|
|
class AppLibraryMock: AppLibrary {
|
2018-12-28 22:08:31 +00:00
|
|
|
var installedApps = [SoftwareProduct]()
|
2018-12-27 23:07:35 +00:00
|
|
|
|
2018-12-28 22:08:31 +00:00
|
|
|
/// Finds an app using a bundle identifier.
|
|
|
|
///
|
|
|
|
/// - Parameter bundleId: Bundle identifier of app.
|
|
|
|
/// - Returns: Software Product of app if found; nil otherwise.
|
2019-01-30 06:15:24 +00:00
|
|
|
public func installedApp(forBundleId _: String) -> SoftwareProduct? {
|
2021-03-22 05:46:17 +00:00
|
|
|
nil
|
2018-12-27 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func uninstallApp(app: SoftwareProduct) throws {
|
2021-04-21 22:13:38 +00:00
|
|
|
if !installedApps.contains(where: { product -> Bool in
|
2019-01-30 06:15:24 +00:00
|
|
|
app.itemIdentifier == product.itemIdentifier
|
2021-03-22 05:25:18 +00:00
|
|
|
}) {
|
|
|
|
throw MASError.notInstalled
|
|
|
|
}
|
2018-12-27 23:07:35 +00:00
|
|
|
|
|
|
|
// Special case for testing where we pretend the trash command failed
|
|
|
|
if app.bundlePath == "/dev/null" {
|
|
|
|
throw MASError.uninstallFailed
|
|
|
|
}
|
|
|
|
|
|
|
|
// Success is the default, watch out for false positives!
|
2018-12-27 22:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-28 22:08:31 +00:00
|
|
|
|
|
|
|
/// Members not part of the AppLibrary protocol that are only for test state managment.
|
2019-01-06 21:01:08 +00:00
|
|
|
extension AppLibraryMock {
|
2018-12-28 22:08:31 +00:00
|
|
|
/// Clears out the list of installed apps.
|
|
|
|
func reset() {
|
|
|
|
installedApps = []
|
|
|
|
}
|
|
|
|
}
|