homebrew-core/Formula/postgrest.rb
2019-06-21 22:41:15 -04:00

64 lines
2 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/PostgREST/postgrest"
url "https://github.com/PostgREST/postgrest/archive/v6.0.0.tar.gz"
sha256 "161095014ccb8bb744849ae8dad8c95b9de2ac6ddf3bcb09bbd6ec7e1fe541e7"
head "https://github.com/PostgREST/postgrest.git"
bottle do
cellar :any
sha256 "203a53be5ca17df60658df5a9b7b288339cb585ff3af90b67dce84419f4e2809" => :mojave
sha256 "060cffafd12f00623bda0941f6ddd5f121ee602bcb8db0ee17c37b6b6da06754" => :high_sierra
sha256 "08f7f10f551a8aae1ab220036b56e74db5516d196bf719dc72dc46690b2c9a62" => :sierra
end
depends_on "cabal-install" => :build
depends_on "ghc" => :build
depends_on "postgresql"
def install
install_cabal_package :using => ["happy"]
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", %Q("-p #{pg_port}"), "start"
begin
system "#{pg_bin}/createdb", "-w", "-p", pg_port, "-U", pg_user, test_db
(testpath/"postgrest.config").write <<~EOS
db-uri = "postgres://#{pg_user}@localhost:#{pg_port}/#{test_db}"
db-schema = "public"
db-anon-role = "#{pg_user}"
server-port = 55560
EOS
pid = fork do
exec "#{bin}/postgrest", "postgrest.config"
end
Process.detach(pid)
sleep(5) # Wait for the server to start
response = Net::HTTP.get(URI("http://localhost:55560"))
assert_match /responses.*200.*OK/, 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