Add tests for multiple service sockets
This commit is contained in:
parent
ae5e9387b9
commit
afeef33bc1
@ -14,6 +14,15 @@ describe Homebrew::Service do
|
||||
end
|
||||
end
|
||||
|
||||
def stub_formula_with_service_sockets(sockets_var)
|
||||
stub_formula do
|
||||
service do
|
||||
run opt_bin/"beanstalkd"
|
||||
sockets sockets_var
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#std_service_path_env" do
|
||||
it "returns valid std_service_path_env" do
|
||||
f = stub_formula do
|
||||
@ -102,43 +111,33 @@ describe Homebrew::Service do
|
||||
end
|
||||
|
||||
describe "#sockets" do
|
||||
it "throws for missing type" do
|
||||
f = stub_formula do
|
||||
service do
|
||||
run opt_bin/"beanstalkd"
|
||||
sockets "127.0.0.1:80"
|
||||
end
|
||||
end
|
||||
let(:sockets_type_error_message) { "Service#sockets a formatted socket definition as <type>://<host>:<port>" }
|
||||
|
||||
expect do
|
||||
f.service.manual_command
|
||||
end.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
||||
it "throws for missing type" do
|
||||
[
|
||||
stub_formula_with_service_sockets("127.0.0.1:80"),
|
||||
stub_formula_with_service_sockets({ "Socket" => "127.0.0.1:80" }),
|
||||
].each do |f|
|
||||
expect { f.service.manual_command }.to raise_error TypeError, sockets_type_error_message
|
||||
end
|
||||
end
|
||||
|
||||
it "throws for missing host" do
|
||||
f = stub_formula do
|
||||
service do
|
||||
run opt_bin/"beanstalkd"
|
||||
sockets "tcp://:80"
|
||||
end
|
||||
[
|
||||
stub_formula_with_service_sockets("tcp://:80"),
|
||||
stub_formula_with_service_sockets({ "Socket" => "tcp://:80" }),
|
||||
].each do |f|
|
||||
expect { f.service.manual_command }.to raise_error TypeError, sockets_type_error_message
|
||||
end
|
||||
|
||||
expect do
|
||||
f.service.manual_command
|
||||
end.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
||||
end
|
||||
|
||||
it "throws for missing port" do
|
||||
f = stub_formula do
|
||||
service do
|
||||
run opt_bin/"beanstalkd"
|
||||
sockets "tcp://127.0.0.1"
|
||||
end
|
||||
[
|
||||
stub_formula_with_service_sockets("tcp://127.0.0.1"),
|
||||
stub_formula_with_service_sockets({ "Socket" => "tcp://127.0.0.1" }),
|
||||
].each do |f|
|
||||
expect { f.service.manual_command }.to raise_error TypeError, sockets_type_error_message
|
||||
end
|
||||
|
||||
expect do
|
||||
f.service.manual_command
|
||||
end.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
||||
end
|
||||
end
|
||||
|
||||
@ -259,10 +258,59 @@ describe Homebrew::Service do
|
||||
end
|
||||
|
||||
it "returns valid plist with socket" do
|
||||
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>LimitLoadToSessionType</key>
|
||||
\t<array>
|
||||
\t\t<string>Aqua</string>
|
||||
\t\t<string>Background</string>
|
||||
\t\t<string>LoginWindow</string>
|
||||
\t\t<string>StandardIO</string>
|
||||
\t\t<string>System</string>
|
||||
\t</array>
|
||||
\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/>
|
||||
\t<key>Sockets</key>
|
||||
\t<dict>
|
||||
\t\t<key>Listeners</key>
|
||||
\t\t<dict>
|
||||
\t\t\t<key>SockFamily</key>
|
||||
\t\t\t<string>IPv4v6</string>
|
||||
\t\t\t<key>SockNodeName</key>
|
||||
\t\t\t<string>127.0.0.1</string>
|
||||
\t\t\t<key>SockProtocol</key>
|
||||
\t\t\t<string>TCP</string>
|
||||
\t\t\t<key>SockServiceName</key>
|
||||
\t\t\t<string>80</string>
|
||||
\t\t</dict>
|
||||
\t</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
EOS
|
||||
|
||||
[
|
||||
stub_formula_with_service_sockets("tcp://127.0.0.1:80"),
|
||||
stub_formula_with_service_sockets({ "Listeners" => "tcp://127.0.0.1:80" }),
|
||||
].each do |f|
|
||||
plist = f.service.to_plist
|
||||
expect(plist).to eq(plist_expect)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns valid plist with multiple sockets" do
|
||||
f = stub_formula do
|
||||
service do
|
||||
run [opt_bin/"beanstalkd", "test"]
|
||||
sockets "tcp://127.0.0.1:80"
|
||||
sockets "Socket" => "tcp://0.0.0.0:80", "SocketTLS" => "tcp://0.0.0.0:443"
|
||||
end
|
||||
end
|
||||
|
||||
@ -291,17 +339,28 @@ describe Homebrew::Service do
|
||||
\t<true/>
|
||||
\t<key>Sockets</key>
|
||||
\t<dict>
|
||||
\t\t<key>Listeners</key>
|
||||
\t\t<key>Socket</key>
|
||||
\t\t<dict>
|
||||
\t\t\t<key>SockFamily</key>
|
||||
\t\t\t<string>IPv4v6</string>
|
||||
\t\t\t<key>SockNodeName</key>
|
||||
\t\t\t<string>127.0.0.1</string>
|
||||
\t\t\t<string>0.0.0.0</string>
|
||||
\t\t\t<key>SockProtocol</key>
|
||||
\t\t\t<string>TCP</string>
|
||||
\t\t\t<key>SockServiceName</key>
|
||||
\t\t\t<string>80</string>
|
||||
\t\t</dict>
|
||||
\t\t<key>SocketTLS</key>
|
||||
\t\t<dict>
|
||||
\t\t\t<key>SockFamily</key>
|
||||
\t\t\t<string>IPv4v6</string>
|
||||
\t\t\t<key>SockNodeName</key>
|
||||
\t\t\t<string>0.0.0.0</string>
|
||||
\t\t\t<key>SockProtocol</key>
|
||||
\t\t\t<string>TCP</string>
|
||||
\t\t\t<key>SockServiceName</key>
|
||||
\t\t\t<string>443</string>
|
||||
\t\t</dict>
|
||||
\t</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user