homebrew-core/Formula/faas-cli.rb
2017-11-26 02:24:26 -08:00

100 lines
3 KiB
Ruby

class FaasCli < Formula
desc "CLI for templating and/or deploying FaaS functions"
homepage "http://docs.get-faas.com/"
url "https://github.com/openfaas/faas-cli.git",
:tag => "0.5.0",
:revision => "91177ec27037eccaf6e827c265a0e452e772f1ab"
bottle do
cellar :any_skip_relocation
rebuild 1
sha256 "d99296c998fc2ff6297318ea21f33045f06fae7b7fc1901b9631b183772510bc" => :high_sierra
sha256 "d089d80543a49c8c65b3714060b7723b600ee5d815adf54263a486866756bc96" => :sierra
sha256 "d3c16359a6b3fbb6f7e8255b1110b50cf528f80e3be8cd1b4ff5942c65aee135" => :el_capitan
end
depends_on "go" => :build
def install
ENV["XC_OS"] = "darwin"
ENV["XC_ARCH"] = MacOS.prefer_64_bit? ? "amd64" : "386"
ENV["GOPATH"] = buildpath
(buildpath/"src/github.com/openfaas/faas-cli").install buildpath.children
cd "src/github.com/openfaas/faas-cli" do
project = "github.com/openfaas/faas-cli"
commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp
system "go", "build", "-ldflags",
"-s -w -X #{project}/version.GitCommit=#{commit}", "-a",
"-installsuffix", "cgo", "-o", bin/"faas-cli"
bin.install_symlink "faas-cli" => "faas"
pkgshare.install "template"
prefix.install_metafiles
end
end
test do
require "socket"
server = TCPServer.new("localhost", 0)
port = server.addr[1]
pid = fork do
loop do
socket = server.accept
response = "OK"
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
(testpath/"test.yml").write <<~EOS
provider:
name: faas
gateway: http://localhost:#{port}
network: "func_functions"
functions:
dummy_function:
lang: python
handler: ./dummy_function
image: dummy_image
EOS
expected = <<~EOS
Deploying: dummy_function.
Removing old function.
Deployed.
URL: http://localhost:#{port}/function/dummy_function
200 OK
EOS
begin
cp_r pkgshare/"template", testpath
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml")
assert_equal expected, output
rm_rf "template"
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml 2>&1", 1)
assert_match "stat ./template/python/template.yml", output
assert_match "ruby", shell_output("#{bin}/faas-cli template pull 2>&1")
assert_match "node", shell_output("#{bin}/faas-cli new --list")
output = shell_output("#{bin}/faas-cli deploy -yaml test.yml")
assert_equal expected, output
stable_resource = stable.instance_variable_get(:@resource)
commit = stable_resource.instance_variable_get(:@specs)[:revision]
assert_match commit, shell_output("#{bin}/faas-cli version")
ensure
Process.kill("TERM", pid)
Process.wait(pid)
end
end
end