@@ -148,7 +148,7 @@ $(SYNCER_BIN): $(SYNCER_BIN_SRCS) syncer_manifest
148148 @touch $@
149149
150150# The default build target.
151- build build-bins: $(CSI_BIN) $(CSI_BIN_WINDOWS) $(SYNCER_BIN)
151+ build build-bins: $(CSI_BIN) $(CSI_BIN_WINDOWS) $(SYNCER_BIN) coverage-check
152152build-with-docker:
153153 hack/make.sh
154154
@@ -196,7 +196,7 @@ dist: dist-csi dist-syncer
196196.PHONY: deploy
197197deploy: | $(DOCKER_SOCK)
198198 $(MAKE) build-bins
199- $(MAKE) unit-test
199+ $(MAKE) coverage-check
200200 $(MAKE) push-images
201201
202202################################################################################
@@ -207,7 +207,8 @@ clean:
207207 @rm -f Dockerfile*
208208 rm -rf $(CSI_BIN) vsphere-csi-*.tar.gz vsphere-csi-*.zip \
209209 $(SYNCER_BIN) vsphere-syncer-*.tar.gz vsphere-syncer-*.zip \
210- image-*.tar image-*.d $(DIST_OUT)/* $(BIN_OUT)/* .build/windows-driver.tar
210+ image-*.tar image-*.d $(DIST_OUT)/* $(BIN_OUT)/* .build/windows-driver.tar \
211+ $(COVERAGE_OUT) $(COVERAGE_HTML) $(BUILD_OUT)/coverage-summary.txt cover.out
211212 GO111MODULE=off go clean -i -x . ./cmd/$(CSI_BIN_NAME) ./cmd/$(SYNCER_BIN_NAME)
212213
213214.PHONY: clean-d
@@ -276,17 +277,49 @@ endif # ifndef X_BUILD_DISABLED
276277## TESTING ##
277278################################################################################
278279ifndef PKGS_WITH_TESTS
279- export PKGS_WITH_TESTS := $(sort $(shell find . -path ./tests -prune -o -name "*_test.go" -type f -exec dirname \{\} \;))
280+ export PKGS_WITH_TESTS := $(sort $(shell find . -path ./tests -prune -o -path ./e2e -prune -o - name "*_test.go" -type f -exec dirname \{\} \;))
280281endif
281282TEST_FLAGS ?= -v -count=1
283+ COVERAGE_OUT ?= $(BUILD_OUT)/coverage.out
284+ COVERAGE_HTML ?= $(BUILD_OUT)/coverage.html
285+ COVERAGE_THRESHOLD ?= 75
286+
282287.PHONY: unit build-unit-tests
283288unit unit-test:
284289 env -u VSPHERE_SERVER -u VSPHERE_DATACENTER -u VSPHERE_PASSWORD -u VSPHERE_USER -u VSPHERE_STORAGE_POLICY_NAME -u KUBECONFIG -u WCP_ENDPOINT -u WCP_PORT -u WCP_NAMESPACE -u TOKEN -u CERTIFICATE go test $(TEST_FLAGS) $(PKGS_WITH_TESTS)
290+
285291unit-cover:
286292 env -u VSPHERE_SERVER -u VSPHERE_DATACENTER -u VSPHERE_PASSWORD -u VSPHERE_USER -u VSPHERE_STORAGE_POLICY_NAME -u KUBECONFIG -u WCP_ENDPOINT -u WCP_PORT -u WCP_NAMESPACE -u TOKEN -u CERTIFICATE go test $(TEST_FLAGS) $(PKGS_WITH_TESTS) && go tool cover -html=cover.out
293+
287294build-unit-tests:
288295 $(foreach pkg,$(PKGS_WITH_TESTS),go test $(TEST_FLAGS) -c $(pkg); )
289296
297+ # Coverage targets with threshold checking
298+ .PHONY: test-coverage coverage-report coverage-check coverage-html
299+ test-coverage: build-dirs
300+ @echo "Running unit tests with coverage..."
301+ @mkdir -p $(BUILD_OUT)
302+ env -u VSPHERE_SERVER -u VSPHERE_DATACENTER -u VSPHERE_PASSWORD -u VSPHERE_USER -u VSPHERE_STORAGE_POLICY_NAME -u KUBECONFIG -u WCP_ENDPOINT -u WCP_PORT -u WCP_NAMESPACE -u TOKEN -u CERTIFICATE \
303+ go test $(TEST_FLAGS) -coverprofile=$(COVERAGE_OUT) -covermode=atomic $(PKGS_WITH_TESTS)
304+
305+ coverage-report: test-coverage
306+ @echo "Generating coverage report..."
307+ go tool cover -func=$(COVERAGE_OUT) | tee $(BUILD_OUT)/coverage-summary.txt
308+
309+ coverage-html: test-coverage
310+ @echo "Generating HTML coverage report..."
311+ go tool cover -html=$(COVERAGE_OUT) -o $(COVERAGE_HTML)
312+ @echo "HTML coverage report generated at: $(COVERAGE_HTML)"
313+
314+ coverage-check: coverage-report
315+ @echo "Analyzing coverage quality (excluding 0% functions)..."
316+ @python3 scripts/check-coverage.py $(BUILD_OUT)/coverage-summary.txt $(COVERAGE_THRESHOLD)
317+
318+ # Full coverage workflow with threshold enforcement
319+ .PHONY: coverage-full
320+ coverage-full: coverage-check coverage-html
321+ @echo "Coverage analysis complete. Check $(COVERAGE_HTML) for detailed report."
322+
290323INTEGRATION_TEST_PKGS ?=
291324.PHONY: integration-unit-test
292325integration-unit-test:
@@ -349,7 +382,7 @@ endif
349382# The default test target.
350383.PHONY: test test-cover build-tests
351384test: unit
352- test-cover: unit-cover
385+ test-cover: coverage-full
353386build-tests: build-unit-tests
354387
355388.PHONY: cover
0 commit comments