1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_unix_socket.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require_relative "helper"
2020-07-12 13:00:29 -04:00
require_relative "helpers/tmp_path"
2011-09-27 13:53:45 -04:00
class TestPumaUnixSocket < Minitest::Test
2020-07-12 13:00:29 -04:00
include TmpPath
App = lambda { |env| [200, {}, ["Works"]] }
def teardown
return if skipped?
@server.stop(true)
end
def server_unix(type)
@tmp_socket_path = type == :unix ? tmp_path('.sock') : "@TestPumaUnixSocket"
@server = Puma::Server.new App
2020-07-12 13:00:29 -04:00
@server.add_unix_listener @tmp_socket_path
@server.run
end
def test_server_unix
skip_unless :unix
server_unix :unix
2020-07-12 13:00:29 -04:00
sock = UNIXSocket.new @tmp_socket_path
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
assert_equal expected, sock.read(expected.size)
2011-09-27 13:53:45 -04:00
end
def test_server_aunix
skip_unless :aunix
server_unix :aunix
sock = UNIXSocket.new @tmp_socket_path.sub(/\A@/, "\0")
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
assert_equal expected, sock.read(expected.size)
end
2012-01-08 14:55:57 -05:00
end