65 lines
2.0 KiB
Ruby
65 lines
2.0 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.2.tar.gz"
|
|
sha256 "8355719e6c6bdf03a93204c5bcf2246521e0ffc02694b2cebfc576d4eae9a0c9"
|
|
head "https://github.com/PostgREST/postgrest.git"
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "fc0ed59614a15faba14a43cb2034c0f13429347a092f82ec88e06f4f013067bc" => :mojave
|
|
sha256 "c3f2b71886b7a2f609f78d3f0ac756a016533674520c778586cac3242063b225" => :high_sierra
|
|
sha256 "151e3406cd3b46b327bf745f99d9e0cf1f7c8208590a54d576ee0672a6f8c8ba" => :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
|