From 9d1043b87aa2a62ede2afcc7316b8073fc4b2fb1 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751NSS@gmail.com> Date: Wed, 27 Mar 2024 16:07:46 +0800 Subject: [PATCH] Update Makefile (#478) --- Makefile | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f25f71f09..826467cc0 100644 --- a/Makefile +++ b/Makefile @@ -292,7 +292,20 @@ test: ## cover: Run unit test with coverage. .PHONY: cover cover: test - @$(GO) test -cover + @echo "Running tests with coverage..." + @$(GO) test -coverprofile=coverage.out ./... + @echo "Checking coverage..." + @$(GO) tool cover -func=coverage.out | grep total: | awk '{print $$3}' | sed 's/%//g' | { \ + read coverage; \ + echo "Total coverage: $$coverage%"; \ + minCoverage=75; \ + if [ `echo "$$coverage < $$minCoverage" | bc` -eq 1 ]; then \ + echo "Coverage ($$coverage%) is below the minimum required ($$minCoverage%). Failing."; \ + exit 1; \ + else \ + echo "Coverage meets minimum requirement ($$minCoverage%)."; \ + fi; \ + } ## start: Start the chat all service. .PHONY: start