From b662ab774f706d1bb114bb7befba4947ada5d2c5 Mon Sep 17 00:00:00 2001 From: Eddie Torres Date: Wed, 14 Feb 2024 18:43:55 +0000 Subject: [PATCH] Add code coverage report Signed-off-by: Eddie Torres --- .gitignore | 3 ++- Makefile | 7 +++++++ docs/makefile.md | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4be608e597..a2804f629e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,9 @@ bin # Test binary, build with `go test -c` *.test -# Output of the go coverage tool, specifically when used with LiteIDE +# Output of the go coverage tool *.out +coverage.html # Vagrant .vagrant diff --git a/Makefile b/Makefile index b366dc51de..db2b48ac5f 100644 --- a/Makefile +++ b/Makefile @@ -76,6 +76,13 @@ clean: test: 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/... diff --git a/docs/makefile.md b/docs/makefile.md index 5314f0c65c..593263de12 100644 --- a/docs/makefile.md +++ b/docs/makefile.md @@ -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._