homebrew-core/Formula/fn.rb

60 lines
2.2 KiB
Ruby

class Fn < Formula
desc "Command-line tool for the fn project"
homepage "https://fnproject.io"
url "https://github.com/fnproject/cli/archive/0.6.8.tar.gz"
sha256 "eebfc7bea0da0f56cbe392c0dc62b35804f6531ba9dd6b49ddf4875f32505fae"
license "Apache-2.0"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "f05b0e3cd6375632eddb33bebfff9a88529cd203e816a6ea554c87bc50bb0379"
sha256 cellar: :any_skip_relocation, big_sur: "c556a28674afde6a2af8863f7379672c7a34019964b09c9934612586fce548ed"
sha256 cellar: :any_skip_relocation, catalina: "f54b7aac76ce204ff59836c248234f9930f7ab30e3cd312563742869661daafe"
sha256 cellar: :any_skip_relocation, mojave: "ea758f6762f87e6c965c290a59d94d03a13c320f68117e75deb28d54c5ba4b15"
sha256 cellar: :any_skip_relocation, x86_64_linux: "f1086364187f4e5b87e255ab4624cf58d8f044d4541dbdc3af31bdc5e080ac79"
end
depends_on "go" => :build
def install
system "go", "build", *std_go_args(ldflags: "-s -w")
end
test do
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"
port = free_port
server = TCPServer.new("localhost", port)
pid = fork do
loop do
response = {
id: "01CQNY9PADNG8G00GZJ000000A",
name: "myapp",
created_at: "2018-09-18T08:56:08.269Z",
updated_at: "2018-09-18T08:56:08.269Z",
}.to_json
socket = server.accept
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
sleep 1
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