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

Add code coverage report #1932

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ bin
# Test binary, build with `go test -c`
Copy link
Contributor

Choose a reason for hiding this comment

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

Top level comment: Consider adding a section to local-development section of our makefile documentation. Perhaps something like:

### `make test/coverage`

Outputs a filtered version of the each package's unit test coverage profiling via go's coverage tool to a local `coverage.html` file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks - added ✅

*.test

# Output of the go coverage tool, specifically when used with LiteIDE
# Output of the go coverage tool
*.out
coverage.html

# Vagrant
.vagrant
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ clean:
test:
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer a separate target (perhaps make test/coverage?) for generating the test coverage profile. I believe make test should be reserved for just running the unit tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added new target as requested: make test/coverage

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I just realized while test/coverage is in line with what we use to separate sub-commands of other make targets (e.g. e2e/cluster, the test-sanity target now sticks out. I think this is fine though (if anything we should consider changing test-sanity to test/sanity in a separate PR).

go test -v -race ./cmd/... ./pkg/...

.PHONY: test/coverage
test/coverage:
go test -coverprofile=cover.out ./cmd/... ./pkg/...
grep -v "mock" cover.out > filtered_cover.out
go tool cover -html=filtered_cover.out -o coverage.html
rm cover.out filtered_cover.out

.PHONY: test-sanity
test-sanity:
go test -v -race ./tests/sanity/...
Expand Down
4 changes: 4 additions & 0 deletions docs/makefile.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Build and push a multi-arch image of the driver based on the OSes in `ALL_OS`, a

Run all unit tests with race condition checking enabled.

### `make test/coverage`

Outputs a filtered version of the each package's unit test coverage profiling via go's coverage tool to a local `coverage.html` file.

### `make test-sanity`

Run the official [CSI sanity tests](https://github.com/kubernetes-csi/csi-test). _Warning: Currently, 3 of the tests are known to fail incorrectly._
Expand Down
Loading