refactor: [shitty claude AI first try] restructure server and user services, add new test cases, and improve error handling
This commit is contained in:
166
Makefile
Normal file
166
Makefile
Normal file
@ -0,0 +1,166 @@
|
||||
# Go Test Makefile
|
||||
|
||||
.PHONY: test test-unit test-integration test-coverage test-race test-verbose test-short clean-test lint fmt build
|
||||
|
||||
# Default target
|
||||
all: test
|
||||
|
||||
# Run all tests
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
# Run only unit tests (excluding integration tests)
|
||||
test-unit:
|
||||
go test -short ./...
|
||||
|
||||
# Run integration tests
|
||||
test-integration:
|
||||
go test -run TestIntegration ./test/integration/...
|
||||
|
||||
# Run tests with coverage
|
||||
test-coverage:
|
||||
go test -cover ./...
|
||||
|
||||
# Generate detailed coverage report
|
||||
test-coverage-html:
|
||||
go test -coverprofile=coverage.out ./...
|
||||
go tool cover -html=coverage.out -o coverage.html
|
||||
@echo "Coverage report generated: coverage.html"
|
||||
|
||||
# Run tests with race detection
|
||||
test-race:
|
||||
go test -race ./...
|
||||
|
||||
# Run tests in verbose mode
|
||||
test-verbose:
|
||||
go test -v ./...
|
||||
|
||||
# Run tests with short timeout (for CI/CD)
|
||||
test-short:
|
||||
go test -short -timeout=60s ./...
|
||||
|
||||
# Run specific test
|
||||
test-specific:
|
||||
@read -p "Enter test name pattern: " pattern; \
|
||||
go test -run $$pattern ./...
|
||||
|
||||
# Run benchmark tests
|
||||
test-bench:
|
||||
go test -bench=. ./...
|
||||
|
||||
# Run tests for specific package
|
||||
test-pkg:
|
||||
@read -p "Enter package path: " pkg; \
|
||||
go test ./$$pkg
|
||||
|
||||
# Clean test cache and temporary files
|
||||
clean-test:
|
||||
go clean -testcache
|
||||
rm -f coverage.out coverage.html
|
||||
|
||||
# Lint code
|
||||
lint:
|
||||
go vet ./...
|
||||
@if command -v golangci-lint >/dev/null 2>&1; then \
|
||||
golangci-lint run; \
|
||||
else \
|
||||
echo "golangci-lint not installed. Installing..."; \
|
||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
|
||||
golangci-lint run; \
|
||||
fi
|
||||
|
||||
# Format code
|
||||
fmt:
|
||||
go fmt ./...
|
||||
|
||||
# Build the application
|
||||
build:
|
||||
go build ./...
|
||||
|
||||
# Run tests in watch mode (requires entr)
|
||||
test-watch:
|
||||
@if command -v entr >/dev/null 2>&1; then \
|
||||
find . -name "*.go" | entr -c go test ./...; \
|
||||
else \
|
||||
echo "entr not installed. Please install it to use watch mode."; \
|
||||
echo "On macOS: brew install entr"; \
|
||||
echo "On Ubuntu: apt-get install entr"; \
|
||||
fi
|
||||
|
||||
# Generate test mocks (if using mockgen)
|
||||
generate-mocks:
|
||||
@if command -v mockgen >/dev/null 2>&1; then \
|
||||
go generate ./...; \
|
||||
else \
|
||||
echo "mockgen not installed. Installing..."; \
|
||||
go install github.com/golang/mock/mockgen@latest; \
|
||||
go generate ./...; \
|
||||
fi
|
||||
|
||||
# Setup test environment
|
||||
setup-test:
|
||||
go mod tidy
|
||||
go mod download
|
||||
|
||||
# Run tests with JSON output for CI/CD
|
||||
test-json:
|
||||
go test -json ./... > test-results.json
|
||||
|
||||
# Check test coverage threshold
|
||||
test-coverage-check:
|
||||
@coverage=$$(go test -cover ./... | grep "coverage:" | awk '{print $$3}' | sed 's/%//' | awk '{sum+=$$1; count++} END {print sum/count}'); \
|
||||
threshold=80; \
|
||||
if [ "$$(echo "$$coverage >= $$threshold" | bc -l)" -eq 1 ]; then \
|
||||
echo "Coverage $$coverage% meets threshold of $$threshold%"; \
|
||||
else \
|
||||
echo "Coverage $$coverage% below threshold of $$threshold%"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# Run tests with profiling
|
||||
test-profile:
|
||||
go test -cpuprofile=cpu.prof -memprofile=mem.prof ./...
|
||||
@echo "Profile files generated: cpu.prof, mem.prof"
|
||||
@echo "View CPU profile: go tool pprof cpu.prof"
|
||||
@echo "View Memory profile: go tool pprof mem.prof"
|
||||
|
||||
# Test specific layers
|
||||
test-domain:
|
||||
go test ./internal/api/*/domain/...
|
||||
|
||||
test-repo:
|
||||
go test ./internal/api/*/repo/...
|
||||
|
||||
test-service:
|
||||
go test ./internal/api/*/service/...
|
||||
|
||||
test-handler:
|
||||
go test ./internal/api/*/handler/...
|
||||
|
||||
test-utils:
|
||||
go test ./internal/phoneutil/... ./test/testutil/...
|
||||
|
||||
# Help target
|
||||
help:
|
||||
@echo "Available targets:"
|
||||
@echo " test - Run all tests"
|
||||
@echo " test-unit - Run unit tests only"
|
||||
@echo " test-integration - Run integration tests"
|
||||
@echo " test-coverage - Run tests with coverage"
|
||||
@echo " test-coverage-html- Generate HTML coverage report"
|
||||
@echo " test-race - Run tests with race detection"
|
||||
@echo " test-verbose - Run tests in verbose mode"
|
||||
@echo " test-short - Run tests with short timeout"
|
||||
@echo " test-bench - Run benchmark tests"
|
||||
@echo " test-watch - Run tests in watch mode"
|
||||
@echo " clean-test - Clean test cache and files"
|
||||
@echo " lint - Run linters"
|
||||
@echo " fmt - Format code"
|
||||
@echo " build - Build application"
|
||||
@echo " setup-test - Setup test environment"
|
||||
@echo " test-domain - Test domain layer only"
|
||||
@echo " test-service - Test service layer only"
|
||||
@echo " test-handler - Test handler layer only"
|
||||
@echo " test-repo - Test repository layer only"
|
||||
@echo " test-utils - Test utility packages"
|
||||
@echo " help - Show this help message"
|
||||
Reference in New Issue
Block a user