homebrew-core/Formula/tm.rb

92 lines
3.2 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.5.0.tar.gz"
sha256 "64ecf3c1d75095f5909d4ee46a2903327099d33b952c6866ef03bfcdfb4d521d"
license "Apache-2.0"
head "https://github.com/triggermesh/tm.git"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "d2c06488354639e40c2020158e3f8e76c637d170b01f555fd274923da0f1ea97"
sha256 cellar: :any_skip_relocation, big_sur: "ee7e1d5f2d1c146b8b3db29a90134b84b9129187fe8c3b6cf02a133ff443de27"
sha256 cellar: :any_skip_relocation, catalina: "67aeec7dfb0ff2a0ec5e38cceeb1baddf7086742944d9af754b171fa2c773d6c"
sha256 cellar: :any_skip_relocation, mojave: "28c4386f4f06b924a1513dceeaa716fdb958b2577ce2d072cbcda6282c0d368c"
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