64 lines
2.0 KiB
Ruby
64 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/begriffs/postgrest"
|
|
url "https://github.com/begriffs/postgrest/archive/v0.4.0.0.tar.gz"
|
|
sha256 "d23aa9b9ed0272dfd2075c573a96ba95e28328617ba63bfc2792f8655a479cb9"
|
|
head "https://github.com/begriffs/postgrest.git"
|
|
|
|
bottle do
|
|
sha256 "5ccd950f8d3eeac90747f21b554c734410c24974c3aaddb0d9af63e3298499a1" => :sierra
|
|
sha256 "c1387285d6c35527786ed4d34b5ba0b9426454eaa2f6effe806e787fd4368339" => :el_capitan
|
|
sha256 "c6ffd2e7503f23fb5cbdbd1e9e0a8af176621dbdedcd21bc298c8e2b93fb6e26" => :yosemite
|
|
end
|
|
|
|
depends_on "ghc" => :build
|
|
depends_on "cabal-install" => :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.undent
|
|
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
|