|
| 1 | +# Makefile for Git Server S3 |
| 2 | + |
| 3 | +.PHONY: help test test-unit test-integration test-coverage build run clean lint fmt vet deps |
| 4 | + |
| 5 | +# Variables |
| 6 | +BINARY_NAME=git-server-s3 |
| 7 | +BUILD_DIR=tmp |
| 8 | +CONFIG_FILE=config.yaml |
| 9 | + |
| 10 | +# Help |
| 11 | +help: ## Display this help |
| 12 | + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' |
| 13 | + |
| 14 | +# Install dependencies |
| 15 | +deps: ## Install dependencies |
| 16 | + go mod download |
| 17 | + go mod tidy |
| 18 | + |
| 19 | +# Unit tests |
| 20 | +test-unit: ## Run unit tests |
| 21 | + go test -v -race -timeout 30s ./pkg/... ./internal/... |
| 22 | + |
| 23 | +# Tests with coverage |
| 24 | +test-coverage: ## Run tests with coverage |
| 25 | + go test -v -race -coverprofile=coverage.out -covermode=atomic ./pkg/... ./internal/... |
| 26 | + go tool cover -html=coverage.out -o coverage.html |
| 27 | + @echo "Coverage report generated: coverage.html" |
| 28 | + |
| 29 | +# Integration tests (requires S3_TEST_*) |
| 30 | +test-integration: ## Run integration tests (requires S3_TEST_* variables) |
| 31 | + @if [ -z "$(S3_TEST_BUCKET)" ]; then \ |
| 32 | + echo "❌ S3_TEST_* variables not defined. Example:"; \ |
| 33 | + echo "export S3_TEST_BUCKET=your-test-bucket"; \ |
| 34 | + echo "export S3_TEST_REGION=us-east-1"; \ |
| 35 | + echo "export S3_TEST_ENDPOINT=https://s3.us-east-1.amazonaws.com"; \ |
| 36 | + echo "make test-integration"; \ |
| 37 | + exit 1; \ |
| 38 | + fi |
| 39 | + go test -v -tags=integration -timeout 5m ./... |
| 40 | + |
| 41 | +# All tests |
| 42 | +test: test-unit ## Run all tests (unit tests only by default) |
| 43 | + |
| 44 | +# Tests with more verbosity |
| 45 | +test-verbose: ## Run tests with more details |
| 46 | + go test -v -race -coverprofile=coverage.out ./pkg/... ./internal/... -args -test.v |
| 47 | + |
| 48 | +# Code formatting |
| 49 | +fmt: ## Format code |
| 50 | + go fmt ./... |
| 51 | + |
| 52 | +# Static checks |
| 53 | +vet: ## Check code with go vet |
| 54 | + go vet ./... |
| 55 | + |
| 56 | +# Linting (requires golangci-lint) |
| 57 | +lint: ## Lint code (requires golangci-lint) |
| 58 | + @if command -v golangci-lint >/dev/null 2>&1; then \ |
| 59 | + golangci-lint run; \ |
| 60 | + else \ |
| 61 | + echo "⚠️ golangci-lint not installed. Installation:"; \ |
| 62 | + echo "go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \ |
| 63 | + fi |
| 64 | + |
| 65 | +# Build |
| 66 | +build: ## Build the server |
| 67 | + @mkdir -p $(BUILD_DIR) |
| 68 | + go build -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/main.go |
| 69 | + |
| 70 | +# Build with version information |
| 71 | +build-release: ## Build for release |
| 72 | + @mkdir -p $(BUILD_DIR) |
| 73 | + go build -ldflags "-X main.version=$(shell git describe --tags --always --dirty)" \ |
| 74 | + -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/main.go |
| 75 | + |
| 76 | +# Run the server |
| 77 | +run: build ## Build and run the server |
| 78 | + ./$(BUILD_DIR)/$(BINARY_NAME) server --config $(CONFIG_FILE) |
| 79 | + |
| 80 | +# Run in development mode with auto-reload (requires air) |
| 81 | +dev: ## Run in development mode (requires air) |
| 82 | + @if command -v air >/dev/null 2>&1; then \ |
| 83 | + air; \ |
| 84 | + else \ |
| 85 | + echo "⚠️ air not installed. Installation:"; \ |
| 86 | + echo "go install github.com/cosmtrek/air@latest"; \ |
| 87 | + echo "Or use: make run"; \ |
| 88 | + fi |
| 89 | + |
| 90 | +# Cleanup |
| 91 | +clean: ## Clean generated files |
| 92 | + rm -rf $(BUILD_DIR) |
| 93 | + rm -f coverage.out coverage.html |
| 94 | + go clean -cache -testcache |
| 95 | + |
| 96 | +# Performance tests |
| 97 | +bench: ## Run benchmarks |
| 98 | + go test -bench=. -benchmem -run=^$$ ./pkg/... ./internal/... |
| 99 | + |
| 100 | +# Race condition tests |
| 101 | +race: ## Run tests with race condition detection |
| 102 | + go test -race ./pkg/... ./internal/... |
| 103 | + |
| 104 | +# Security check (requires gosec) |
| 105 | +security: ## Check code security (requires gosec) |
| 106 | + @if command -v gosec >/dev/null 2>&1; then \ |
| 107 | + gosec ./...; \ |
| 108 | + else \ |
| 109 | + echo "⚠️ gosec not installed. Installation:"; \ |
| 110 | + echo "go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest"; \ |
| 111 | + fi |
| 112 | + |
| 113 | +# Update dependencies |
| 114 | +update-deps: ## Update dependencies |
| 115 | + go get -u ./... |
| 116 | + go mod tidy |
| 117 | + |
| 118 | +# Complete check (CI) |
| 119 | +ci: fmt vet test-unit ## CI/CD checks |
| 120 | + |
| 121 | +# Memory tests with Valgrind (Linux only) |
| 122 | +memcheck: ## Memory tests (Linux only) |
| 123 | + @if command -v valgrind >/dev/null 2>&1; then \ |
| 124 | + go test -c ./pkg/storage/s3/ && valgrind --leak-check=full ./s3.test; \ |
| 125 | + else \ |
| 126 | + echo "⚠️ valgrind not available (Linux only)"; \ |
| 127 | + fi |
| 128 | + |
| 129 | +# Install development tools |
| 130 | +install-tools: ## Install development tools |
| 131 | + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest |
| 132 | + go install github.com/cosmtrek/air@latest |
| 133 | + go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest |
| 134 | + |
| 135 | +# Test configuration example |
| 136 | +setup-test-env: ## Display test configuration example |
| 137 | + @echo "Configuration for integration tests:" |
| 138 | + @echo "" |
| 139 | + @echo "# Local MinIO (for testing)" |
| 140 | + @echo "export S3_TEST_BUCKET=git-server-test" |
| 141 | + @echo "export S3_TEST_REGION=us-east-1" |
| 142 | + @echo "export S3_TEST_ENDPOINT=http://localhost:9000" |
| 143 | + @echo "export AWS_ACCESS_KEY_ID=minio" |
| 144 | + @echo "export AWS_SECRET_ACCESS_KEY=minio123" |
| 145 | + @echo "" |
| 146 | + @echo "# Real AWS S3 (for cloud testing)" |
| 147 | + @echo "export S3_TEST_BUCKET=your-test-bucket" |
| 148 | + @echo "export S3_TEST_REGION=us-east-1" |
| 149 | + @echo "export S3_TEST_ENDPOINT=https://s3.us-east-1.amazonaws.com" |
| 150 | + @echo "# + your AWS credentials via AWS CLI or environment variables" |
| 151 | + |
| 152 | +# Tests with different log levels |
| 153 | +test-debug: ## Run tests with debug logs |
| 154 | + ZEROLOG_LEVEL=debug go test -v ./pkg/... ./internal/... |
| 155 | + |
| 156 | +# Tests on specific files |
| 157 | +test-s3: ## Test only the S3 package |
| 158 | + go test -v ./pkg/storage/s3/... |
| 159 | + |
| 160 | +test-api: ## Test only the API |
| 161 | + go test -v ./internal/api/... |
| 162 | + |
| 163 | +# Test statistics |
| 164 | +test-stats: ## Test statistics |
| 165 | + @echo "📊 Test statistics:" |
| 166 | + @find . -name "*_test.go" -not -path "./vendor/*" | wc -l | xargs echo "Test files:" |
| 167 | + @grep -r "func Test" --include="*_test.go" . | wc -l | xargs echo "Test functions:" |
| 168 | + @grep -r "func Benchmark" --include="*_test.go" . | wc -l | xargs echo "Benchmarks:" |
0 commit comments