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
|
||||||
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
|
describe "#std_service_path_env" do
|
||||||
it "returns valid std_service_path_env" do
|
it "returns valid std_service_path_env" do
|
||||||
f = stub_formula do
|
f = stub_formula do
|
||||||
@ -102,43 +111,33 @@ describe Homebrew::Service do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#sockets" do
|
describe "#sockets" do
|
||||||
it "throws for missing type" do
|
let(:sockets_type_error_message) { "Service#sockets a formatted socket definition as <type>://<host>:<port>" }
|
||||||
f = stub_formula do
|
|
||||||
service do
|
|
||||||
run opt_bin/"beanstalkd"
|
|
||||||
sockets "127.0.0.1:80"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
expect do
|
it "throws for missing type" do
|
||||||
f.service.manual_command
|
[
|
||||||
end.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
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
|
end
|
||||||
|
|
||||||
it "throws for missing host" do
|
it "throws for missing host" do
|
||||||
f = stub_formula do
|
[
|
||||||
service do
|
stub_formula_with_service_sockets("tcp://:80"),
|
||||||
run opt_bin/"beanstalkd"
|
stub_formula_with_service_sockets({ "Socket" => "tcp://:80" }),
|
||||||
sockets "tcp://:80"
|
].each do |f|
|
||||||
end
|
expect { f.service.manual_command }.to raise_error TypeError, sockets_type_error_message
|
||||||
end
|
end
|
||||||
|
|
||||||
expect do
|
|
||||||
f.service.manual_command
|
|
||||||
end.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "throws for missing port" do
|
it "throws for missing port" do
|
||||||
f = stub_formula do
|
[
|
||||||
service do
|
stub_formula_with_service_sockets("tcp://127.0.0.1"),
|
||||||
run opt_bin/"beanstalkd"
|
stub_formula_with_service_sockets({ "Socket" => "tcp://127.0.0.1" }),
|
||||||
sockets "tcp://127.0.0.1"
|
].each do |f|
|
||||||
end
|
expect { f.service.manual_command }.to raise_error TypeError, sockets_type_error_message
|
||||||
end
|
end
|
||||||
|
|
||||||
expect do
|
|
||||||
f.service.manual_command
|
|
||||||
end.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -259,10 +258,59 @@ describe Homebrew::Service do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns valid plist with socket" do
|
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
|
f = stub_formula do
|
||||||
service do
|
service do
|
||||||
run [opt_bin/"beanstalkd", "test"]
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -291,17 +339,28 @@ describe Homebrew::Service do
|
|||||||
\t<true/>
|
\t<true/>
|
||||||
\t<key>Sockets</key>
|
\t<key>Sockets</key>
|
||||||
\t<dict>
|
\t<dict>
|
||||||
\t\t<key>Listeners</key>
|
\t\t<key>Socket</key>
|
||||||
\t\t<dict>
|
\t\t<dict>
|
||||||
\t\t\t<key>SockFamily</key>
|
\t\t\t<key>SockFamily</key>
|
||||||
\t\t\t<string>IPv4v6</string>
|
\t\t\t<string>IPv4v6</string>
|
||||||
\t\t\t<key>SockNodeName</key>
|
\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<key>SockProtocol</key>
|
||||||
\t\t\t<string>TCP</string>
|
\t\t\t<string>TCP</string>
|
||||||
\t\t\t<key>SockServiceName</key>
|
\t\t\t<key>SockServiceName</key>
|
||||||
\t\t\t<string>80</string>
|
\t\t\t<string>80</string>
|
||||||
\t\t</dict>
|
\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>
|
\t</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user