Skip to content

Commit

Permalink
Add target to generate code coverage report (#263)
Browse files Browse the repository at this point in the history
* Add target to generate code coverage report

Signed-off-by: Shiva Krishna, Merla <[email protected]>

* Ignore test packages for code coverage

Signed-off-by: Shiva Krishna, Merla <[email protected]>

---------

Signed-off-by: Shiva Krishna, Merla <[email protected]>
  • Loading branch information
shivamerla authored Dec 19, 2024
1 parent a4af156 commit ae8e87d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: ${{ env.GOLANG_VERSION }}
- run: make test
- run: make coverage
build:
name: Build
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ testbin/*

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

# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*
Expand Down
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,16 @@ vet: ## Run go vet against code.
check-vendor: vendor
git diff --quiet HEAD -- go.mod go.sum

COVERAGE_FILE := cover.out

.PHONY: coverage
coverage: test
cat $(COVERAGE_FILE) | grep -v "_mock.go" > $(COVERAGE_FILE).no-mocks
go tool cover -func=$(COVERAGE_FILE).no-mocks

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
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)

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

0 comments on commit ae8e87d

Please sign in to comment.