mas/Tests/MasKitTests/Commands/UninstallCommandSpec.swift

86 lines
2.8 KiB
Swift
Raw Normal View History

//
// 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
import Nimble
2019-01-30 06:15:24 +00:00
import Quick
2021-03-22 05:25:18 +00:00
@testable import MasKit
class UninstallCommandSpec: QuickSpec {
override func spec() {
describe("uninstall command") {
let appId = 12345
let app = SoftwareProductMock(
appName: "Some App",
bundleIdentifier: "com.some.app",
bundlePath: "/tmp/Some.app",
bundleVersion: "1.0",
itemIdentifier: NSNumber(value: appId)
)
let mockLibrary = AppLibraryMock()
let uninstall = UninstallCommand(appLibrary: mockLibrary)
context("dry run") {
let options = UninstallCommand.Options(appId: appId, dryRun: true)
beforeEach {
mockLibrary.reset()
}
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
})
}
it("finds an app") {
mockLibrary.installedApps.append(app)
let result = uninstall.run(options)
expect(result).to(beSuccess())
}
}
context("wet run") {
let options = UninstallCommand.Options(appId: appId, dryRun: false)
beforeEach {
mockLibrary.reset()
}
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
})
}
it("removes an app") {
mockLibrary.installedApps.append(app)
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
brokenUninstall.bundlePath = "/dev/null"
mockLibrary.installedApps.append(brokenUninstall)
let result = uninstall.run(options)
2021-03-22 05:25:18 +00:00
expect(result)
.to(
beFailure { error in
expect(error) == .uninstallFailed
})
}
}
}
}
}