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))
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      sig { void }
 | 
			
		||||
      def self.reset_executable!
 | 
			
		||||
        @executable = nil
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      sig { returns(String) }
 | 
			
		||||
      def self.scope
 | 
			
		||||
        System.root? ? "--system" : "--user"
 | 
			
		||||
 | 
			
		||||
@ -177,8 +177,7 @@ RSpec.describe Services::Cli do
 | 
			
		||||
 | 
			
		||||
  describe "#systemd_load", :needs_linux 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(:scope).once.and_return("--user")
 | 
			
		||||
      expect(Services::System::Systemctl).to receive(:run).once.and_return(true)
 | 
			
		||||
      services_cli.systemd_load(
 | 
			
		||||
        instance_double(Services::FormulaWrapper, service_name: "name"),
 | 
			
		||||
        enable: false,
 | 
			
		||||
@ -186,8 +185,7 @@ RSpec.describe Services::Cli do
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    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(:scope).twice.and_return("--user")
 | 
			
		||||
      expect(Services::System::Systemctl).to receive(:run).twice.and_return(true)
 | 
			
		||||
      services_cli.systemd_load(
 | 
			
		||||
        instance_double(Services::FormulaWrapper, service_name: "name"),
 | 
			
		||||
        enable: true,
 | 
			
		||||
@ -197,15 +195,15 @@ RSpec.describe Services::Cli do
 | 
			
		||||
 | 
			
		||||
  describe "#launchctl_load", :needs_macos 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(:launchctl).once.and_return(Pathname.new("/bin/launchctl"))
 | 
			
		||||
      expect(described_class).to receive(:safe_system).once.and_return(true)
 | 
			
		||||
      services_cli.launchctl_load(instance_double(Services::FormulaWrapper), file: "a", enable: false)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    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(:launchctl).once.and_return(Pathname.new("/bin/launchctl"))
 | 
			
		||||
      expect(described_class).to receive(:safe_system).twice.and_return(true)
 | 
			
		||||
      services_cli.launchctl_load(instance_double(Services::FormulaWrapper, service_name: "name"), file:   "a",
 | 
			
		||||
                                                                                                   enable: true)
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,11 @@ RSpec.describe Services::System::Systemctl do
 | 
			
		||||
 | 
			
		||||
  describe ".executable" 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
 | 
			
		||||
 | 
			
		||||
@ -9,7 +9,7 @@ RSpec.describe Services::System do
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user