homebrew-core/Formula/dgraph.rb

70 lines
1.8 KiB
Ruby

class Dgraph < Formula
desc "Fast, Distributed Graph DB"
homepage "https://dgraph.io"
url "https://github.com/dgraph-io/dgraph/archive/v20.03.3.tar.gz"
sha256 "1e2145d8921b980882ef4475c82337e80c15fa3012a012424dadc9f636bffaa1"
bottle do
cellar :any_skip_relocation
sha256 "3679525940f0702aaf4cd2b6a92ec3793c73d6a1e00ec0c7388c302bfeb5068a" => :catalina
sha256 "7b51803834a9e6153ef9b288259900c2e2c26827b565c8e39bb810e3fc85b56e" => :mojave
sha256 "90d9e1ae909b36d0d04ddd40180a80a3c6ec9e766e97bba2b30ebd11e5520b3b" => :high_sierra
end
depends_on "go" => :build
def install
ENV["GOBIN"] = bin
system "make", "oss_install"
end
test do
fork do
exec bin/"dgraph", "zero"
end
fork do
exec bin/"dgraph", "alpha", "--lru_mb=1024"
end
sleep 10
(testpath/"mutate.json").write <<~EOS
{
"set": [
{
"name": "Karthic",
"age": 28,
"follows": {
"name": "Jessica",
"age": 31
}
}
]
}
EOS
(testpath/"query.graphql").write <<~EOS
{
people(func: has(name), orderasc: name) {
name
age
}
}
EOS
system "curl", "-s", "-H", "Content-Type: application/json",
"-XPOST", "--data-binary", "@#{testpath}/mutate.json",
"http://localhost:8080/mutate?commitNow=true"
command = %W[
curl -s -H "Content-Type: application/graphql+-"
-XPOST --data-binary @#{testpath}/query.graphql
http://localhost:8080/query
]
response = JSON.parse(shell_output(command.join(" ")))
expected = [{ "name" => "Jessica", "age" => 31 }, { "name" => "Karthic", "age" => 28 }]
assert_equal response["data"]["people"], expected
ensure
system "pkill", "-9", "-f", "dgraph"
end
end