2020-12-11 23:14:50 +01:00
|
|
|
# typed: false
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "formula"
|
|
|
|
require "service"
|
|
|
|
|
|
|
|
describe Homebrew::Service do
|
|
|
|
let(:klass) do
|
|
|
|
Class.new(Formula) do
|
|
|
|
url "https://brew.sh/test-1.0.tbz"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
let(:name) { "formula_name" }
|
|
|
|
let(:path) { Formulary.core_path(name) }
|
|
|
|
let(:spec) { :stable }
|
|
|
|
let(:f) { klass.new(name, path, spec) }
|
|
|
|
|
2021-04-13 16:59:59 +02:00
|
|
|
describe "#std_service_path_env" do
|
|
|
|
it "returns valid std_service_path_env" do
|
|
|
|
f.class.service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
|
|
|
end
|
|
|
|
|
|
|
|
path = f.service.std_service_path_env
|
|
|
|
expect(path).to eq("#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-11 23:14:50 +01:00
|
|
|
describe "#to_plist" do
|
|
|
|
it "returns valid plist" do
|
2021-04-08 10:06:45 +02:00
|
|
|
f.class.service do
|
2021-04-29 09:43:39 +02:00
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
2020-12-11 23:14:50 +01:00
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
2021-05-22 18:17:36 +02:00
|
|
|
input_path var/"in/beanstalkd"
|
|
|
|
root_dir var
|
2020-12-11 23:14:50 +01:00
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
2021-05-22 18:17:36 +02:00
|
|
|
restart_delay 30
|
|
|
|
macos_legacy_timers true
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
|
2021-04-08 10:06:45 +02:00
|
|
|
plist = f.service.to_plist
|
2021-04-29 09:43:39 +02:00
|
|
|
plist_expect = <<~EOS
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
\t<key>EnvironmentVariables</key>
|
|
|
|
\t<dict>
|
|
|
|
\t\t<key>PATH</key>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
|
|
|
\t</dict>
|
|
|
|
\t<key>KeepAlive</key>
|
|
|
|
\t<true/>
|
|
|
|
\t<key>Label</key>
|
|
|
|
\t<string>homebrew.mxcl.formula_name</string>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>LegacyTimers</key>
|
|
|
|
\t<true/>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t\t<string>test</string>
|
|
|
|
\t</array>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>RootDirectory</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var</string>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
\t<key>StandardErrorPath</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log</string>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>StandardInPath</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var/in/beanstalkd</string>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>StandardOutPath</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.log</string>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>TimeOut</key>
|
|
|
|
\t<integer>30</integer>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>WorkingDirectory</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var</string>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid partial plist" do
|
2021-04-08 10:06:45 +02:00
|
|
|
f.class.service do
|
2021-04-29 09:43:39 +02:00
|
|
|
run opt_bin/"beanstalkd"
|
2020-12-11 23:14:50 +01:00
|
|
|
run_type :immediate
|
|
|
|
end
|
|
|
|
|
2021-04-08 10:06:45 +02:00
|
|
|
plist = f.service.to_plist
|
2021-04-29 09:43:39 +02:00
|
|
|
plist_expect = <<~EOS
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
<plist version="1.0">
|
|
|
|
<dict>
|
|
|
|
\t<key>Label</key>
|
|
|
|
\t<string>homebrew.mxcl.formula_name</string>
|
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t</array>
|
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
end
|
2021-04-13 16:59:59 +02:00
|
|
|
|
|
|
|
describe "#to_systemd_unit" do
|
|
|
|
it "returns valid unit" do
|
|
|
|
f.class.service do
|
2021-04-29 09:43:39 +02:00
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
2021-04-13 16:59:59 +02:00
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
2021-05-22 18:17:36 +02:00
|
|
|
input_path var/"in/beanstalkd"
|
|
|
|
root_dir var
|
2021-04-13 16:59:59 +02:00
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
2021-05-22 18:17:36 +02:00
|
|
|
restart_delay 30
|
|
|
|
macos_legacy_timers true
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_unit
|
|
|
|
std_path = "#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
|
2021-04-29 09:43:39 +02:00
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated unit for formula_name
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd test
|
|
|
|
Restart=always
|
2021-05-22 18:17:36 +02:00
|
|
|
RestartSec=30
|
2021-04-29 09:43:39 +02:00
|
|
|
WorkingDirectory=#{HOMEBREW_PREFIX}/var
|
2021-05-22 18:17:36 +02:00
|
|
|
RootDirectory=#{HOMEBREW_PREFIX}/var
|
|
|
|
StandardInput=file:#{HOMEBREW_PREFIX}/var/in/beanstalkd
|
2021-04-29 09:43:39 +02:00
|
|
|
StandardOutput=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.log
|
|
|
|
StandardError=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log
|
|
|
|
Environment=\"PATH=#{std_path}\"
|
|
|
|
EOS
|
|
|
|
expect(unit).to eq(unit_expect.strip)
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid partial unit" do
|
|
|
|
f.class.service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_unit
|
2021-04-29 09:43:39 +02:00
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated unit for formula_name
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd
|
|
|
|
EOS
|
|
|
|
expect(unit).to eq(unit_expect)
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
end
|
2021-04-13 11:25:56 +02:00
|
|
|
|
|
|
|
describe "#command" do
|
|
|
|
it "returns @run data" do
|
|
|
|
f.class.service do
|
2021-04-29 09:43:39 +02:00
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
2021-04-13 11:25:56 +02:00
|
|
|
run_type :immediate
|
|
|
|
end
|
|
|
|
|
|
|
|
command = f.service.command
|
2021-04-29 09:43:39 +02:00
|
|
|
expect(command).to eq(["#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd", "test"])
|
2021-04-13 11:25:56 +02:00
|
|
|
end
|
|
|
|
end
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|