homebrew-core/Formula/postgrest.rb
2015-12-25 21:05:40 +00:00

57 lines
1.8 KiB
Ruby

require "language/haskell"
require "net/http"
class Postgrest < Formula
include Language::Haskell::Cabal
desc "Serves a fully RESTful API from any existing PostgreSQL database."
homepage "https://github.com/begriffs/postgrest"
url "https://github.com/begriffs/postgrest/archive/v0.3.0.2.tar.gz"
sha256 "376ce2cef0f79a85ea99639e5b1420ede52935ff931535fe6ea0430e7579a9be"
bottle do
sha256 "89b5e12b6b8307a2500d01e12dc0beec5c00bd275f4828aab664f697d5f82af9" => :el_capitan
sha256 "7e008c229b5e341e3e22a8d35b567d8a24b4e8d8f0df9dd83b3d5debb7cb883b" => :yosemite
sha256 "820ff26f2eb79c9a3f585b1e5850805ff231328542e4db93fb4a96b0ce5728ea" => :mavericks
end
depends_on "ghc" => :build
depends_on "cabal-install" => :build
depends_on "postgresql"
def install
install_cabal_package
end
test do
pg_bin = Formula["postgresql"].bin
pg_port = 55561
pg_user = "postgrest_test_user"
test_db = "test_postgrest_formula"
system "#{pg_bin}/initdb", "-D", testpath/test_db,
"--auth=trust", "--username=#{pg_user}"
system "#{pg_bin}/pg_ctl", "-D", testpath/test_db, "-l",
testpath/"#{test_db}.log", "-w", "-o", %("-p #{pg_port}"), "start"
begin
system "#{pg_bin}/createdb", "-w", "-p", pg_port, "-U", pg_user, test_db
pid = fork do
exec "postgrest", "postgres://#{pg_user}@localhost:#{pg_port}/#{test_db}",
"-a", pg_user, "-p", "55560"
end
Process.detach(pid)
sleep(5) # Wait for the server to start
response = Net::HTTP.get(URI("http://localhost:55560"))
assert_equal "[]", response
ensure
begin
Process.kill("TERM", pid) if pid
ensure
system "#{pg_bin}/pg_ctl", "-D", testpath/test_db, "stop",
"-s", "-m", "fast"
end
end
end
end