require "language/go" class Gnatsd < Formula desc "Lightweight cloud messaging system" homepage "https://nats.io" url "https://github.com/nats-io/gnatsd/archive/v0.7.2.tar.gz" sha256 "f71d77ff31fc31770cf8e140d084ecfa91f7a8333f945bac1ff44732901680b5" head "https://github.com/apcera/gnatsd.git" bottle do cellar :any_skip_relocation revision 1 sha256 "8f2ed4766107495ba638febfdaf5f225d5ed3393021d2d2b98056ed0d8ffd971" => :el_capitan sha256 "f0aa019cb44ed19334585450a70be74a3a22dd96c5f0af14769f1f6ff43a5b59" => :yosemite sha256 "9c12dceb0b70351db64ebf3d3ac9725d2be4e761936ddad97235d8f5d8510638" => :mavericks end depends_on "go" => :build go_resource "github.com/nats-io/nats" do url "https://github.com/nats-io/nats.git", :revision => "355b5b97e0842dc94f1106729aa88e33e06317ca" end go_resource "golang.org/x/crypto" do url "https://go.googlesource.com/crypto.git", :revision => "f18420efc3b4f8e9f3d51f6bd2476e92c46260e9" end def install ENV["GOPATH"] = buildpath Language::Go.stage_deps resources, buildpath/"src" mkdir_p "src/github.com/nats-io" ln_s buildpath, "src/github.com/nats-io/gnatsd" system "go", "install", "github.com/nats-io/gnatsd" system "go", "build", "-o", bin/"gnatsd", "gnatsd.go" end plist_options :manual => "gnatsd" def plist; <<-EOS.undent Label #{plist_name} ProgramArguments #{opt_bin}/gnatsd RunAtLoad EOS end test do pid = fork do exec "#{bin}/gnatsd --port=8085 --pid=#{testpath}/pid --log=#{testpath}/log" end sleep 3 begin assert_match version.to_s, shell_output("curl localhost:8085") assert File.exist?(testpath/"log") ensure Process.kill "SIGINT", pid Process.wait pid end end end