class Pushpin < Formula desc "Reverse proxy for realtime web services" homepage "http://pushpin.org" url "https://dl.bintray.com/fanout/source/pushpin-1.11.0.tar.bz2" sha256 "e1c9464f3a5c5473ace17920da0defb32973a70f30cc6b29e0852b94ff8b2995" head "https://github.com/fanout/pushpin.git" bottle do sha256 "4b1b453ef7ccf2d68432a4bf0784890bc3b889c86b9f324535fd02905d05d21d" => :el_capitan sha256 "ef3747605a4e25e6d47c37363e359cb3d7e08df8a1fcb3a90467333b35841dbd" => :yosemite sha256 "ece1b40d5fd3fc130e636a4a2ee5f09bc1b28c4db469f76fa351604ddc28028c" => :mavericks end depends_on "pkg-config" => :build depends_on "qt5" depends_on "zeromq" depends_on "mongrel2" depends_on "zurl" def install system "./configure", "--prefix=#{prefix}", "--configdir=#{etc}", "--rundir=#{var}/run", "--logdir=#{var}/log", "--extraconf=QMAKE_MACOSX_DEPLOYMENT_TARGET=#{MacOS.version}" system "make" system "make", "check" system "make", "install" end test do conffile = testpath/"pushpin.conf" routesfile = testpath/"routes" runfile = testpath/"test.py" cp HOMEBREW_PREFIX/"etc/pushpin/pushpin.conf", conffile cp HOMEBREW_PREFIX/"etc/pushpin/routes", routesfile inreplace conffile do |s| s.gsub! "rundir=#{HOMEBREW_PREFIX}/var/run/pushpin", "rundir=#{testpath}/var/run/pushpin" s.gsub! "logdir=#{HOMEBREW_PREFIX}/var/log/pushpin", "logdir=#{testpath}/var/log/pushpin" end inreplace routesfile, "test", "localhost:10080" runfile.write <<-EOS.undent import urllib2 import threading from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class TestHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() self.wfile.write('test response\\n') def server_worker(c): global port server = HTTPServer(('', 10080), TestHandler) port = server.server_address[1] c.acquire() c.notify() c.release() try: server.serve_forever() except: server.server_close() c = threading.Condition() c.acquire() server_thread = threading.Thread(target=server_worker, args=(c,)) server_thread.daemon = True server_thread.start() c.wait() c.release() f = urllib2.urlopen('http://localhost:7999/test') body = f.read() assert(body == 'test response\\n') EOS pid = fork do exec "#{bin}/pushpin", "--config=#{conffile}" end begin sleep 3 # make sure pushpin processes have started system "python", runfile ensure Process.kill("TERM", pid) Process.wait(pid) end end end