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.3.0.tar.gz"
sha256 "643cb0d24886bcca4a01dd2e65aa5da235ed0599a575ffa67ba46b095bcea9f4"
license "Apache-2.0"
head "https://github.com/triggermesh/tm.git"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "ee64fb1f753b611c0417d2f346a5f40f6eeba83a0788c3d2100b630d5d8a41fb"
sha256 cellar: :any_skip_relocation, big_sur: "f18a9b4454bcaf2e3dce803c48334f55705668224ae6d29a5b0e7b531d3c7eb8"
sha256 cellar: :any_skip_relocation, catalina: "0095bd87a847107f958de558b096a701c99eec4cbcfc2e7aaa5ef74994208b98"
sha256 cellar: :any_skip_relocation, mojave: "4160f40f0d8b5d52e0fb66ab3152b8918a83c74d4010bbf79d7d06beec697ddd"
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