diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml index 426bacb1..ce7d4dc2 100644 --- a/.github/workflows/golang.yml +++ b/.github/workflows/golang.yml @@ -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 diff --git a/.gitignore b/.gitignore index 58e07d96..8c2994d1 100644 --- a/.gitignore +++ b/.gitignore @@ -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.* diff --git a/Makefile b/Makefile index 542401d5..a6809d98 100644 --- a/Makefile +++ b/Makefile @@ -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.