55 lines
2.1 KiB
Ruby
55 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.6.2.tar.gz"
|
|
sha256 "6a2d22f88e5267e9a7364adb75c95e9a59b84c5f46695a514edbe75218d328be"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, arm64_big_sur: "205eee71bfc340b94481c41f2f61b67529c8f48c387b9aed5c3fb75d4ead587d"
|
|
sha256 cellar: :any_skip_relocation, big_sur: "ae3a6489a19b83c1486e369dcbe812392f4d38e50bd4034ea30caccafe327d29"
|
|
sha256 cellar: :any_skip_relocation, catalina: "18244079c335e570523670439efc0ee9b9b35c700c327d1e561171d38abba680"
|
|
sha256 cellar: :any_skip_relocation, mojave: "f9f20203e958f01f23f1e9a510a9b35863e35f8cf2c68ff89edb122d29aea57e"
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
|
|
def install
|
|
system "go", "build", "-ldflags", "-s -w", "-trimpath", "-o", "#{bin}/fn"
|
|
prefix.install_metafiles
|
|
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
|
|
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
|