class Fn < Formula desc "Command-line tool for the fn project" homepage "https://fnproject.io" url "https://github.com/fnproject/cli/archive/0.5.44.tar.gz" sha256 "ea18dcbb3e7e71a5c03d7c9d156e2164cd650373bc991b7258b58cab1564e475" bottle do cellar :any_skip_relocation sha256 "a663cf9a30c970458753f1fe0d7dc5e7d02ffa3762d6e8cc0bdae087b4a55982" => :mojave sha256 "d7a68fbd671e0887d338c47803ab93cdadd0b2749ad90ee2661cfacfac92df28" => :high_sierra sha256 "b57cd3a2d9550d9e8c9b5bd882a2d0bed609555a6a5240c15feac8e3c834cc90" => :sierra end depends_on "dep" => :build depends_on "go" => :build def install ENV["GOPATH"] = buildpath dir = buildpath/"src/github.com/fnproject/cli" dir.install Dir["*"] cd dir do system "dep", "ensure", "-vendor-only" system "go", "build", "-o", "#{bin}/fn" prefix.install_metafiles end end test do require "socket" assert_match version.to_s, shell_output("#{bin}/fn --version") system "#{bin}/fn", "init", "--runtime", "go", "--name", "myfunc" assert_predicate testpath/"func.go", :exist?, "expected file func.go doesn't exist" assert_predicate testpath/"func.yaml", :exist?, "expected file func.yaml doesn't exist" server = TCPServer.new("localhost", 0) port = server.addr[1] pid = fork do loop do socket = server.accept response = '{"id":"01CQNY9PADNG8G00GZJ000000A","name":"myapp","created_at":"2018-09-18T08:56:08.269Z","updated_at":"2018-09-18T08:56:08.269Z"}' socket.print "HTTP/1.1 200 OK\r\n" \ "Content-Length: #{response.bytesize}\r\n" \ "Connection: close\r\n" socket.print "\r\n" socket.print response socket.close end end begin ENV["FN_API_URL"] = "http://localhost:#{port}" ENV["FN_REGISTRY"] = "fnproject" expected = "Successfully created app: myapp" output = shell_output("#{bin}/fn create app myapp") assert_match expected, output.chomp ensure Process.kill("TERM", pid) Process.wait(pid) end end end