2017-05-12 12:16:55 -07:00
|
|
|
require_relative "helper"
|
2011-09-27 10:53:45 -07:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
class TestPumaUnixSocket < Minitest::Test
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
App = lambda { |env| [200, {}, ["Works"]] }
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
Path = "test/puma.sock"
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
def setup
|
2019-02-20 14:15:55 -06:00
|
|
|
skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
|
2018-08-21 20:08:06 -05:00
|
|
|
@server = Puma::Server.new App
|
|
|
|
@server.add_unix_listener Path
|
|
|
|
@server.run
|
|
|
|
end
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
def teardown
|
|
|
|
@server.stop(true) if @server
|
|
|
|
File.unlink Path if File.exist? Path
|
|
|
|
end
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
def test_server
|
|
|
|
sock = UNIXSocket.new Path
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
sock << "GET / HTTP/1.0\r\nHost: blah.com\r\n\r\n"
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
expected = "HTTP/1.0 200 OK\r\nContent-Length: 5\r\n\r\nWorks"
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
assert_equal expected, sock.read(expected.size)
|
2015-02-19 14:43:17 +01:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
sock.close
|
2011-09-27 10:53:45 -07:00
|
|
|
end
|
2012-01-08 16:55:57 -03:00
|
|
|
end
|