2019-07-27 12:47:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 15:16:55 -04:00
|
|
|
require_relative "helper"
|
2020-07-12 13:00:29 -04:00
|
|
|
require_relative "helpers/tmp_path"
|
2011-09-27 13:53:45 -04:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
class TestPumaUnixSocket < Minitest::Test
|
2020-07-12 13:00:29 -04:00
|
|
|
include TmpPath
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
App = lambda { |env| [200, {}, ["Works"]] }
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
def setup
|
2019-07-29 21:16:09 -04:00
|
|
|
return unless UNIX_SKT_EXIST
|
2020-07-12 13:00:29 -04:00
|
|
|
@tmp_socket_path = tmp_path('.sock')
|
2018-08-21 21:08:06 -04:00
|
|
|
@server = Puma::Server.new App
|
2020-07-12 13:00:29 -04:00
|
|
|
@server.add_unix_listener @tmp_socket_path
|
2018-08-21 21:08:06 -04:00
|
|
|
@server.run
|
|
|
|
end
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
def teardown
|
2019-07-29 21:16:09 -04:00
|
|
|
return unless UNIX_SKT_EXIST
|
2019-07-27 12:47:19 -04:00
|
|
|
@server.stop(true)
|
2018-08-21 21:08:06 -04:00
|
|
|
end
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
def test_server
|
2019-07-29 21:16:09 -04:00
|
|
|
skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
|
2020-07-12 13:00:29 -04:00
|
|
|
sock = UNIXSocket.new @tmp_socket_path
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
|
2015-02-19 08:43:17 -05:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
assert_equal expected, sock.read(expected.size)
|
2011-09-27 13:53:45 -04:00
|
|
|
end
|
2012-01-08 14:55:57 -05:00
|
|
|
end
|