mas/Tests/masTests/Controllers/AppLibraryMock.swift

37 lines
948 B
Swift
Raw Normal View History

//
// AppLibraryMock.swift
// masTests
//
// Created by Ben Chatelain on 12/27/18.
// Copyright © 2018 mas-cli. All rights reserved.
//
@testable import mas
class AppLibraryMock: AppLibrary {
var installedApps = [SoftwareProduct]()
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
}
// 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!
}
}
/// Members not part of the AppLibrary protocol that are only for test state management.
extension AppLibraryMock {
/// Clears out the list of installed apps.
func reset() {
installedApps = []
}
}