class Fn < Formula desc "Command-line tool for the fn project" homepage "https://fnproject.io" url "https://github.com/fnproject/cli/archive/0.5.91.tar.gz" sha256 "66f470d50fdb43b33bba1ec2c82d773adc109baadf417e7673bb4098f975fbd8" bottle do cellar :any_skip_relocation rebuild 1 sha256 "a1b85cd457cdd8313464d2fe0c1de2958eb395f8002caf4eae1a2ba7fb2a1074" => :catalina sha256 "9ac868d2ad2671618f32077b6390e6f4d90c05af74d1b52ba9f683d968235d1f" => :mojave sha256 "7bcd165245b02a75a00645661996f75622d445bbff5ffe257bfd66686d85a9b8" => :high_sierra end depends_on "go" => :build def install system "go", "build", "-ldflags", "-s -w", "-trimpath", "-o", "#{bin}/fn" prefix.install_metafiles 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