Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (118 loc) · 4.78 KB
/
Copy pathMakefile
File metadata and controls
130 lines (118 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.PHONY: build test test-unit test-bdd test-all coverage clean infra-up infra-down help
# Coverage output directory
COVERAGE_DIR := .coverage
# Docker compose services needed for tests (NOT pgproxy - tests run it themselves)
INFRA_SERVICES := valkey postgres-fast postgres-shunt postgres-reporter
help:
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@echo " build Build all binaries (pgproxy, loadgen, valkey-token)"
@echo " test Run all tests (unit + BDD, excludes @real-bedrock)"
@echo " test-unit Run unit tests only"
@echo " test-bdd Run BDD tests only (excludes @real-bedrock)"
@echo " test-all Run all tests including @real-bedrock (requires AWS creds)"
@echo " coverage Run all tests with merged coverage report"
@echo " infra-up Start test infrastructure containers"
@echo " infra-down Stop and remove test infrastructure containers"
@echo " clean Remove coverage files and test cache"
# Build all binaries
build:
@echo "=== Building binaries ==="
go build -o pgproxy ./cmd/pgproxy
go build -o loadgen ./cmd/loadgen
go build -o valkey-token ./cmd/valkey-token
@echo "Built: pgproxy, loadgen, valkey-token"
# Default target: quick pre-commit check
test: clean infra-up test-unit test-bdd
@echo ""
@echo "=== All tests passed ==="
# Unit tests only (no infrastructure needed)
test-unit:
@echo ""
@echo "=== Running unit tests ==="
go test -race -v ./internal/... ./cmd/...
# BDD tests only (requires infrastructure)
test-bdd: infra-up
@echo ""
@echo "=== Running BDD tests (excluding @real-bedrock) ==="
@# Kill any lingering proxy processes
@pkill -f pgproxy 2>/dev/null || true
@# Clear go test cache to ensure fresh run
go clean -testcache
INTEGRATION_TESTS=true GODOG_TAGS="~@real-bedrock" go test -race -v ./tests/...
# All tests including real-bedrock (requires AWS credentials)
test-all: clean infra-up test-unit
@echo ""
@echo "=== Running all BDD tests (including @real-bedrock) ==="
@pkill -f pgproxy 2>/dev/null || true
go clean -testcache
INTEGRATION_TESTS=true go test -race -v ./tests/...
# Coverage: merged unit + BDD coverage
# Note: Coverage runs without -race because BDD coverage uses 'set' mode which is incompatible with -race
# Use 'make test' for race detection
coverage: clean infra-up
@echo ""
@echo "=== Running tests with coverage ==="
@mkdir -p $(COVERAGE_DIR)
@# Unit test coverage (use set mode to match BDD coverage)
@echo "--- Unit test coverage ---"
go test -coverprofile=$(COVERAGE_DIR)/unit.out -covermode=set ./internal/... ./cmd/...
@# BDD test coverage (instrumented binary)
@echo ""
@echo "--- BDD test coverage ---"
@pkill -f pgproxy 2>/dev/null || true
go clean -testcache
@rm -rf $(COVERAGE_DIR)/bdd
@mkdir -p $(COVERAGE_DIR)/bdd
GOCOVERDIR=$(PWD)/$(COVERAGE_DIR)/bdd INTEGRATION_TESTS=true GODOG_TAGS="~@real-bedrock" go test -v ./tests/...
@# Convert BDD coverage to text format
@echo ""
@echo "--- Merging coverage ---"
@go tool covdata textfmt -i=$(COVERAGE_DIR)/bdd -o=$(COVERAGE_DIR)/bdd.out
@# Merge coverage files (both use mode: set)
@echo "mode: set" > $(COVERAGE_DIR)/merged.out
@grep -v "^mode:" $(COVERAGE_DIR)/unit.out >> $(COVERAGE_DIR)/merged.out 2>/dev/null || true
@grep -v "^mode:" $(COVERAGE_DIR)/bdd.out >> $(COVERAGE_DIR)/merged.out 2>/dev/null || true
@# Generate report
@echo ""
@echo "=== Coverage Summary ==="
@go tool cover -func=$(COVERAGE_DIR)/merged.out | tail -1
@echo ""
@echo "Coverage report: $(COVERAGE_DIR)/merged.out"
@echo "View HTML report: go tool cover -html=$(COVERAGE_DIR)/merged.out"
# Start infrastructure containers (fresh state)
infra-up:
@echo ""
@echo "=== Starting test infrastructure ==="
@# Stop and remove existing containers and volumes for clean state
docker compose down -v --remove-orphans 2>/dev/null || true
@# Start only infrastructure services (not pgproxy)
docker compose up -d $(INFRA_SERVICES)
@# Wait for postgres containers to be healthy
@echo "Waiting for databases to be ready..."
@for i in 1 2 3 4 5 6 7 8 9 10; do \
if docker compose exec -T postgres-fast pg_isready -U testuser -d testdb >/dev/null 2>&1 && \
docker compose exec -T postgres-shunt pg_isready -U testuser -d testdb >/dev/null 2>&1 && \
docker compose exec -T postgres-reporter pg_isready -U testuser -d testdb >/dev/null 2>&1; then \
echo "Databases ready"; \
break; \
fi; \
echo " waiting... ($$i/10)"; \
sleep 2; \
done
@# Verify valkey is ready
@docker exec valkey redis-cli PING >/dev/null 2>&1 || (echo "Valkey not ready" && exit 1)
@echo "Infrastructure ready"
# Stop infrastructure containers
infra-down:
@echo ""
@echo "=== Stopping test infrastructure ==="
docker compose down -v --remove-orphans
# Clean up
clean:
@echo ""
@echo "=== Cleaning up ==="
@rm -rf $(COVERAGE_DIR)
@pkill -f pgproxy 2>/dev/null || true
go clean -testcache