forked from puma/puma
/
test_unix_socket.rb
46 lines (33 loc) · 1.07 KB
/
test_unix_socket.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true
require_relative "helper"
require_relative "helpers/tmp_path"
class TestPumaUnixSocket < Minitest::Test
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
@server.add_unix_listener @tmp_socket_path
@server.run
end
def test_server_unix
skip_unless :unix
server_unix :unix
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)
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
end