add initial tests

This commit is contained in:
Bevan Kay 2022-12-13 00:00:43 +11:00
parent 836efe621f
commit e8e6ee30b4
No known key found for this signature in database
GPG Key ID: C55CB024B5314B57
4 changed files with 42 additions and 7 deletions

View File

@ -95,7 +95,7 @@ module Cask
# if launchctl item contains a wildcard, find matching process(es)
services.each do |service|
all_services << service
all_services << service unless service.include?("*")
next unless service.include?("*")
all_services += find_launchctl_with_wildcard(service)

View File

@ -61,6 +61,19 @@ shared_examples "#uninstall_phase or #zap_phase" do
end
end
context "using launchctl with regex" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-launchctl-wildcard")) }
let(:launchctl_list_cmd) { %w[/bin/launchctl list] }
it "searches running launchctl items" do
allow(fake_system_command).to receive(:run)
.with("/bin/launchctl", args: ["list"], print_stderr: false, sudo: false)
.and_return(instance_double(SystemCommand::Result))
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
end
end
context "using :pkgutil" do
let(:cask) { Cask::CaskLoader.load(cask_path("with-#{artifact_dsl_key}-pkgutil")) }
@ -117,9 +130,9 @@ shared_examples "#uninstall_phase or #zap_phase" do
allow(User.current).to receive(:gui?).and_return false
allow(subject).to receive(:running?).with(bundle_id).and_return(true)
expect {
expect do
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
}.to output(/Not logged into a GUI; skipping quitting application ID 'my.fancy.package.app'\./).to_stderr
end.to output(/Not logged into a GUI; skipping quitting application ID 'my.fancy.package.app'\./).to_stderr
end
it "quits a running application" do
@ -130,9 +143,9 @@ shared_examples "#uninstall_phase or #zap_phase" do
.and_return(instance_double("SystemCommand::Result", success?: true))
expect(subject).to receive(:running?).with(bundle_id).ordered.and_return(false)
expect {
expect do
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
}.to output(/Application 'my.fancy.package.app' quit successfully\./).to_stdout
end.to output(/Application 'my.fancy.package.app' quit successfully\./).to_stdout
end
it "tries to quit the application for 10 seconds" do
@ -143,9 +156,9 @@ shared_examples "#uninstall_phase or #zap_phase" do
.and_return(instance_double("SystemCommand::Result", success?: false))
time = Benchmark.measure do
expect {
expect do
subject.public_send(:"#{artifact_dsl_key}_phase", command: fake_system_command)
}.to output(/Application 'my.fancy.package.app' did not quit\./).to_stderr
end.to output(/Application 'my.fancy.package.app' did not quit\./).to_stderr
end
expect(time.real).to be_within(3).of(10)

View File

@ -0,0 +1,11 @@
cask "with-uninstall-launchctl-wildcard" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
homepage "https://brew.sh/fancy"
app "Fancy.app"
uninstall launchctl: "my.fancy.package.service.*"
end

View File

@ -0,0 +1,11 @@
cask "with-zap-launchctl-wildcard" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyApp.zip"
homepage "https://brew.sh/fancy"
app "Fancy.app"
zap launchctl: "my.fancy.package.service.*"
end