homebrew-core/Formula/tm.rb

93 lines
3.4 KiB
Ruby

class Tm < Formula
desc "TriggerMesh CLI to work with knative objects"
homepage "https://triggermesh.com"
url "https://github.com/triggermesh/tm/archive/v1.9.0.tar.gz"
sha256 "00b74b7b5149e6db0d26fb49486530de718d30bd6bd6a2d90cfc5c358db0e511"
license "Apache-2.0"
head "https://github.com/triggermesh/tm.git", branch: "main"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "4f4b92292ce8779e767f2518a7d2d7e649914334ed302994932a0fd234b9d125"
sha256 cellar: :any_skip_relocation, big_sur: "8071336743fbd6e49a98b977df25fa11ba99dc39c8ae53a850fb7967a014cdd6"
sha256 cellar: :any_skip_relocation, catalina: "0f089fca0f5c961bdc3623c42e376cc4d176495b347aa013ff8f4a3a14a58c91"
sha256 cellar: :any_skip_relocation, mojave: "3b3d490e709b59a0e6f14fea36dfbea576c7fa9eea7d1e5fcf7010d2ffa23849"
sha256 cellar: :any_skip_relocation, x86_64_linux: "a80902518bad2186e160541dcf25242757769efd5c06b0b02e6bfb6d986b79c0"
end
depends_on "go" => :build
def install
ldflags = %W[
-s -w
-X github.com/triggermesh/tm/cmd.version=v#{version}
]
system "go", "build", *std_go_args, "-ldflags", ldflags.join(" ")
end
test do
(testpath/"kubeconfig").write <<~EOS
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: test
server: http://127.0.0.1:8080
name: test
contexts:
- context:
cluster: test
user: test
name: test
current-context: test
kind: Config
preferences: {}
users:
- name: test
user:
token: test
EOS
ENV["KUBECONFIG"] = testpath/"kubeconfig"
# version
version_output = shell_output("#{bin}/tm version")
assert_match "Triggermesh CLI, version v#{version}", version_output
# node
system "#{bin}/tm", "generate", "node", "foo-node"
assert_predicate testpath/"foo-node/serverless.yaml", :exist?
assert_predicate testpath/"foo-node/handler.js", :exist?
runtime = "https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/node10/runtime.yaml"
yaml = File.read("foo-node/serverless.yaml")
assert_match "runtime: #{runtime}", yaml
# python
system "#{bin}/tm", "generate", "python", "foo-python"
assert_predicate testpath/"foo-python/serverless.yaml", :exist?
assert_predicate testpath/"foo-python/handler.py", :exist?
runtime = "https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/python37/runtime.yaml"
yaml = File.read("foo-python/serverless.yaml")
assert_match "runtime: #{runtime}", yaml
# go
system "#{bin}/tm", "generate", "go", "foo-go"
assert_predicate testpath/"foo-go/serverless.yaml", :exist?
assert_predicate testpath/"foo-go/main.go", :exist?
runtime = "https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/go/runtime.yaml"
yaml = File.read("foo-go/serverless.yaml")
assert_match "runtime: #{runtime}", yaml
# ruby
system "#{bin}/tm", "generate", "ruby", "foo-ruby"
assert_predicate testpath/"foo-ruby/serverless.yaml", :exist?
assert_predicate testpath/"foo-ruby/handler.rb", :exist?
runtime = "https://raw.githubusercontent.com/triggermesh/knative-lambda-runtime/master/ruby25/runtime.yaml"
yaml = File.read("foo-ruby/serverless.yaml")
assert_match "runtime: #{runtime}", yaml
end
end