test-coverage: go test -v -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
test-coverage-html: go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
Docker環境用:
test-coverage-local: docker exec -i paput-api ash -c "go test -v -coverprofile=coverage.out ./... && go tool cover -func=coverage.out"test-coverage-html-local: docker exec -i paput-api ash -c "go test -v -coverprofile=coverage.out ./... && go tool cover -html=coverage.out -o coverage.html"
OS別に自動でブラウザを開く処理:
@if [ "$$(uname)" = "Darwin" ]; then \
open coverage.html; \
elif [ "$$(uname)" = "Linux" ]; then \
xdg-open coverage.html 2>/dev/null || echo "Please open coverage.html manually"; \
elif [ "$$(expr substr $$(uname -s) 1 5)" = "MINGW" ]; then \
start coverage.html; \
else \
echo "Please open coverage.html manually"; \
fi