diff --git a/Makefile b/Makefile index 4f576df..fa90336 100644 --- a/Makefile +++ b/Makefile @@ -1,175 +1,37 @@ -.PHONY: run build test test-unit test-integration test-coverage test-coverage-func test-watch test-verbose test-benchmarks test-clean clean dev prod docker-build docker-run ci-test ci-build health-check install-service update-service test-endpoints test-errors +.PHONY: test test-all test-unit test-integration lint build -# Development -dev: - @echo "๐Ÿš€ Starting development server..." - GO_ENV=development go run main.go +# Default: Run unit tests only (fast, no Chrome needed) +test: test-unit -# Production -prod: - @echo "๐Ÿš€ Starting production server..." - GO_ENV=production go run main.go - -# Build -build: - @echo "๐Ÿ”จ Building binary..." - go build -o cv-server -ldflags="-s -w" . - @echo "โœ“ Binary created: ./cv-server" - -# Run built binary -run: build - ./cv-server - -# ============================================================================ -# TESTING TARGETS -# ============================================================================ - -# Run all tests with coverage -test: - @echo "๐Ÿงช Running all tests..." - go test -v -race -coverprofile=coverage.out ./... - @echo "โœ“ All tests complete" - -# Run unit tests only (fast) +# Run unit tests only (CI-safe, no Chrome) test-unit: @echo "๐Ÿงช Running unit tests..." - go test -v -race -short ./... - @echo "โœ“ Unit tests complete" + go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... + +# Run ALL tests including PDF/Chrome integration tests +test-all: + @echo "๐Ÿงช Running ALL tests (including integration tests)..." + go test -v -race -tags=integration -coverprofile=coverage.txt -covermode=atomic ./... # Run integration tests only test-integration: - @echo "๐Ÿงช Running integration tests..." - go test -v -race -run Integration ./... - @echo "โœ“ Integration tests complete" + @echo "๐Ÿงช Running integration tests only..." + go test -v -race -tags=integration ./internal/handlers -run PDF -# Generate HTML coverage report -test-coverage: test - @echo "๐Ÿ“Š Generating coverage report..." - go tool cover -html=coverage.out -o coverage.html - @echo "โœ“ Coverage report: coverage.html" - @open coverage.html 2>/dev/null || echo "Open coverage.html in your browser" +# Run linter +lint: + @echo "๐Ÿ” Running golangci-lint..." + golangci-lint run -# Show coverage by function -test-coverage-func: test - @echo "๐Ÿ“Š Coverage by function:" - go tool cover -func=coverage.out +# Build binary +build: + @echo "๐Ÿ”จ Building..." + go build -v -o cv-server . -# Watch for changes and run tests -test-watch: - @echo "๐Ÿ‘€ Watching for changes and running tests..." - @which watchexec > /dev/null || (echo "Install watchexec: brew install watchexec" && exit 1) - watchexec -e go -c clear -- make test +# Run all checks (lint + unit tests) +check: lint test-unit + @echo "โœ… All checks passed!" -# Run tests with verbose output and save to log -test-verbose: - @echo "๐Ÿงช Running verbose tests..." - go test -v -race -coverprofile=coverage.out -covermode=atomic ./... | tee test-output.log - @echo "โœ“ Tests complete. Output saved to test-output.log" - -# Run benchmarks -test-benchmarks: - @echo "โšก Running benchmarks..." - go test -bench=. -benchmem ./... - @echo "โœ“ Benchmarks complete" - -# Clean test artifacts -test-clean: - @echo "๐Ÿงน Cleaning test artifacts..." - rm -f coverage.out coverage.html test-output.log - go clean -testcache - @echo "โœ“ Test artifacts cleaned" - -# ============================================================================ -# ENDPOINT TESTING (requires running server) -# ============================================================================ - -# Test endpoints (requires server running) -test-endpoints: - @echo "๐Ÿงช Testing endpoints..." - @echo "\n1. Health check:" - @curl -s http://localhost:1999/health | jq . - @echo "\n2. English CV (first 50 chars):" - @curl -s "http://localhost:1999/?lang=en" | head -c 50 - @echo "\n\n3. Spanish CV content (first 50 chars):" - @curl -s "http://localhost:1999/cv?lang=es" | head -c 50 - @echo "\n\n4. Security headers:" - @curl -I http://localhost:1999/ 2>&1 | grep -E "^(X-|Content-Security)" - @echo "\nโœ“ All tests complete" - -# Test error handling (requires server running) -test-errors: - @echo "๐Ÿงช Testing error handling..." - @echo "\n1. Invalid language:" - @curl -i "http://localhost:1999/?lang=invalid" 2>&1 | head -15 - @echo "\n2. Error logging check" - @echo "โœ“ Error tests complete" - -# ============================================================================ -# CLEAN TARGETS -# ============================================================================ - -# Clean build artifacts -clean: - @echo "๐Ÿงน Cleaning build artifacts..." - rm -f cv-server - @echo "โœ“ Clean complete" - -# Docker -docker-build: - @echo "๐Ÿณ Building Docker image..." - docker build -t cv-server:latest . - @echo "โœ“ Docker image built" - -docker-run: - @echo "๐Ÿณ Running Docker container..." - docker run -p 1999:1999 cv-server:latest - -# CI/CD Targets -ci-test: - @echo "๐Ÿงช Running CI tests..." - go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - @echo "โœ“ CI tests complete" - -ci-build: - @echo "๐Ÿ”จ Building for CI/CD..." - mkdir -p build - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o build/cv-server . - @echo "โœ“ CI build complete: build/cv-server" - -health-check: - @echo "๐Ÿฅ Running health check..." - @./scripts/healthcheck.sh - -install-service: - @echo "๐Ÿ“ฆ Installing systemd service..." - sudo cp config/systemd/cv.service /etc/systemd/system/ - sudo systemctl daemon-reload - sudo systemctl enable cv - @echo "โœ“ Service installed and enabled" - -update-service: - @echo "๐Ÿ”„ Updating systemd service..." - sudo cp config/systemd/cv.service /etc/systemd/system/ - sudo systemctl daemon-reload - sudo systemctl restart cv - @echo "โœ“ Service updated and restarted" - -# Help -help: - @echo "Available commands:" - @echo " make dev - Run in development mode (hot-reload enabled)" - @echo " make prod - Run in production mode" - @echo " make build - Build production binary" - @echo " make run - Build and run binary" - @echo " make test - Test all endpoints" - @echo " make test-errors - Test error handling" - @echo " make clean - Remove build artifacts" - @echo " make docker-build - Build Docker image" - @echo " make docker-run - Run Docker container" - @echo "" - @echo "CI/CD commands:" - @echo " make ci-test - Run tests for CI pipeline" - @echo " make ci-build - Build binary for CI/CD" - @echo " make health-check - Check service health" - @echo " make install-service - Install systemd service" - @echo " make update-service - Update and restart service" +# Run everything (lint + all tests + build) +all: lint test-all build + @echo "โœ… Everything passed!"