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