mas/Tests/MasKitTests/Commands/UninstallCommandSpec.swift

89 lines
2.9 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
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()
}
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
})
}
}
}
}
}