-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
49 lines (39 loc) · 1.62 KB
/
Copy pathMakefile
File metadata and controls
49 lines (39 loc) · 1.62 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
BINARY_NAME=go-template
BUILD_DIR=bin
COMPOSE_TEST=docker-compose.test.yml
.PHONY: build run generate test test-integration clean watch docker-run docker-down
# Regenerate mockgen mocks from the //go:generate directives in models/.
# Run this whenever an interface signature changes so mocks never drift.
generate:
go generate ./...
build: generate
go build -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/main.go
# Schema migrations are Go code (migrations/vN.go) applied by app.InitMigrations
# during boot, so `make run` migrates before it serves. There is deliberately no
# `make migrate` target — a separate manual step is what this design removes.
# See migrations/doc.go for how to add one.
run:
go run ./cmd/main.go
# Fast, hermetic unit tests — no real database, mocks only.
# The `integration` build tag excludes ./tests/integration from this run.
test: generate
go test ./... -v
# Integration tests against a real, disposable Postgres. Brings the compose
# stack up (waiting for the healthcheck), runs the tagged tests, then always
# tears the stack down — even if the tests fail. The tests build their schema by
# running the real migrations, so this also verifies migrations/vN.go.
test-integration:
docker compose -f $(COMPOSE_TEST) up -d --wait
@TEST_DB_HOST=localhost TEST_DB_PORT=5433 TEST_DB_USER=test TEST_DB_PASSWORD=test TEST_DB_NAME=go_template_test \
go test -tags=integration -count=1 -v ./tests/integration/... ; \
status=$$? ; \
docker compose -f $(COMPOSE_TEST) down -v ; \
exit $$status
clean:
rm -rf $(BUILD_DIR)
watch:
air -c .air.toml
docker-run:
docker compose up -d
docker-down:
docker compose down