2019-07-27 12:47:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 15:16:55 -04:00
|
|
|
require_relative "helper"
|
2011-09-27 13:53:45 -04:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
class TestPumaUnixSocket < Minitest::Test
|
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
|
|
|
|
2020-03-07 08:37:05 -05:00
|
|
|
PATH = "test/puma.sock"
|
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
|
2018-08-21 21:08:06 -04:00
|
|
|
@server = Puma::Server.new App
|
2020-03-07 08:37:05 -05:00
|
|
|
@server.add_unix_listener 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-03-07 08:37:05 -05:00
|
|
|
sock = UNIXSocket.new 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
|