2018-12-27 15:24:20 -07:00
|
|
|
//
|
2024-10-01 18:55:04 -04:00
|
|
|
// UninstallSpec.swift
|
2024-10-01 14:05:41 -04:00
|
|
|
// masTests
|
2018-12-27 15:24:20 -07:00
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 2018-12-27.
|
|
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2021-04-26 16:44:17 -07:00
|
|
|
import Foundation
|
2018-12-27 15:24:20 -07:00
|
|
|
import Nimble
|
2019-01-29 23:15:24 -07:00
|
|
|
import Quick
|
2018-12-27 15:24:20 -07:00
|
|
|
|
2024-10-01 14:05:41 -04:00
|
|
|
@testable import mas
|
2021-03-21 22:25:18 -07:00
|
|
|
|
2024-10-01 18:55:04 -04:00
|
|
|
public class UninstallSpec: QuickSpec {
|
2024-10-18 10:28:44 -04:00
|
|
|
override public func spec() {
|
2021-04-23 00:01:18 -07:00
|
|
|
beforeSuite {
|
2024-10-25 13:21:19 -04:00
|
|
|
MAS.initialize()
|
2021-04-23 00:01:18 -07:00
|
|
|
}
|
2024-10-23 14:20:31 -04:00
|
|
|
xdescribe("uninstall command") {
|
2024-10-14 01:50:10 -04:00
|
|
|
let appID: AppID = 12345
|
2024-10-25 23:09:31 -04:00
|
|
|
let app = MockSoftwareProduct(
|
2018-12-27 16:07:35 -07:00
|
|
|
appName: "Some App",
|
2019-03-30 09:50:30 -06:00
|
|
|
bundleIdentifier: "com.some.app",
|
2018-12-27 16:07:35 -07:00
|
|
|
bundlePath: "/tmp/Some.app",
|
2018-12-28 15:08:31 -07:00
|
|
|
bundleVersion: "1.0",
|
2024-10-14 01:50:10 -04:00
|
|
|
itemIdentifier: NSNumber(value: appID)
|
2018-12-27 16:07:35 -07:00
|
|
|
)
|
2024-10-25 20:48:03 -04:00
|
|
|
let mockLibrary = MockAppLibrary()
|
2018-12-27 16:07:35 -07:00
|
|
|
|
|
|
|
context("dry run") {
|
2024-10-25 13:21:19 -04:00
|
|
|
let uninstall = try! MAS.Uninstall.parse(["--dry-run", String(appID)])
|
2018-12-27 15:24:20 -07:00
|
|
|
|
2018-12-28 15:08:31 -07:00
|
|
|
beforeEach {
|
|
|
|
mockLibrary.reset()
|
|
|
|
}
|
2018-12-27 16:07:35 -07:00
|
|
|
it("can't remove a missing app") {
|
2024-10-01 18:55:04 -04:00
|
|
|
expect {
|
2024-10-01 21:54:15 -04:00
|
|
|
try uninstall.run(appLibrary: mockLibrary)
|
2024-10-01 18:55:04 -04:00
|
|
|
}
|
2024-10-23 12:57:34 -04:00
|
|
|
.to(throwError(MASError.notInstalled(appID: appID)))
|
2018-12-27 16:07:35 -07:00
|
|
|
}
|
|
|
|
it("finds an app") {
|
2018-12-28 15:08:31 -07:00
|
|
|
mockLibrary.installedApps.append(app)
|
2024-10-01 18:55:04 -04:00
|
|
|
expect {
|
2024-10-23 14:04:02 -04:00
|
|
|
try captureStream(stdout) {
|
|
|
|
try uninstall.run(appLibrary: mockLibrary)
|
|
|
|
}
|
2024-10-01 18:55:04 -04:00
|
|
|
}
|
2024-10-23 14:04:02 -04:00
|
|
|
== "==> 'Some App' '/tmp/Some.app'\n==> (not removed, dry run)\n"
|
2018-12-27 16:07:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
context("wet run") {
|
2024-10-25 13:21:19 -04:00
|
|
|
let uninstall = try! MAS.Uninstall.parse([String(appID)])
|
2018-12-27 16:07:35 -07:00
|
|
|
|
2018-12-28 15:08:31 -07:00
|
|
|
beforeEach {
|
|
|
|
mockLibrary.reset()
|
|
|
|
}
|
2018-12-27 16:07:35 -07:00
|
|
|
it("can't remove a missing app") {
|
2024-10-01 18:55:04 -04:00
|
|
|
expect {
|
2024-10-01 21:54:15 -04:00
|
|
|
try uninstall.run(appLibrary: mockLibrary)
|
2024-10-01 18:55:04 -04:00
|
|
|
}
|
2024-10-23 12:57:34 -04:00
|
|
|
.to(throwError(MASError.notInstalled(appID: appID)))
|
2018-12-27 16:07:35 -07:00
|
|
|
}
|
|
|
|
it("removes an app") {
|
2018-12-28 15:08:31 -07:00
|
|
|
mockLibrary.installedApps.append(app)
|
2024-10-01 18:55:04 -04:00
|
|
|
expect {
|
2024-10-02 09:49:30 -04:00
|
|
|
try captureStream(stdout) {
|
|
|
|
try uninstall.run(appLibrary: mockLibrary)
|
|
|
|
}
|
2024-10-01 18:55:04 -04:00
|
|
|
}
|
2024-10-23 14:04:02 -04:00
|
|
|
.toNot(throwError())
|
2018-12-27 16:07:35 -07:00
|
|
|
}
|
|
|
|
it("fails if there is a problem with the trash command") {
|
2024-10-23 14:04:02 -04:00
|
|
|
var brokenApp = app
|
|
|
|
brokenApp.bundlePath = "/dev/null"
|
|
|
|
mockLibrary.installedApps.append(brokenApp)
|
2024-10-01 18:55:04 -04:00
|
|
|
expect {
|
2024-10-23 14:20:31 -04:00
|
|
|
try captureStream(stdout) {
|
|
|
|
try uninstall.run(appLibrary: mockLibrary)
|
|
|
|
}
|
2024-10-01 18:55:04 -04:00
|
|
|
}
|
2024-10-23 14:11:52 -04:00
|
|
|
.to(throwError(MASError.uninstallFailed(error: nil)))
|
2018-12-27 16:07:35 -07:00
|
|
|
}
|
2018-12-27 15:24:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|