test/services: fix some more tests.
This commit is contained in:
parent
7a7395a229
commit
0d3cbcad41
@ -9,6 +9,11 @@ module Services
|
|||||||
@executable ||= T.let(which("systemctl"), T.nilable(Pathname))
|
@executable ||= T.let(which("systemctl"), T.nilable(Pathname))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { void }
|
||||||
|
def self.reset_executable!
|
||||||
|
@executable = nil
|
||||||
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
def self.scope
|
def self.scope
|
||||||
System.root? ? "--system" : "--user"
|
System.root? ? "--system" : "--user"
|
||||||
|
|||||||
@ -177,8 +177,7 @@ RSpec.describe Services::Cli do
|
|||||||
|
|
||||||
describe "#systemd_load", :needs_linux do
|
describe "#systemd_load", :needs_linux do
|
||||||
it "checks non-enabling run" do
|
it "checks non-enabling run" do
|
||||||
expect(Services::System::Systemctl).to receive(:executable).once.and_return(Pathname.new("/usr/bin/systemctl"))
|
expect(Services::System::Systemctl).to receive(:run).once.and_return(true)
|
||||||
expect(Services::System::Systemctl).to receive(:scope).once.and_return("--user")
|
|
||||||
services_cli.systemd_load(
|
services_cli.systemd_load(
|
||||||
instance_double(Services::FormulaWrapper, service_name: "name"),
|
instance_double(Services::FormulaWrapper, service_name: "name"),
|
||||||
enable: false,
|
enable: false,
|
||||||
@ -186,8 +185,7 @@ RSpec.describe Services::Cli do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "checks enabling run" do
|
it "checks enabling run" do
|
||||||
expect(Services::System::Systemctl).to receive(:executable).once.and_return(Pathname.new("/usr/bin/systemctl"))
|
expect(Services::System::Systemctl).to receive(:run).twice.and_return(true)
|
||||||
expect(Services::System::Systemctl).to receive(:scope).twice.and_return("--user")
|
|
||||||
services_cli.systemd_load(
|
services_cli.systemd_load(
|
||||||
instance_double(Services::FormulaWrapper, service_name: "name"),
|
instance_double(Services::FormulaWrapper, service_name: "name"),
|
||||||
enable: true,
|
enable: true,
|
||||||
@ -197,15 +195,15 @@ RSpec.describe Services::Cli do
|
|||||||
|
|
||||||
describe "#launchctl_load", :needs_macos do
|
describe "#launchctl_load", :needs_macos do
|
||||||
it "checks non-enabling run" do
|
it "checks non-enabling run" do
|
||||||
|
allow(Services::System).to receive(:launchctl).and_return(Pathname.new("/bin/launchctl"))
|
||||||
expect(Services::System).to receive(:domain_target).once.and_return("target")
|
expect(Services::System).to receive(:domain_target).once.and_return("target")
|
||||||
expect(Services::System).to receive(:launchctl).once.and_return(Pathname.new("/bin/launchctl"))
|
|
||||||
expect(described_class).to receive(:safe_system).once.and_return(true)
|
expect(described_class).to receive(:safe_system).once.and_return(true)
|
||||||
services_cli.launchctl_load(instance_double(Services::FormulaWrapper), file: "a", enable: false)
|
services_cli.launchctl_load(instance_double(Services::FormulaWrapper), file: "a", enable: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "checks enabling run" do
|
it "checks enabling run" do
|
||||||
|
allow(Services::System).to receive(:launchctl).and_return(Pathname.new("/bin/launchctl"))
|
||||||
expect(Services::System).to receive(:domain_target).twice.and_return("target")
|
expect(Services::System).to receive(:domain_target).twice.and_return("target")
|
||||||
expect(Services::System).to receive(:launchctl).once.and_return(Pathname.new("/bin/launchctl"))
|
|
||||||
expect(described_class).to receive(:safe_system).twice.and_return(true)
|
expect(described_class).to receive(:safe_system).twice.and_return(true)
|
||||||
services_cli.launchctl_load(instance_double(Services::FormulaWrapper, service_name: "name"), file: "a",
|
services_cli.launchctl_load(instance_double(Services::FormulaWrapper, service_name: "name"), file: "a",
|
||||||
enable: true)
|
enable: true)
|
||||||
|
|||||||
@ -18,7 +18,11 @@ RSpec.describe Services::System::Systemctl do
|
|||||||
|
|
||||||
describe ".executable" do
|
describe ".executable" do
|
||||||
it "outputs systemctl command location", :needs_linux do
|
it "outputs systemctl command location", :needs_linux do
|
||||||
expect(described_class.executable).to eq(Pathname.new("/usr/bin/systemctl"))
|
systemctl = Pathname("/bin/systemctl")
|
||||||
|
expect(described_class).to receive(:which).and_return(systemctl)
|
||||||
|
described_class.reset_executable!
|
||||||
|
|
||||||
|
expect(described_class.executable).to eq(systemctl)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,7 +9,7 @@ RSpec.describe Services::System do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "Other - outputs launchctl command location", :needs_linux do
|
it "Other - outputs launchctl command location", :needs_linux do
|
||||||
expect(described_class.launchctl).to eq_nil
|
expect(described_class.launchctl).to be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user