67 lines
1.7 KiB
Ruby
67 lines
1.7 KiB
Ruby
|
class FaasCli < Formula
|
||
|
desc "CLI for templating and/or deploying FaaS functions"
|
||
|
homepage "http://docs.get-faas.com/"
|
||
|
url "https://github.com/alexellis/faas-cli/archive/0.3.tar.gz"
|
||
|
sha256 "d4db7ddb0ea1dadf469c3da9893b004874d19570d09457e8cf86e5aef0df00f5"
|
||
|
|
||
|
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/alexellis/faas-cli").install buildpath.children
|
||
|
cd "src/github.com/alexellis/faas-cli" do
|
||
|
system "go", "build", "-o", bin/"faas-cli"
|
||
|
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 <<-EOF.undent
|
||
|
provider:
|
||
|
name: faas
|
||
|
gateway: http://localhost:#{port}
|
||
|
network: "func_functions"
|
||
|
|
||
|
functions:
|
||
|
dummy_function:
|
||
|
lang: python
|
||
|
handler: ./dummy_function
|
||
|
image: dummy_image
|
||
|
EOF
|
||
|
|
||
|
expected = <<-EOS.undent
|
||
|
Deploying: dummy_function.
|
||
|
Removing old service.
|
||
|
200 OK
|
||
|
URL: http://localhost:#{port}/function/dummy_function
|
||
|
EOS
|
||
|
|
||
|
begin
|
||
|
output = shell_output("#{bin}/faas-cli -action deploy -yaml test.yml")
|
||
|
assert_equal expected, output.chomp
|
||
|
ensure
|
||
|
Process.kill("TERM", pid)
|
||
|
Process.wait(pid)
|
||
|
end
|
||
|
end
|
||
|
end
|