homebrew-core/Formula/fn.rb
2019-02-04 14:43:39 +08:00

59 lines
2.1 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.5.45.tar.gz"
sha256 "14a7f689d5729584b942cdc082661b98fcdfe13fc71f02d3c6d32cdbd1a73d37"
bottle do
cellar :any_skip_relocation
sha256 "a90aa4c5a422469e6f14107aed4782383e159cdd9c746853ed58425ba0d1446b" => :mojave
sha256 "4eca7deb015e7b269d1398e00f239e3488b396e8e1c7ae3317e34ab2dc73e5cc" => :high_sierra
sha256 "8cb558163f31a8ae6c9fde77ed12d22efd2630420edafe89c88b555a06cf3ce4" => :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