mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-21 00:01:28 +00:00
aaa77eecb2
The seeder is one of the few things every developer runs on every new
checkout, but it had zero tests. With three migrations added in the last
few days and the rich-fixture path now creating 30+ rows, the chance of
silently breaking a schema migration without noticing was non-trivial.
cmd/seed/main_test.go connects to SEED_TEST_DB (skips otherwise — keeps
unit tests in CI fast and prevents accidentally clobbering a dev
database), runs migrations, wipes only the fixture rows, then:
1. Runs seedBaseline twice, verifies row count stays at 1.
2. Runs seedRich, asserts 9 different row counts match expectations
(users, orgs, workers, accounts, campaign, sequences, contacts,
unsubscribed contacts, campaign leads).
3. Re-runs seedRich, asserts every count is unchanged — the most
important guarantee the seeder makes.
4. Verifies warmup pool membership: 2 free, 4 premium, with the
correct accounts in each.
Plain testing package, table-driven, matches the existing style in
internal/app/warmup/service_test.go.
`make test-seed` brings up the docker-compose Postgres and runs the
suite against it.
88 lines
3.2 KiB
Makefile
88 lines
3.2 KiB
Makefile
GO_BIN := $(shell go env GOBIN)
|
|
ifeq ($(strip $(GO_BIN)),)
|
|
GO_BIN := $(shell go env GOPATH)/bin
|
|
endif
|
|
|
|
export PATH := $(GO_BIN):$(PATH)
|
|
|
|
GOLANGCI_LINT_VERSION ?= v1.64.8
|
|
PROTOC_GEN_GO_VERSION ?= v1.36.11
|
|
PROTOC_GEN_GO_GRPC_VERSION ?= v1.6.1
|
|
|
|
PROTO_DIR := internal/tasks/proto
|
|
PROTO_GEN_FILES := $(PROTO_DIR)/tasks.pb.go
|
|
|
|
.PHONY: setup-tools lint proto check-proto \
|
|
dev sim seed reset logs status stop down tools test-seed
|
|
|
|
setup-tools:
|
|
@echo "Installing required Go tools into $(GO_BIN)"
|
|
GOBIN=$(GO_BIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
|
|
GOBIN=$(GO_BIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
|
|
GOBIN=$(GO_BIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@$(PROTOC_GEN_GO_GRPC_VERSION)
|
|
|
|
lint:
|
|
golangci-lint run --timeout=5m
|
|
|
|
proto:
|
|
@command -v protoc >/dev/null || (echo "protoc not found in PATH"; exit 1)
|
|
@command -v protoc-gen-go >/dev/null || (echo "protoc-gen-go not found in PATH; run 'make setup-tools'"; exit 1)
|
|
protoc --proto_path=$(PROTO_DIR) --go_out=$(PROTO_DIR) --go_opt=paths=source_relative $(PROTO_DIR)/*.proto
|
|
|
|
check-proto:
|
|
@tmpdir=$$(mktemp -d); \
|
|
trap 'rm -rf "$$tmpdir"' EXIT; \
|
|
command -v protoc >/dev/null || { echo "protoc not found in PATH"; exit 1; }; \
|
|
command -v protoc-gen-go >/dev/null || { echo "protoc-gen-go not found in PATH; run 'make setup-tools'"; exit 1; }; \
|
|
protoc --proto_path=$(PROTO_DIR) --go_out="$$tmpdir" --go_opt=paths=source_relative $(PROTO_DIR)/*.proto; \
|
|
if ! cmp -s $(PROTO_GEN_FILES) "$$tmpdir/tasks.pb.go"; then \
|
|
echo "Generated protobuf files are out of date. Run 'make proto' and commit the changes."; \
|
|
exit 1; \
|
|
fi
|
|
|
|
# ─── dev / simulation stack ─────────────────────────────────────────────
|
|
|
|
# Start infra + app services (one worker). Foreground.
|
|
dev:
|
|
docker compose up
|
|
|
|
# Full simulation: infra + app + premium and dedicated workers.
|
|
sim:
|
|
docker compose --profile sim up
|
|
|
|
# Load rich fixture data. Backend must already be healthy.
|
|
seed:
|
|
docker compose --profile seed run --rm seed
|
|
|
|
# Spin up debugging UIs (kafka-ui).
|
|
tools:
|
|
docker compose --profile tools up -d kafka-ui
|
|
@echo "kafka-ui: http://localhost:18090"
|
|
|
|
# Stop services, keep volumes.
|
|
stop:
|
|
docker compose --profile sim --profile seed --profile tools stop
|
|
|
|
# Stop + remove containers, keep volumes (postgres, redis, web node_modules).
|
|
down:
|
|
docker compose --profile sim --profile seed --profile tools down
|
|
|
|
# Nuke everything including volumes. Useful for "start over".
|
|
reset:
|
|
docker compose --profile sim --profile seed --profile tools down -v
|
|
|
|
logs:
|
|
docker compose logs -f --tail=200
|
|
|
|
status:
|
|
docker compose ps
|
|
|
|
# Run seeder tests against the docker-compose Postgres. Brings up the db
|
|
# if it isn't running. Requires `docker compose up -d postgres` to have
|
|
# happened at least once so the volume exists.
|
|
test-seed:
|
|
docker compose up -d postgres
|
|
@until docker compose exec -T postgres pg_isready -U warmbly >/dev/null 2>&1; do echo "waiting for postgres..."; sleep 1; done
|
|
SEED_TEST_DB="postgres://warmbly:warmbly@localhost:15432/warmbly_dev?sslmode=disable" \
|
|
go test -count=1 -v ./cmd/seed/
|