Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

harbor 0.0.1 (new formula) #165860

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Formula/h/harbor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Harbor < Formula
desc "[Sandbox] Official Harbor CLI"
homepage "https://github.com/goharbor/harbor-cli"
url "https://github.com/goharbor/harbor-cli/archive/refs/tags/v0.0.1.tar.gz"
sha256 "8a764ea10173d8dca4c99c79f55b054bea184abf012e7a346b7b39fae094d805"
license "Apache-2.0"

depends_on "go" => :build

def install
ENV["CGO_ENABLED"] = "0"

ldflags = %W[
-s -w
-X github.com/goharbor/harbor-cli/cmd/harbor/internal/version.Version=#{version}
]
system "go", "build", *std_go_args(ldflags:), "./cmd/harbor"
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a test that exercises the some of the functionality of the app. Version checks or usage checks (foo --version or foo --help) are not sufficient, as explained in the formula cookbook.

In most cases, a good test would involve running a simple test case: run #{bin}/foo input.txt.

  • Then you can check that the output is as expected (with assert_equal or assert_match on the output of shell_output)
  • You can also check that an output file was created, if that is expected: assert_predicate testpath/"output.txt", :exist?

Some advice for specific cases:

  • If the formula is a library, compile and run some simple code that links against it. It could be taken from upstream's documentation / source examples.
  • If the formula is for a GUI program, try to find some function that runs as command-line only, like a format conversion, reading or displaying a config file, etc.
  • If the software cannot function without credentials, a test could be to try to connect with invalid credentials (or without credentials) and confirm that it fails as expected.
  • Same if the software requires a virtual machine, docker instance, etc. to be running.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test do
assert_match "#{version}", shell_output("#{bin}/harbor version")
# Test for handling credential store error during project creation.
assert_match "failed to read credential store", shell_output("#{bin}/harbor create project 2>&1", 1)
end

end
Loading