Skip to content

Latest commit

 

History

History
104 lines (81 loc) · 4.36 KB

README.md

File metadata and controls

104 lines (81 loc) · 4.36 KB

go-opine

Go Report Card Build Status GoDoc NetflixOSS Lifecycle GitHub

Project Overview

go-opine is an opiniated way to run go test ./... -race and generate percent total of lines covered by tests. By default go-opine exits successfully if at least 50% code has test coverage, but this can be configured. go-opine tries to ignore and skip code that was generated by tools when calculating test coverage (e.g minimock mocks). go-opine also supports outputting test coverage reports in various formats, such as junit & cobertura.

Getting Started

Run go-opine test to test for code coverage in the root of a go project. For example, running in this repo produces the following output:

~/go-opine $
go-opine test
?       indeed.com/gophers/go-opine     [no test files]
ok      indeed.com/gophers/go-opine/internal/run        0.039s
ok      indeed.com/gophers/go-opine/internal/printing   0.019s
ok      indeed.com/gophers/go-opine/internal/coverage   0.317s
ok      indeed.com/gophers/go-opine/internal/junit      0.364s
ok      indeed.com/gophers/go-opine/internal/gotest     1.572s
ok      indeed.com/gophers/go-opine/internal/cmd        3.132s
Test coverage sufficient (85.4% >= 50.0%)

To generate a go coverage report, junit report, or corbertura report, see the usage info:

$ go-opine help test
test [-min-coverage <percent>] [-junit <path>] [-xmlcov <path>] [-coverprofile <path>]:
  Run Go tests in an opinionated way.
  -coverprofile string
        write Go coverprofile coverage
  -junit string
        write JUnit XML test results
  -min-coverage float
        minimum code test coverage to enforce (default 50)
  -xmlcov string
        write Cobertura XML coverage

Configuring minimum code coverage

By default go-opine requires 50% code coverage. This may not be adequate for every project, but Indeed has found it to be a good minimum. For projects that want to enforce different test coverage requirements, set the -min-coverage flag to the coverage percentage desired, between 0 and 100.

For example, to enforce a 75% code coverage requirement:

go-opine test -min-coverage 75

To disable code coverage requirements entirely, set -min-coverage to 0.

go-opine is a Go tool

Since go-opine is typically a tool dependency (rather than a library dependency) you can use the "tools.go" approach described in gotools and go#25922 to declare the dependency.

If you are not using a tools.go you can go get go-opine and install it on your path.

How To Contribute

We welcome contributions! Feel free to help make go-opine better.

Process

  • Open an issue and describe the desired feature / bug fix before making changes. It's useful to get a second pair of eyes before investing development effort.
  • Make the change. If adding a new feature, remember to provide tests that demonstrate the new feature works, including any error paths. If contributing a bug fix, add tests that demonstrate the erroneous behavior is fixed.
  • Open a pull request. Automated CI tests will run. If the tests fail, please make changes to fix the behavior, and repeat until the tests pass.
  • Once everything looks good, one of the indeedeng members will review the PR and provide feedback.

Maintainers

The oss.indeed.com/go/go-opine module is maintained by Indeed Engineering.

While we are always busy helping people get jobs, we will try to respond to GitHub issues, pull requests, and questions within a couple of business days.

Code of Conduct

This project is governed by the Contributor Covenant v 1.4.1.

License

This project uses the Apache 2.0 license. (Update this and the LICENSE file if your project uses a different license.)