2018-12-27 22:24:20 +00:00
|
|
|
//
|
|
|
|
// UninstallCommandSpec.swift
|
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2021-03-22 05:25:18 +00:00
|
|
|
@testable import MasKit
|
|
|
|
|
2021-05-08 22:49:32 +00:00
|
|
|
public class UninstallCommandSpec: QuickSpec {
|
2021-05-09 20:25:20 +00:00
|
|
|
override public func spec() {
|
2021-04-23 07:01:18 +00:00
|
|
|
beforeSuite {
|
|
|
|
MasKit.initialize()
|
|
|
|
}
|
2018-12-27 22:24:20 +00:00
|
|
|
describe("uninstall command") {
|
2018-12-27 23:07:35 +00:00
|
|
|
let appId = 12345
|
2019-01-06 21:01:08 +00:00
|
|
|
let app = SoftwareProductMock(
|
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",
|
2018-12-27 23:07:35 +00:00
|
|
|
itemIdentifier: NSNumber(value: appId)
|
|
|
|
)
|
2019-01-06 21:01:08 +00:00
|
|
|
let mockLibrary = AppLibraryMock()
|
2018-12-27 23:07:35 +00:00
|
|
|
let uninstall = UninstallCommand(appLibrary: mockLibrary)
|
|
|
|
|
|
|
|
context("dry run") {
|
2018-12-27 22:24:20 +00:00
|
|
|
let options = UninstallCommand.Options(appId: appId, dryRun: true)
|
|
|
|
|
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") {
|
|
|
|
let result = uninstall.run(options)
|
2021-03-22 05:25:18 +00:00
|
|
|
expect(result)
|
|
|
|
.to(
|
|
|
|
beFailure { error in
|
|
|
|
expect(error) == .notInstalled
|
|
|
|
})
|
2018-12-27 23:07:35 +00:00
|
|
|
}
|
|
|
|
it("finds an app") {
|
2018-12-28 22:08:31 +00:00
|
|
|
mockLibrary.installedApps.append(app)
|
2018-12-27 23:07:35 +00:00
|
|
|
|
|
|
|
let result = uninstall.run(options)
|
|
|
|
expect(result).to(beSuccess())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
context("wet run") {
|
|
|
|
let options = UninstallCommand.Options(appId: appId, dryRun: false)
|
|
|
|
|
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") {
|
|
|
|
let result = uninstall.run(options)
|
2021-03-22 05:25:18 +00:00
|
|
|
expect(result)
|
|
|
|
.to(
|
|
|
|
beFailure { error in
|
|
|
|
expect(error) == .notInstalled
|
|
|
|
})
|
2018-12-27 23:07:35 +00:00
|
|
|
}
|
|
|
|
it("removes an app") {
|
2018-12-28 22:08:31 +00:00
|
|
|
mockLibrary.installedApps.append(app)
|
2018-12-27 23:07:35 +00:00
|
|
|
|
|
|
|
let result = uninstall.run(options)
|
|
|
|
expect(result).to(beSuccess())
|
|
|
|
}
|
|
|
|
it("fails if there is a problem with the trash command") {
|
2021-03-22 05:25:18 +00:00
|
|
|
var brokenUninstall = app // make mutable copy
|
2018-12-27 23:07:35 +00:00
|
|
|
brokenUninstall.bundlePath = "/dev/null"
|
2018-12-28 22:08:31 +00:00
|
|
|
mockLibrary.installedApps.append(brokenUninstall)
|
2018-12-27 23:07:35 +00:00
|
|
|
|
|
|
|
let result = uninstall.run(options)
|
2021-03-22 05:25:18 +00:00
|
|
|
expect(result)
|
|
|
|
.to(
|
|
|
|
beFailure { error in
|
|
|
|
expect(error) == .uninstallFailed
|
|
|
|
})
|
2018-12-27 23:07:35 +00:00
|
|
|
}
|
2018-12-27 22:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|