|
1 | | -.PHONY: help tests tests-coverage build run migrate clean docker-up docker-down docker-clean deps install-tools fmt fmt-check lint dev-setup test-all |
| 1 | +.PHONY: help tests tests-coverage build run init-db clean docker-up docker-down docker-clean deps install-tools fmt fmt-check lint dev-setup test-all schemathesis |
2 | 2 |
|
3 | 3 | # Default target - show help |
4 | 4 | help: |
|
7 | 7 | @echo " make tests - Run all tests" |
8 | 8 | @echo " make build - Build the API server" |
9 | 9 | @echo " make run - Run the API server" |
10 | | - @echo " make migrate - Run database migrations" |
| 10 | + @echo " make init-db - Initialize database schema" |
11 | 11 | @echo " make docker-up - Start Docker containers" |
12 | 12 | @echo " make docker-down - Stop Docker containers" |
13 | 13 | @echo " make clean - Clean build artifacts" |
14 | 14 | @echo " make fmt - Format code with gofumpt" |
15 | 15 | @echo " make fmt-check - Check if code is formatted" |
| 16 | + @echo " make schemathesis - Run Schemathesis API tests (requires API server running)" |
16 | 17 |
|
17 | 18 | # Run all tests |
18 | 19 | tests: |
|
44 | 45 | echo "API_KEY=test-api-key-12345" >> .env; \ |
45 | 46 | echo "" >> .env; \ |
46 | 47 | echo "# Database connection URL" >> .env; \ |
47 | | - echo "DATABASE_URL=postgres://formbricks:formbricks_dev@localhost:5432/formbricks_hub?sslmode=disable" >> .env; \ |
| 48 | + echo "DATABASE_URL=postgres://postgres:postgres@localhost:5432/test_db?sslmode=disable" >> .env; \ |
48 | 49 | echo "" >> .env; \ |
49 | 50 | echo "# Server port (default: 8080)" >> .env; \ |
50 | 51 | echo "PORT=8080" >> .env; \ |
|
53 | 54 | @echo "Starting API server..." |
54 | 55 | go run cmd/api/main.go |
55 | 56 |
|
56 | | -# Run database migrations |
57 | | -migrate: |
58 | | - @echo "Running database migrations..." |
| 57 | +# Initialize database schema |
| 58 | +init-db: |
| 59 | + @echo "Initializing database schema..." |
59 | 60 | @if [ -f .env ]; then \ |
60 | 61 | export $$(grep -v '^#' .env | xargs) && \ |
61 | 62 | if [ -z "$$DATABASE_URL" ]; then \ |
62 | 63 | echo "Error: DATABASE_URL not found in .env file"; \ |
63 | 64 | exit 1; \ |
64 | 65 | fi && \ |
65 | | - psql "$$DATABASE_URL" -f migrations/001_initial_schema.sql; \ |
| 66 | + psql "$$DATABASE_URL" -f sql/001_initial_schema.sql; \ |
66 | 67 | else \ |
67 | 68 | if [ -z "$$DATABASE_URL" ]; then \ |
68 | 69 | echo "Error: DATABASE_URL environment variable is not set"; \ |
69 | 70 | echo "Please set it or create a .env file with DATABASE_URL"; \ |
70 | 71 | exit 1; \ |
71 | 72 | fi && \ |
72 | | - psql "$$DATABASE_URL" -f migrations/001_initial_schema.sql; \ |
| 73 | + psql "$$DATABASE_URL" -f sql/001_initial_schema.sql; \ |
73 | 74 | fi |
74 | | - @echo "Migration completed successfully" |
| 75 | + @echo "Database schema initialized successfully" |
75 | 76 |
|
76 | 77 |
|
77 | 78 | # Start Docker containers |
@@ -135,11 +136,45 @@ lint: |
135 | 136 | $(HOME)/go/bin/golangci-lint run ./... |
136 | 137 |
|
137 | 138 | # Run everything needed for development |
138 | | -dev-setup: docker-up deps install-tools migrate |
| 139 | +dev-setup: docker-up deps install-tools init-db |
139 | 140 | @echo "Development environment ready!" |
140 | 141 | @echo "Set API_KEY environment variable for authentication" |
141 | 142 | @echo "Run 'make run' to start the API server" |
142 | 143 |
|
143 | 144 | # Full test suite (unit + integration) |
144 | 145 | test-all: tests |
145 | 146 | @echo "All tests passed!" |
| 147 | + |
| 148 | +# Run Schemathesis API tests (all phases for thorough local testing) |
| 149 | +# Phases: examples (schema examples), coverage (boundary values), stateful (API sequences), fuzzing (random) |
| 150 | +# This runs more thorough tests than CI to find edge-case bugs. |
| 151 | +# Requires: API server running (make run in another terminal) |
| 152 | +# Requires: uvx (install via: curl -LsSf https://astral.sh/uv/install.sh | sh) |
| 153 | +schemathesis: |
| 154 | + @echo "Running Schemathesis API tests (all phases)..." |
| 155 | + @echo "This is deeper testing than CI - may find edge-case bugs." |
| 156 | + @export PATH="$$HOME/.local/bin:$$PATH" && \ |
| 157 | + if [ -f .env ]; then \ |
| 158 | + export $$(grep -v '^#' .env | xargs) && \ |
| 159 | + if [ -z "$$API_KEY" ]; then \ |
| 160 | + echo "Warning: API_KEY not found in .env file, tests may fail authentication"; \ |
| 161 | + fi && \ |
| 162 | + uvx schemathesis run ./openapi.yaml \ |
| 163 | + --url http://localhost:8080 \ |
| 164 | + --header "Authorization: Bearer $${API_KEY:-test-api-key-12345}" \ |
| 165 | + --checks all \ |
| 166 | + --phases examples,coverage,stateful,fuzzing \ |
| 167 | + --max-examples 50; \ |
| 168 | + else \ |
| 169 | + if [ -z "$$API_KEY" ]; then \ |
| 170 | + echo "Error: API_KEY environment variable is not set and .env file not found"; \ |
| 171 | + echo "Please set API_KEY or create a .env file"; \ |
| 172 | + exit 1; \ |
| 173 | + fi && \ |
| 174 | + uvx schemathesis run ./openapi.yaml \ |
| 175 | + --url http://localhost:8080 \ |
| 176 | + --header "Authorization: Bearer $$API_KEY" \ |
| 177 | + --checks all \ |
| 178 | + --phases examples,coverage,stateful,fuzzing \ |
| 179 | + --max-examples 50; \ |
| 180 | + fi |
0 commit comments