Makefile

  1GO_TEST_FLAGS ?= -race -count=1 -v -timeout=5m -json
  2
  3# These are the default values for the test database. They can be overridden
  4DB_USER ?= dbuser
  5DB_PASSWORD ?= password1
  6DB_NAME ?= testdb
  7DB_POSTGRES_PORT ?= 5433
  8DB_MYSQL_PORT ?= 3307
  9DB_CLICKHOUSE_PORT ?= 9001
 10DB_YDB_PORT ?= 2136
 11DB_TURSO_PORT ?= 8080
 12DB_STARROCKS_PORT ?= 9030
 13
 14list-build-tags:
 15	@echo "Available build tags:"
 16	@echo "$$(rg -o --trim 'no_[a-zA-Z0-9_]+' ./cmd/goose \
 17		--no-line-number --no-filename | sort | uniq | \
 18		xargs -n 4 | column -t | sed 's/^/  /')"
 19
 20.PHONY: dist
 21dist:
 22	@mkdir -p ./bin
 23	@rm -f ./bin/*
 24	GOOS=darwin  GOARCH=amd64 go build -o ./bin/goose-darwin64       ./cmd/goose
 25	GOOS=linux   GOARCH=amd64 go build -o ./bin/goose-linux64        ./cmd/goose
 26	GOOS=linux   GOARCH=386   go build -o ./bin/goose-linux386       ./cmd/goose
 27	GOOS=windows GOARCH=amd64 go build -o ./bin/goose-windows64.exe  ./cmd/goose
 28	GOOS=windows GOARCH=386   go build -o ./bin/goose-windows386.exe ./cmd/goose
 29
 30.PHONY: clean
 31clean:
 32	@find . -type f -name '*.FAIL' -delete
 33
 34.PHONY: lint
 35lint: tools
 36	@golangci-lint run ./... --fix
 37
 38.PHONY: tools
 39tools:
 40	@go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
 41	@go install github.com/mfridman/tparse@main
 42
 43test-packages:
 44	go test $(GO_TEST_FLAGS) $$(go list ./... | grep -v -e /bin -e /cmd -e /examples) |\
 45		tparse --follow -sort=elapsed -trimpath=auto -all
 46
 47test-packages-short:
 48	go test -test.short $(GO_TEST_FLAGS) $$(go list ./... | grep -v -e /bin -e /cmd -e /examples) |\
 49		tparse --follow -sort=elapsed
 50
 51coverage-short:
 52	go test ./ -test.short $(GO_TEST_FLAGS) -cover -coverprofile=coverage.out | tparse --follow -sort=elapsed
 53	go tool cover -html=coverage.out
 54
 55coverage:
 56	go test ./ $(GO_TEST_FLAGS) -cover -coverprofile=coverage.out | tparse --follow -sort=elapsed
 57	go tool cover -html=coverage.out
 58
 59#
 60# Integration-related targets
 61#
 62add-gowork:
 63	@[ -f go.work ] || go work init
 64	@[ -f go.work.sum ] || go work use -r .
 65
 66remove-gowork:
 67	rm -rf go.work go.work.sum
 68
 69upgrade-integration-deps:
 70	cd ./internal/testing && go get -u ./... && go mod tidy
 71
 72test-postgres-long: add-gowork test-postgres
 73	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='(TestPostgresProviderLocking|TestPostgresSessionLocker)' |\
 74		tparse --follow -sort=elapsed
 75
 76test-postgres: add-gowork
 77	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run="^TestPostgres$$" | tparse --follow -sort=elapsed
 78
 79test-clickhouse: add-gowork
 80	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='(TestClickhouse|TestClickhouseRemote)' |\
 81		tparse --follow -sort=elapsed
 82
 83test-mysql: add-gowork
 84	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='TestMySQL' | tparse --follow -sort=elapsed
 85
 86test-turso: add-gowork
 87	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='TestTurso' | tparse --follow -sort=elapsed
 88
 89test-vertica: add-gowork
 90	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='TestVertica' | tparse --follow -sort=elapsed
 91
 92test-ydb: add-gowork
 93	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='TestYDB' | tparse --follow -sort=elapsed
 94
 95test-starrocks: add-gowork
 96	go test $(GO_TEST_FLAGS) ./internal/testing/integration -run='TestStarrocks' | tparse --follow -sort=elapsed
 97
 98test-integration: add-gowork
 99	go test $(GO_TEST_FLAGS) ./internal/testing/integration/... | tparse --follow -sort=elapsed -trimpath=auto -all
100
101#
102# Docker-related targets
103#
104
105docker-cleanup:
106	docker stop -t=0 $$(docker ps --filter="label=goose_test" -aq)
107
108docker-postgres:
109	docker run --rm -d \
110		-e POSTGRES_USER=$(DB_USER) \
111		-e POSTGRES_PASSWORD=$(DB_PASSWORD) \
112		-e POSTGRES_DB=$(DB_NAME) \
113		-p $(DB_POSTGRES_PORT):5432 \
114		-l goose_test \
115		postgres:14-alpine -c log_statement=all
116	echo "postgres://$(DB_USER):$(DB_PASSWORD)@localhost:$(DB_POSTGRES_PORT)/$(DB_NAME)?sslmode=disable"
117
118docker-mysql:
119	docker run --rm -d \
120		-e MYSQL_ROOT_PASSWORD=rootpassword1 \
121		-e MYSQL_DATABASE=$(DB_NAME) \
122		-e MYSQL_USER=$(DB_USER) \
123		-e MYSQL_PASSWORD=$(DB_PASSWORD) \
124		-p $(DB_MYSQL_PORT):3306 \
125		-l goose_test \
126		mysql:8.0.31
127	echo "mysql://$(DB_USER):$(DB_PASSWORD)@localhost:$(DB_MYSQL_PORT)/$(DB_NAME)?parseTime=true"
128
129docker-clickhouse:
130	docker run --rm -d \
131		-e CLICKHOUSE_DB=$(DB_NAME) \
132		-e CLICKHOUSE_USER=$(DB_USER) \
133		-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
134		-e CLICKHOUSE_PASSWORD=$(DB_PASSWORD) \
135		-p $(DB_CLICKHOUSE_PORT):9000/tcp \
136		-l goose_test \
137		clickhouse/clickhouse-server:23-alpine
138	echo "clickhouse://$(DB_USER):$(DB_PASSWORD)@localhost:$(DB_CLICKHOUSE_PORT)/$(DB_NAME)"
139
140docker-turso:
141	docker run --rm -d \
142		-p $(DB_TURSO_PORT):8080 \
143		-l goose_test \
144		ghcr.io/tursodatabase/libsql-server:v0.22.10