60 lines
1.8 KiB
Ruby
60 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.1.tar.gz"
|
|
sha256 "d2e92795a480e3a06d625905fb20bce30e5b86af6525cdec809e6a88200efab8"
|
|
|
|
bottle do
|
|
revision 1
|
|
sha256 "6e3dbaeeba86ca9f071af471d5a3296652aedc9b6484674ed337f23abef88f85" => :el_capitan
|
|
sha256 "a6ad263ae0aa979ed9da6bcb9002316a0a3e3980653c2a1921efbbfc1f3edf3a" => :yosemite
|
|
sha256 "6d2ee6020ab78948b30aefddb92f3d372eb0f6f9629b2d64399f5b7863a54ace" => :mavericks
|
|
end
|
|
|
|
depends_on "ghc" => :build
|
|
depends_on "cabal-install" => :build
|
|
depends_on "postgresql"
|
|
|
|
setup_ghc_compilers
|
|
|
|
def install
|
|
install_cabal_package "--enable-executable-stripping"
|
|
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
|