mas/Tests/masTests/Commands/UninstallSpec.swift
Ross Goldberg 2535e3da42
Use Swift Argument Parser instead of Commandant.
Command structs are nested types of Mas.

Renamed structs.

Limit code visibility as much as possible.

Standardize variable names.

Standardize spacing.

Fix a few tests.

Disable a useless test.

Remove unnecessary test stdout output.

Get swift-format from Brewfile instead of from Package.swift
since swift-format depends on an old version of swift-argument-parser.

Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
2024-10-14 03:44:11 -04:00

97 lines
3 KiB
Swift

//
// UninstallSpec.swift
// masTests
//
// Created by Ben Chatelain on 2018-12-27.
// Copyright © 2018 mas-cli. All rights reserved.
//
import Foundation
import Nimble
import Quick
@testable import mas
public class UninstallSpec: QuickSpec {
override public func spec() {
beforeSuite {
Mas.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()
context("dry run") {
let uninstall = try! Mas.Uninstall.parse(["--dry-run", String(appId)])
beforeEach {
mockLibrary.reset()
}
it("can't remove a missing app") {
expect {
uninstall.run(appLibrary: mockLibrary)
}
.to(
beFailure { error in
expect(error) == .notInstalled
}
)
}
it("finds an app") {
mockLibrary.installedApps.append(app)
expect {
uninstall.run(appLibrary: mockLibrary)
}
.to(beSuccess())
}
}
context("wet run") {
let uninstall = try! Mas.Uninstall.parse([String(appId)])
beforeEach {
mockLibrary.reset()
}
it("can't remove a missing app") {
expect {
uninstall.run(appLibrary: mockLibrary)
}
.to(
beFailure { error in
expect(error) == .notInstalled
}
)
}
it("removes an app") {
mockLibrary.installedApps.append(app)
expect {
uninstall.run(appLibrary: mockLibrary)
}
.to(beSuccess())
}
it("fails if there is a problem with the trash command") {
var brokenUninstall = app // make mutable copy
brokenUninstall.bundlePath = "/dev/null"
mockLibrary.installedApps.append(brokenUninstall)
expect {
uninstall.run(appLibrary: mockLibrary)
}
.to(
beFailure { error in
expect(error) == .uninstallFailed
}
)
}
}
}
}
}