class Etcd < Formula desc "Key value store for shared configuration and service discovery" homepage "https://github.com/etcd-io/etcd" url "https://github.com/etcd-io/etcd.git", tag: "v3.4.13", revision: "ae9734ed278b7a1a7dfc82e800471ebbf9fce56f" license "Apache-2.0" head "https://github.com/etcd-io/etcd.git" bottle do cellar :any_skip_relocation sha256 "ff3603b21a38568e3a2ae9964cdacbb5adfdc8b094c98b8e0423d2e4fb82c8ca" => :catalina sha256 "8c3f78a11d36c7c934deb4faa1007645d8cdb8293b04242e92e536551752a805" => :mojave sha256 "642a6b2ef0dbfabad3645e512c507aca25fa777a84e1790f7d18f8f63a2c637d" => :high_sierra end depends_on "go" => :build def install # Fix vendored deps issue (remove this in the next release) system "go", "mod", "vendor" system "go", "build", "-mod=vendor", "-ldflags", "-s -w -X main.version=#{version}", "-trimpath", "-o", bin/"etcd" system "go", "build", "-mod=vendor", "-ldflags", "-s -w -X main.version=#{version}", "-trimpath", "-o", bin/"etcdctl", "etcdctl/main.go" prefix.install_metafiles end plist_options manual: "etcd" def plist <<~EOS KeepAlive SuccessfulExit Label #{plist_name} ProgramArguments #{opt_bin}/etcd RunAtLoad WorkingDirectory #{var} EOS end test do test_string = "Hello from brew test!" etcd_pid = fork do exec bin/"etcd", "--enable-v2", # enable etcd v2 client support "--force-new-cluster", "--logger=zap", # default logger (`capnslog`) to be deprecated in v3.5 "--data-dir=#{testpath}" end # sleep to let etcd get its wits about it sleep 10 etcd_uri = "http://127.0.0.1:2379/v2/keys/brew_test" system "curl", "--silent", "-L", etcd_uri, "-XPUT", "-d", "value=#{test_string}" curl_output = shell_output("curl --silent -L #{etcd_uri}") response_hash = JSON.parse(curl_output) assert_match(test_string, response_hash.fetch("node").fetch("value")) assert_equal "OK\n", shell_output("#{bin}/etcdctl put foo bar") assert_equal "foo\nbar\n", shell_output("#{bin}/etcdctl get foo 2>&1") ensure # clean up the etcd process before we leave Process.kill("HUP", etcd_pid) end end