Skip to content

Commit ae8e87d

Browse files
authored
Add target to generate code coverage report (#263)
* Add target to generate code coverage report Signed-off-by: Shiva Krishna, Merla <smerla@nvidia.com> * Ignore test packages for code coverage Signed-off-by: Shiva Krishna, Merla <smerla@nvidia.com> --------- Signed-off-by: Shiva Krishna, Merla <smerla@nvidia.com>
1 parent a4af156 commit ae8e87d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

.github/workflows/golang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
uses: actions/setup-go@v5
6868
with:
6969
go-version: ${{ env.GOLANG_VERSION }}
70-
- run: make test
70+
- run: make coverage
7171
build:
7272
name: Build
7373
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ testbin/*
1414

1515
# Output of the go coverage tool, specifically when used with LiteIDE
1616
*.out
17+
*.out.no-mocks
1718

1819
# Kubernetes Generated files - skip generated files, except for vendored files
1920
!vendor/**/zz_generated.*

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,16 @@ vet: ## Run go vet against code.
112112
check-vendor: vendor
113113
git diff --quiet HEAD -- go.mod go.sum
114114

115+
COVERAGE_FILE := cover.out
116+
117+
.PHONY: coverage
118+
coverage: test
119+
cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
120+
go tool cover -func=$(COVERAGE_FILE).no-mocks
121+
115122
.PHONY: test
116123
test: manifests generate fmt vet envtest ## Run tests.
117-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
124+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v test/ | grep -v api/) -coverprofile $(COVERAGE_FILE)
118125

119126
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
120127
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.

0 commit comments

Comments
 (0)